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
@@ -1,4 +1,4 @@
1
- /*! indexeddbshim - v11.0.0 - 4/29/2023 */
1
+ /*! indexeddbshim - v12.0.0-pre.0 - 6/7/2023 */
2
2
 
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
@@ -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', function (val) {
244
- 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(val)) {
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' // Callback not used by default
258
- ].forEach(function (prop) {
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
- // eslint-disable-next-line func-name-matching
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 || this instanceof DummyDOMException || this instanceof Error)) {
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['_' + prop];
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).forEach(function (codeName) {
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,36 @@
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|Error|null} error
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
- if (error && error.message) {
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 + '. ' + (error || ''));
605
+ console[method](name + ': ' + message + '. ' + (msg || ''));
476
606
  console.trace && console.trace();
477
607
  }
478
608
  }
609
+
610
+ /**
611
+ * @typedef {any} ArbitraryValue
612
+ */
613
+
614
+ /**
615
+ * @param {ArbitraryValue} obj
616
+ * @returns {boolean}
617
+ */
479
618
  function isErrorOrDOMErrorOrDOMException(obj) {
480
619
  return obj && _typeof(obj) === 'object' &&
481
620
  // We don't use util.isObj here as mutual dependency causing problems in Babel with browser
@@ -492,17 +631,43 @@
492
631
  useNativeDOMException = true;
493
632
  }
494
633
  } catch (e) {}
495
- var createDOMException = useNativeDOMException ? function (name, message, error) {
634
+ var createDOMException = useNativeDOMException
635
+ // eslint-disable-next-line operator-linebreak -- Need JSDoc
636
+ ?
637
+ /**
638
+ * @param {string} name
639
+ * @param {string} message
640
+ * @param {ErrorLike} [error]
641
+ * @returns {DOMException}
642
+ */
643
+ function (name, message, error) {
496
644
  logError(name, message, error);
497
645
  return createNativeDOMException(name, message);
498
- } : function (name, message, error) {
646
+ }
647
+ // eslint-disable-next-line operator-linebreak -- Need JSDoc
648
+ :
649
+ /**
650
+ * @param {string} name
651
+ * @param {string} message
652
+ * @param {ErrorLike} [error]
653
+ * @returns {Error}
654
+ */
655
+ function (name, message, error) {
499
656
  logError(name, message, error);
500
657
  return createNonNativeDOMException(name, message);
501
658
  };
502
659
 
660
+ /**
661
+ * @typedef {number} Integer
662
+ */
663
+
664
+ /**
665
+ * @param {string} arg
666
+ * @returns {string}
667
+ */
503
668
  function escapeUnmatchedSurrogates(arg) {
504
669
  // http://stackoverflow.com/a/6701665/271577
505
- return arg.replace(/((?:[\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) {
670
+ 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
671
  // Could add a corresponding surrogate for compatibility with `node-sqlite3`: http://bugs.python.org/issue12569 and http://stackoverflow.com/a/6701665/271577
507
672
  // but Chrome having problems
508
673
  if (unmatchedHighSurrogate) {
@@ -512,41 +677,80 @@
512
677
  });
513
678
  }
514
679
 
515
- // The escaping of unmatched surrogates was needed by Chrome but not Node
680
+ /**
681
+ * The escaping of unmatched surrogates was needed by Chrome but not Node.
682
+ * @param {string} arg
683
+ * @returns {string}
684
+ */
516
685
  function escapeSQLiteStatement(arg) {
517
- return escapeUnmatchedSurrogates(arg.replace(/\^/g, '^^').replace(/\0/g, '^0'));
686
+ return escapeUnmatchedSurrogates(arg.replaceAll('^', '^^').replaceAll('\0', '^0'));
518
687
  }
688
+
689
+ /**
690
+ *
691
+ * @param {AnyValue} obj
692
+ * @returns {obj is object}
693
+ */
519
694
  function isObj(obj) {
520
- return obj && _typeof(obj) === 'object';
695
+ return obj !== null && _typeof(obj) === 'object';
521
696
  }
697
+
698
+ /**
699
+ *
700
+ * @param {object} obj
701
+ * @returns {boolean}
702
+ */
522
703
  function isDate(obj) {
523
- return isObj(obj) && typeof obj.getDate === 'function';
704
+ return isObj(obj) && 'getDate' in obj && typeof obj.getDate === 'function';
524
705
  }
706
+
707
+ /**
708
+ *
709
+ * @param {object} obj
710
+ * @returns {boolean}
711
+ */
525
712
  function isBlob(obj) {
526
- return isObj(obj) && typeof obj.size === 'number' && typeof obj.slice === 'function' && !('lastModified' in obj);
713
+ return isObj(obj) && 'size' in obj && typeof obj.size === 'number' && 'slice' in obj && typeof obj.slice === 'function' && !('lastModified' in obj);
527
714
  }
715
+
716
+ /**
717
+ *
718
+ * @param {object} obj
719
+ * @returns {boolean}
720
+ */
528
721
  function isFile(obj) {
529
- return isObj(obj) && typeof obj.name === 'string' && typeof obj.slice === 'function' && 'lastModified' in obj;
722
+ return isObj(obj) && 'name' in obj && typeof obj.name === 'string' && 'slice' in obj && typeof obj.slice === 'function' && 'lastModified' in obj;
530
723
  }
724
+
725
+ /**
726
+ *
727
+ * @param {AnyValue} obj
728
+ * @returns {boolean}
729
+ */
531
730
  function isBinary(obj) {
532
- return isObj(obj) && typeof obj.byteLength === 'number' && (typeof obj.slice === 'function' ||
731
+ return isObj(obj) && 'byteLength' in obj && typeof obj.byteLength === 'number' && ('slice' in obj && typeof obj.slice === 'function' ||
533
732
  // `TypedArray` (view on buffer) or `ArrayBuffer`
534
- typeof obj.getFloat64 === 'function' // `DataView` (view on buffer)
733
+ 'getFloat64' in obj && typeof obj.getFloat64 === 'function' // `DataView` (view on buffer)
535
734
  );
536
735
  }
736
+
737
+ /**
738
+ * @param {AnyValue} v
739
+ * @returns {v is null|undefined}
740
+ */
537
741
  function isNullish(v) {
538
742
  return v === null || v === undefined;
539
743
  }
540
744
 
541
745
  /**
542
746
  * Compares two keys.
543
- * @param first
544
- * @param second
545
- * @returns {number}
747
+ * @param {import('./Key.js').Key} first
748
+ * @param {import('./Key.js').Key} second
749
+ * @returns {0|1|-1}
546
750
  */
547
751
  function cmp(first, second) {
548
- var encodedKey1 = _encode(first);
549
- var encodedKey2 = _encode(second);
752
+ var encodedKey1 = /** @type {string} */_encode(first);
753
+ var encodedKey2 = /** @type {string} */_encode(second);
550
754
  var result = encodedKey1 > encodedKey2 ? 1 : encodedKey1 === encodedKey2 ? 0 : -1;
551
755
  if (CFG.DEBUG) {
552
756
  // verify that the keys encoded correctly
@@ -574,12 +778,57 @@
574
778
  }
575
779
 
576
780
  /**
577
- * @module Key
781
+ * @typedef {NodeJS.TypedArray|DataView} ArrayBufferView
782
+ */
783
+
784
+ /**
785
+ * @typedef {ArrayBufferView|ArrayBuffer} BufferSource
786
+ */
787
+
788
+ /**
789
+ * @typedef {"number"|"date"|"string"|"binary"|"array"} KeyType
790
+ */
791
+
792
+ /**
793
+ * @typedef {any} Value
794
+ */
795
+
796
+ /**
797
+ * @typedef {any} Key
798
+ * @todo Specify possible value more precisely
799
+ */
800
+
801
+ /**
802
+ * @typedef {KeyPath[]} KeyPathArray
803
+ */
804
+ /**
805
+ * @typedef {string|KeyPathArray} KeyPath
806
+ */
807
+
808
+ /**
809
+ * @typedef {object} KeyValueObject
810
+ * @property {KeyType|"NaN"|"null"|"undefined"|"boolean"|"object"|"symbol"|
811
+ * "function"|"bigint"} type If not `KeyType`, indicates invalid value
812
+ * @property {Value} [value]
813
+ * @property {boolean} [invalid]
814
+ * @property {string} [message]
815
+ * @todo Specify acceptable `value` more precisely
816
+ */
817
+
818
+ /**
819
+ * @typedef {number|string|Date|ArrayBuffer} ValueTypePrimitive
820
+ */
821
+ /**
822
+ * @typedef {ValueType[]} ValueTypeArray
823
+ */
824
+ /**
825
+ * @typedef {ValueTypePrimitive|ValueTypeArray} ValueType
578
826
  */
579
827
 
580
828
  /**
581
829
  * Encodes the keys based on their types. This is required to maintain collations
582
830
  * We leave space for future keys.
831
+ * @type {{[key: string]: Integer|string}}
583
832
  */
584
833
  var keyTypeToEncodedChar = {
585
834
  invalid: 100,
@@ -589,14 +838,14 @@
589
838
  binary: 500,
590
839
  array: 600
591
840
  };
592
- var keyTypes = Object.keys(keyTypeToEncodedChar);
841
+ var keyTypes = /** @type {(KeyType|"invalid")[]} */Object.keys(keyTypeToEncodedChar);
593
842
  keyTypes.forEach(function (k) {
594
- keyTypeToEncodedChar[k] = String.fromCodePoint(keyTypeToEncodedChar[k]);
843
+ keyTypeToEncodedChar[k] = String.fromCodePoint( /** @type {number} */keyTypeToEncodedChar[k]);
595
844
  });
596
845
  var encodedCharToKeyType = keyTypes.reduce(function (o, k) {
597
846
  o[keyTypeToEncodedChar[k]] = k;
598
847
  return o;
599
- }, {});
848
+ }, /** @type {{[key: string]: KeyType|"invalid"}} */{});
600
849
 
601
850
  /**
602
851
  * The sign values for numbers, ordered from least to greatest.
@@ -608,12 +857,25 @@
608
857
  * - "positiveInfinity": Sorts above all other values.
609
858
  */
610
859
  var signValues = ['negativeInfinity', 'bigNegative', 'smallNegative', 'smallPositive', 'bigPositive', 'positiveInfinity'];
860
+
861
+ /**
862
+ * @typedef {any} AnyValue
863
+ */
864
+
611
865
  var types = {
612
866
  invalid: {
613
- encode: function encode(key) {
867
+ /**
868
+ * @param {AnyValue} _key
869
+ * @returns {string}
870
+ */
871
+ encode: function encode(_key) {
614
872
  return keyTypeToEncodedChar.invalid + '-';
615
873
  },
616
- decode: function decode(key) {
874
+ /**
875
+ * @param {string} _key
876
+ * @returns {undefined}
877
+ */
878
+ decode: function decode(_key) {
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.replace(/((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, '-$1') + ' ';
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).replace(/\x2D((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g, '$1');
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
- n = n.toString(32);
813
- return n.length === 1 ? '0' + n : n;
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
- exponent = Number.parseInt(exponent, 32);
861
- if (exponent < 0) {
862
- return roundToPrecision(Number.parseInt(mantissa, 32) * Math.pow(32, exponent - 10));
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 (exponent < 11) {
865
- var whole = mantissa.slice(0, exponent);
866
- whole = Number.parseInt(whole, 32);
867
- var fraction = mantissa.slice(exponent);
868
- fraction = Number.parseInt(fraction, 32) * Math.pow(32, exponent - 11);
869
- return roundToPrecision(whole + fraction);
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(exponent - 11);
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=16]
1185
+ * @param {Float} [precision]
878
1186
  * @returns {Float}
879
1187
  */
880
1188
  function roundToPrecision(num) {
@@ -901,27 +1209,23 @@
901
1209
  }
902
1210
 
903
1211
  /**
904
- * @typedef {"number"|"date"|"string"|"binary"|"array"} module:Key.KeyType
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
1216
  if (Array.isArray(key)) return 'array';
913
1217
  if (isDate(key)) return 'date';
914
1218
  if (isBinary(key)) return 'binary';
915
1219
  var keyType = _typeof(key);
916
- return ['string', 'number'].includes(keyType) ? keyType : 'invalid';
1220
+ return ['string', 'number'].includes(keyType) ? /** @type {"string"|"number"} */keyType : 'invalid';
917
1221
  }
918
1222
 
919
1223
  /**
920
1224
  * Keys must be strings, numbers (besides `NaN`), Dates (if value is not
921
1225
  * `NaN`), binary objects or Arrays.
922
- * @param input The key input
923
- * @param {?(Array)} [seen] An array of already seen keys
924
- * @returns {module:Key.keyValueObject}
1226
+ * @param {Value} input The key input
1227
+ * @param {Value[]|null|undefined} [seen] An array of already seen keys
1228
+ * @returns {KeyValueObject}
925
1229
  */
926
1230
  function convertValueToKey(input, seen) {
927
1231
  return convertValueToKeyValueDecoded(input, seen, false, true);
@@ -929,8 +1233,8 @@
929
1233
 
930
1234
  /**
931
1235
  * Currently not in use.
932
- * @param input
933
- * @returns {module:Key.keyValueObject}
1236
+ * @param {Value} input
1237
+ * @returns {KeyValueObject}
934
1238
  */
935
1239
  function convertValueToMultiEntryKey(input) {
936
1240
  return convertValueToKeyValueDecoded(input, null, true, true);
@@ -938,7 +1242,7 @@
938
1242
 
939
1243
  /**
940
1244
  *
941
- * @param O
1245
+ * @param {BufferSource} O
942
1246
  * @throws {TypeError}
943
1247
  * @see https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
944
1248
  * @returns {Uint8Array}
@@ -959,29 +1263,23 @@
959
1263
  }
960
1264
  // const octets = new Uint8Array(input);
961
1265
  // const octets = types.binary.decode(types.binary.encode(input));
962
- return new Uint8Array(O.buffer || O, offset, length);
1266
+ return new Uint8Array(
1267
+ // Should allow DataView
1268
+ /** @type {ArrayBuffer} */
1269
+ 'buffer' in O && O.buffer || O, offset, length);
963
1270
  }
964
1271
 
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
1272
  /**
975
1273
  * Shortcut utility to avoid returning full keys from `convertValueToKey`
976
1274
  * and subsequent need to process in calling code unless `fullKeys` is
977
1275
  * set; may throw.
978
- * @param {module:Key.Key} input
979
- * @param {?(Array)} [seen]
1276
+ * @param {Value} input
1277
+ * @param {Value[]|null} [seen]
980
1278
  * @param {boolean} [multiEntry]
981
1279
  * @param {boolean} [fullKeys]
982
1280
  * @throws {TypeError} See `getCopyBytesHeldByBufferSource`
983
1281
  * @todo Document other allowable `input`
984
- * @returns {module:Key.keyValueObject}
1282
+ * @returns {KeyValueObject}
985
1283
  */
986
1284
  function convertValueToKeyValueDecoded(input, seen, multiEntry, fullKeys) {
987
1285
  seen = seen || [];
@@ -1016,18 +1314,20 @@
1016
1314
  value: 0
1017
1315
  };
1018
1316
  }
1019
- return ret;
1317
+ return (/** @type {{type: KeyType; value: Value}} */ret
1318
+ );
1020
1319
  }
1021
1320
  case 'string':
1022
1321
  {
1023
- return ret;
1322
+ return (/** @type {{type: KeyType; value: Value}} */ret
1323
+ );
1024
1324
  }
1025
1325
  case 'binary':
1026
1326
  {
1027
1327
  // May throw (if detached)
1028
1328
  // Get a copy of the bytes held by the buffer source
1029
1329
  // https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
1030
- var octets = getCopyBytesHeldByBufferSource(input);
1330
+ var octets = getCopyBytesHeldByBufferSource( /** @type {BufferSource} */input);
1031
1331
  return {
1032
1332
  type: 'binary',
1033
1333
  value: octets
@@ -1036,12 +1336,15 @@
1036
1336
  case 'array':
1037
1337
  {
1038
1338
  // May throw (from binary)
1039
- var len = input.length;
1339
+ var arr = /** @type {Array<any>} */input;
1340
+ var len = arr.length;
1040
1341
  seen.push(input);
1342
+
1343
+ /** @type {(KeyValueObject|Value)[]} */
1041
1344
  var keys = [];
1042
1345
  var _loop = function _loop() {
1043
1346
  // We cannot iterate here with array extras as we must ensure sparse arrays are invalidated
1044
- if (!multiEntry && !Object.prototype.hasOwnProperty.call(input, i)) {
1347
+ if (!multiEntry && !Object.hasOwn(arr, i)) {
1045
1348
  return {
1046
1349
  v: {
1047
1350
  type: type,
@@ -1051,7 +1354,7 @@
1051
1354
  };
1052
1355
  }
1053
1356
  try {
1054
- var entry = input[i];
1357
+ var entry = arr[i];
1055
1358
  var key = convertValueToKeyValueDecoded(entry, seen, false, fullKeys); // Though steps do not list rethrowing, the next is returnifabrupt when not multiEntry
1056
1359
  if (key.invalid) {
1057
1360
  if (multiEntry) {
@@ -1090,13 +1393,14 @@
1090
1393
  }
1091
1394
  case 'date':
1092
1395
  {
1093
- if (!Number.isNaN(input.getTime())) {
1396
+ var date = /** @type {Date} */input;
1397
+ if (!Number.isNaN(date.getTime())) {
1094
1398
  return fullKeys ? {
1095
1399
  type: type,
1096
- value: input.getTime()
1400
+ value: date.getTime()
1097
1401
  } : {
1098
1402
  type: type,
1099
- value: new Date(input.getTime())
1403
+ value: new Date(date.getTime())
1100
1404
  };
1101
1405
  }
1102
1406
  return {
@@ -1110,7 +1414,7 @@
1110
1414
  default:
1111
1415
  {
1112
1416
  // Other `typeof` types which are not valid keys:
1113
- // 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function
1417
+ // 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function'
1114
1418
  var _type = input === null ? 'null' : _typeof(input); // Convert `null` for convenience of consumers in reporting errors
1115
1419
  return {
1116
1420
  type: _type,
@@ -1121,16 +1425,11 @@
1121
1425
  }
1122
1426
  }
1123
1427
 
1124
- /**
1125
- * @typedef {*} module:Key.Key
1126
- * @todo Specify possible value more precisely
1127
- */
1128
-
1129
1428
  /**
1130
1429
  *
1131
- * @param {module:Key.Key} key
1132
- * @param {boolean} fullKeys
1133
- * @returns {module:Key.keyValueObject}
1430
+ * @param {Key} key
1431
+ * @param {boolean} [fullKeys]
1432
+ * @returns {KeyValueObject}
1134
1433
  * @todo Document other allowable `key`?
1135
1434
  */
1136
1435
  function convertValueToMultiEntryKeyDecoded(key, fullKeys) {
@@ -1139,10 +1438,10 @@
1139
1438
 
1140
1439
  /**
1141
1440
  * An internal utility.
1142
- * @param input
1143
- * @param {boolean} seen
1441
+ * @param {Value} input
1442
+ * @param {Value[]|null|undefined} [seen]
1144
1443
  * @throws {DOMException} `DataError`
1145
- * @returns {module:Key.keyValueObject}
1444
+ * @returns {KeyValueObject}
1146
1445
  */
1147
1446
  function convertValueToKeyRethrowingAndIfInvalid(input, seen) {
1148
1447
  var key = convertValueToKey(input, seen);
@@ -1154,10 +1453,10 @@
1154
1453
 
1155
1454
  /**
1156
1455
  *
1157
- * @param value
1158
- * @param keyPath
1456
+ * @param {Value} value
1457
+ * @param {KeyPath} keyPath
1159
1458
  * @param {boolean} multiEntry
1160
- * @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
1459
+ * @returns {KeyValueObject|KeyPathEvaluateValue}
1161
1460
  * @todo Document other possible return?
1162
1461
  */
1163
1462
  function extractKeyFromValueUsingKeyPath(value, keyPath, multiEntry) {
@@ -1165,10 +1464,10 @@
1165
1464
  }
1166
1465
  /**
1167
1466
  * Not currently in use.
1168
- * @param value
1169
- * @param keyPath
1467
+ * @param {Value} value
1468
+ * @param {KeyPath} keyPath
1170
1469
  * @param {boolean} multiEntry
1171
- * @returns {module:Key.KeyPathEvaluateValue}
1470
+ * @returns {KeyPathEvaluateValue}
1172
1471
  */
1173
1472
  function evaluateKeyPathOnValue(value, keyPath, multiEntry) {
1174
1473
  return evaluateKeyPathOnValueToDecodedValue(value, keyPath);
@@ -1177,11 +1476,11 @@
1177
1476
  /**
1178
1477
  * May throw, return `{failure: true}` (e.g., non-object on keyPath resolution)
1179
1478
  * or `{invalid: true}` (e.g., `NaN`).
1180
- * @param value
1181
- * @param keyPath
1182
- * @param {boolean} multiEntry
1183
- * @param {boolean} fullKeys
1184
- * @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
1479
+ * @param {Value} value
1480
+ * @param {KeyPath} keyPath
1481
+ * @param {boolean} [multiEntry]
1482
+ * @param {boolean} [fullKeys]
1483
+ * @returns {KeyValueObject|KeyPathEvaluateValue}
1185
1484
  * @todo Document other possible return?
1186
1485
  */
1187
1486
  function extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, fullKeys) {
@@ -1196,26 +1495,37 @@
1196
1495
  }
1197
1496
 
1198
1497
  /**
1199
- * @typedef {PlainObject} module:Key.KeyPathEvaluateFailure
1200
- * @property {boolean} failure
1201
- */
1498
+ * Unused?
1499
+ * @typedef {object} KeyPathEvaluateFailure
1500
+ * @property {boolean} failure
1501
+ */
1202
1502
 
1203
1503
  /**
1204
- * @typedef {PlainObject} module:Key.KeyPathEvaluateValue
1205
- * @property {undefined|array|string} value
1206
- */
1504
+ * @typedef {KeyPathEvaluateValueValue[]} KeyPathEvaluateValueValueArray
1505
+ */
1506
+
1507
+ /**
1508
+ * @typedef {undefined|number|string|Date|object|KeyPathEvaluateValueValueArray} KeyPathEvaluateValueValue
1509
+ */
1510
+
1511
+ /**
1512
+ * @typedef {object} KeyPathEvaluateValue
1513
+ * @property {KeyPathEvaluateValueValue} [value]
1514
+ * @property {boolean} [failure]
1515
+ */
1207
1516
 
1208
1517
  /**
1209
1518
  * Returns the value of an inline key based on a key path (wrapped in an
1210
1519
  * object with key `value`) or `{failure: true}`
1211
- * @param {object} value
1212
- * @param {string|array} keyPath
1213
- * @param {boolean} multiEntry
1520
+ * @param {Value} value
1521
+ * @param {KeyPath} keyPath
1522
+ * @param {boolean} [multiEntry]
1214
1523
  * @param {boolean} [fullKeys]
1215
- * @returns {module:Key.KeyPathEvaluateValue}
1524
+ * @returns {KeyPathEvaluateValue}
1216
1525
  */
1217
1526
  function evaluateKeyPathOnValueToDecodedValue(value, keyPath, multiEntry, fullKeys) {
1218
1527
  if (Array.isArray(keyPath)) {
1528
+ /** @type {KeyPathEvaluateValueValueArray} */
1219
1529
  var result = [];
1220
1530
  return keyPath.some(function (item) {
1221
1531
  var key = evaluateKeyPathOnValueToDecodedValue(value, item);
@@ -1243,23 +1553,23 @@
1243
1553
  switch (idntfr) {
1244
1554
  case 'size':
1245
1555
  case 'type':
1246
- value = value[idntfr];
1556
+ value = /** @type {Blob} */value[idntfr];
1247
1557
  break;
1248
1558
  }
1249
1559
  } else if (isFile(value)) {
1250
1560
  switch (idntfr) {
1251
1561
  case 'name':
1252
1562
  case 'lastModified':
1253
- value = value[idntfr];
1563
+ value = /** @type {File} */value[idntfr];
1254
1564
  break;
1255
1565
  case 'lastModifiedDate':
1256
- value = new Date(value.lastModified);
1566
+ value = new Date( /** @type {File} */value.lastModified);
1257
1567
  break;
1258
1568
  }
1259
- } else if (!isObj(value) || !Object.prototype.hasOwnProperty.call(value, idntfr)) {
1569
+ } else if (!isObj(value) || !Object.hasOwn(value, idntfr)) {
1260
1570
  return true;
1261
1571
  } else {
1262
- value = value[idntfr];
1572
+ value = /** @type {{[key: string]: KeyPathEvaluateValueValue}} */value[idntfr];
1263
1573
  return value === undefined;
1264
1574
  }
1265
1575
  return false;
@@ -1272,8 +1582,8 @@
1272
1582
 
1273
1583
  /**
1274
1584
  * Sets the inline key value.
1275
- * @param {object} value
1276
- * @param {*} key
1585
+ * @param {{[key: string]: AnyValue}} value
1586
+ * @param {Key} key
1277
1587
  * @param {string} keyPath
1278
1588
  * @returns {void}
1279
1589
  */
@@ -1281,19 +1591,19 @@
1281
1591
  var identifiers = keyPath.split('.');
1282
1592
  var last = identifiers.pop();
1283
1593
  identifiers.forEach(function (identifier) {
1284
- var hop = Object.prototype.hasOwnProperty.call(value, identifier);
1594
+ var hop = Object.hasOwn(value, identifier);
1285
1595
  if (!hop) {
1286
1596
  value[identifier] = {};
1287
1597
  }
1288
1598
  value = value[identifier];
1289
1599
  });
1290
- value[last] = key; // key is already a `keyValue` in our processing so no need to convert
1600
+ value[/** @type {string} */last] = key; // key is already a `keyValue` in our processing so no need to convert
1291
1601
  }
1292
1602
 
1293
1603
  /**
1294
1604
  *
1295
- * @param value
1296
- * @param keyPath
1605
+ * @param {Value} value
1606
+ * @param {string} keyPath
1297
1607
  * @see https://github.com/w3c/IndexedDB/pull/146
1298
1608
  * @returns {boolean}
1299
1609
  */
@@ -1308,11 +1618,11 @@
1308
1618
  if (!isObj(value)) {
1309
1619
  return false;
1310
1620
  }
1311
- var hop = Object.prototype.hasOwnProperty.call(value, identifier);
1621
+ var hop = Object.hasOwn(value, identifier);
1312
1622
  if (!hop) {
1313
1623
  return true;
1314
1624
  }
1315
- value = value[identifier];
1625
+ value = /** @type {{[key: string]: Value}} */value[identifier];
1316
1626
  }
1317
1627
  } catch (err) {
1318
1628
  _iterator3.e(err);
@@ -1324,9 +1634,9 @@
1324
1634
 
1325
1635
  /**
1326
1636
  *
1327
- * @param {module:Key.Key} key
1328
- * @param {IDBKeyRange} range
1329
- * @param {boolean} checkCached
1637
+ * @param {Key} key
1638
+ * @param {import('./IDBKeyRange.js').IDBKeyRangeFull} range
1639
+ * @param {boolean} [checkCached]
1330
1640
  * @returns {boolean}
1331
1641
  */
1332
1642
  function isKeyInRange(key, range, checkCached) {
@@ -1335,21 +1645,11 @@
1335
1645
  var encodedKey = _encode(key, true);
1336
1646
  var lower = checkCached ? range.__lowerCached : _encode(range.lower, true);
1337
1647
  var upper = checkCached ? range.__upperCached : _encode(range.upper, true);
1338
- if (range.lower !== undefined) {
1339
- if (range.lowerOpen && encodedKey > lower) {
1340
- lowerMatch = true;
1341
- }
1342
- if (!range.lowerOpen && encodedKey >= lower) {
1343
- lowerMatch = true;
1344
- }
1648
+ if (!lowerMatch && (range.lowerOpen && encodedKey !== null && lower !== null && encodedKey > lower || !range.lowerOpen && (!encodedKey && !lower || encodedKey !== null && lower !== null && encodedKey >= lower))) {
1649
+ lowerMatch = true;
1345
1650
  }
1346
- if (range.upper !== undefined) {
1347
- if (range.upperOpen && encodedKey < upper) {
1348
- upperMatch = true;
1349
- }
1350
- if (!range.upperOpen && encodedKey <= upper) {
1351
- upperMatch = true;
1352
- }
1651
+ if (!upperMatch && (range.upperOpen && encodedKey !== null && upper !== null && encodedKey < upper || !range.upperOpen && (!encodedKey && !upper || encodedKey !== null && upper !== null && encodedKey <= upper))) {
1652
+ upperMatch = true;
1353
1653
  }
1354
1654
  return lowerMatch && upperMatch;
1355
1655
  }
@@ -1370,9 +1670,9 @@
1370
1670
 
1371
1671
  /**
1372
1672
  *
1373
- * @param {module:Key.Key} keyEntry
1374
- * @param {IDBKeyRange} range
1375
- * @returns {module:Key.Key[]}
1673
+ * @param {Key} keyEntry
1674
+ * @param {import('./IDBKeyRange.js').IDBKeyRangeFull|undefined} range
1675
+ * @returns {Key[]}
1376
1676
  */
1377
1677
  function findMultiEntryMatches(keyEntry, range) {
1378
1678
  var matches = [];
@@ -1411,15 +1711,11 @@
1411
1711
  return matches;
1412
1712
  }
1413
1713
 
1414
- /**
1415
- * @typedef {number|string|Date|ArrayBuffer|module:Key.ValueTypes[]} module:Key.ValueTypes
1416
- */
1417
-
1418
1714
  /**
1419
1715
  * Not currently in use but keeping for spec parity.
1420
- * @param {module:Key.Key} key
1716
+ * @param {Key} key
1421
1717
  * @throws {Error} Upon a "bad key"
1422
- * @returns {module:Key.ValueTypes}
1718
+ * @returns {ValueType}
1423
1719
  */
1424
1720
  function convertKeyToValue(key) {
1425
1721
  var type = key.type,
@@ -1463,8 +1759,8 @@
1463
1759
 
1464
1760
  /**
1465
1761
  *
1466
- * @param {module:Key.Key} key
1467
- * @param {boolean} inArray
1762
+ * @param {Key} key
1763
+ * @param {boolean} [inArray]
1468
1764
  * @returns {string|null}
1469
1765
  */
1470
1766
  function _encode(key, inArray) {
@@ -1478,10 +1774,10 @@
1478
1774
 
1479
1775
  /**
1480
1776
  *
1481
- * @param {module:Key.Key} key
1482
- * @param {boolean} inArray
1777
+ * @param {Key} key
1778
+ * @param {boolean} [inArray]
1483
1779
  * @throws {Error} Invalid number
1484
- * @returns {undefined|module:Key.ValueTypes}
1780
+ * @returns {undefined|ValueType}
1485
1781
  */
1486
1782
  function _decode(key, inArray) {
1487
1783
  if (typeof key !== 'string') {
@@ -1492,9 +1788,9 @@
1492
1788
 
1493
1789
  /**
1494
1790
  *
1495
- * @param {module:Key.Key} key
1496
- * @param {boolean} inArray
1497
- * @returns {undefined|module:Key.ValueTypes}
1791
+ * @param {Key} key
1792
+ * @param {boolean} [inArray]
1793
+ * @returns {undefined|ValueType}
1498
1794
  */
1499
1795
  function roundTrip(key, inArray) {
1500
1796
  return _decode(_encode(key, inArray), inArray);
@@ -1502,30 +1798,25 @@
1502
1798
  var MAX_ALLOWED_CURRENT_NUMBER = 9007199254740992; // 2 ^ 53 (Also equal to `Number.MAX_SAFE_INTEGER + 1`)
1503
1799
 
1504
1800
  /**
1505
- * @external WebSQLTransaction
1801
+ * @typedef {number} Integer
1506
1802
  */
1507
1803
 
1508
- /**
1509
- * @typedef {IDBObjectStore} IDBObjectStoreWithCurrentName
1510
- * @property {string} __currentName
1511
- */
1512
-
1513
1804
  /**
1514
1805
  * @callback CurrentNumberCallback
1515
- * @param {Integer} The current number
1806
+ * @param {Integer} cn The current number
1516
1807
  * @returns {void}
1517
1808
  */
1518
1809
 
1519
1810
  /**
1520
1811
  * @callback SQLFailureCallback
1521
- * @param {DOMException} exception
1812
+ * @param {DOMException|Error} exception
1522
1813
  * @returns {void}
1523
1814
  */
1524
1815
 
1525
1816
  /**
1526
1817
  *
1527
- * @param {external:WebSQLTransaction} tx
1528
- * @param {IDBObjectStoreWithCurrentName} store
1818
+ * @param {SQLTransaction} tx
1819
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1529
1820
  * @param {CurrentNumberCallback} func
1530
1821
  * @param {SQLFailureCallback} sqlFailCb
1531
1822
  * @returns {void}
@@ -1539,13 +1830,14 @@
1539
1830
  }
1540
1831
  }, function (tx, error) {
1541
1832
  sqlFailCb(createDOMException('DataError', 'Could not get the auto increment value for key', error));
1833
+ return true;
1542
1834
  });
1543
1835
  }
1544
1836
 
1545
1837
  /**
1546
1838
  *
1547
- * @param {external:WebSQLTransaction} tx
1548
- * @param {IDBObjectStoreWithCurrentName} store
1839
+ * @param {SQLTransaction} tx
1840
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1549
1841
  * @param {Integer} num
1550
1842
  * @param {CurrentNumberCallback} successCb
1551
1843
  * @param {SQLFailureCallback} failCb
@@ -1559,6 +1851,7 @@
1559
1851
  successCb(num);
1560
1852
  }, function (tx, err) {
1561
1853
  failCb(createDOMException('UnknownError', 'Could not set the auto increment value for key', err));
1854
+ return true;
1562
1855
  });
1563
1856
  }
1564
1857
 
@@ -1566,8 +1859,8 @@
1566
1859
  * Bump up the auto-inc counter if the key path-resolved value is valid
1567
1860
  * (greater than old value and >=1) OR if a manually passed in key is
1568
1861
  * valid (numeric and >= 1) and >= any primaryKey.
1569
- * @param {external:WebSQLTransaction} tx
1570
- * @param {IDBObjectStoreWithCurrentName} store
1862
+ * @param {SQLTransaction} tx
1863
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1571
1864
  * @param {Integer} num
1572
1865
  * @param {CurrentNumberCallback} successCb
1573
1866
  * @param {SQLFailureCallback} failCb
@@ -1589,8 +1882,8 @@
1589
1882
 
1590
1883
  /**
1591
1884
  *
1592
- * @param {external:WebSQLTransaction} tx
1593
- * @param {IDBObjectStoreWithCurrentName} store
1885
+ * @param {SQLTransaction} tx
1886
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1594
1887
  * @param {KeyForStoreCallback} cb
1595
1888
  * @param {SQLFailureCallback} sqlFailCb
1596
1889
  * @returns {void}
@@ -1616,10 +1909,10 @@
1616
1909
  // so we do not return a key
1617
1910
  /**
1618
1911
  *
1619
- * @param {external:WebSQLTransaction} tx
1620
- * @param {IDBObjectStoreWithCurrentName} store
1621
- * @param {*|Integer} key
1622
- * @param {CurrentNumberCallback|void} successCb
1912
+ * @param {SQLTransaction} tx
1913
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1914
+ * @param {import('./Key.js').Key} key
1915
+ * @param {(num?: Integer) => void} successCb
1623
1916
  * @param {SQLFailureCallback} sqlFailCb
1624
1917
  * @returns {void}
1625
1918
  */