indexeddbshim 11.0.0 → 12.0.0-pre.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 (98) hide show
  1. package/badges/licenses-badge.svg +1 -1
  2. package/dist/CFG.d.ts +80 -0
  3. package/dist/CFG.d.ts.map +1 -0
  4. package/dist/DOMException.d.ts +71 -0
  5. package/dist/DOMException.d.ts.map +1 -0
  6. package/dist/DOMStringList.d.ts +20 -0
  7. package/dist/DOMStringList.d.ts.map +1 -0
  8. package/dist/Event.d.ts +21 -0
  9. package/dist/Event.d.ts.map +1 -0
  10. package/dist/IDBCursor.d.ts +289 -0
  11. package/dist/IDBCursor.d.ts.map +1 -0
  12. package/dist/IDBDatabase.d.ts +144 -0
  13. package/dist/IDBDatabase.d.ts.map +1 -0
  14. package/dist/IDBFactory.d.ts +96 -0
  15. package/dist/IDBFactory.d.ts.map +1 -0
  16. package/dist/IDBIndex.d.ts +243 -0
  17. package/dist/IDBIndex.d.ts.map +1 -0
  18. package/dist/IDBKeyRange.d.ts +79 -0
  19. package/dist/IDBKeyRange.d.ts.map +1 -0
  20. package/dist/IDBObjectStore.d.ts +273 -0
  21. package/dist/IDBObjectStore.d.ts.map +1 -0
  22. package/dist/IDBRequest.d.ts +90 -0
  23. package/dist/IDBRequest.d.ts.map +1 -0
  24. package/dist/IDBTransaction.d.ts +271 -0
  25. package/dist/IDBTransaction.d.ts.map +1 -0
  26. package/dist/IDBVersionChangeEvent.d.ts +23 -0
  27. package/dist/IDBVersionChangeEvent.d.ts.map +1 -0
  28. package/dist/Key.d.ts +214 -0
  29. package/dist/Key.d.ts.map +1 -0
  30. package/dist/Sca.d.ts +31 -0
  31. package/dist/Sca.d.ts.map +1 -0
  32. package/dist/UnicodeIdentifiers.d.ts +3 -0
  33. package/dist/UnicodeIdentifiers.d.ts.map +1 -0
  34. package/dist/browser-UnicodeIdentifiers.d.ts +2 -0
  35. package/dist/browser-UnicodeIdentifiers.d.ts.map +1 -0
  36. package/dist/browser-noninvasive.d.ts +3 -0
  37. package/dist/browser-noninvasive.d.ts.map +1 -0
  38. package/dist/browser.d.ts +2 -0
  39. package/dist/browser.d.ts.map +1 -0
  40. package/dist/cmp.d.ts +9 -0
  41. package/dist/cmp.d.ts.map +1 -0
  42. package/dist/indexeddbshim-Key.js +491 -189
  43. package/dist/indexeddbshim-Key.js.map +1 -1
  44. package/dist/indexeddbshim-Key.min.js +2 -2
  45. package/dist/indexeddbshim-Key.min.js.map +1 -1
  46. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +17263 -1396
  47. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
  48. package/dist/indexeddbshim-UnicodeIdentifiers.js +3892 -1271
  49. package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
  50. package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -2
  51. package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
  52. package/dist/indexeddbshim-node.cjs +17259 -1396
  53. package/dist/indexeddbshim-node.cjs.map +1 -1
  54. package/dist/indexeddbshim-noninvasive.js +3887 -1271
  55. package/dist/indexeddbshim-noninvasive.js.map +1 -1
  56. package/dist/indexeddbshim-noninvasive.min.js +2 -2
  57. package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
  58. package/dist/indexeddbshim.js +3887 -1271
  59. package/dist/indexeddbshim.js.map +1 -1
  60. package/dist/indexeddbshim.min.js +2 -2
  61. package/dist/indexeddbshim.min.js.map +1 -1
  62. package/dist/node-UnicodeIdentifiers.d.ts +8 -0
  63. package/dist/node-UnicodeIdentifiers.d.ts.map +1 -0
  64. package/dist/node.d.ts +8 -0
  65. package/dist/node.d.ts.map +1 -0
  66. package/dist/nodeWebSQL.d.ts +3 -0
  67. package/dist/nodeWebSQL.d.ts.map +1 -0
  68. package/dist/setGlobalVars.d.ts +79 -0
  69. package/dist/setGlobalVars.d.ts.map +1 -0
  70. package/dist/unicode-regex.d.ts +3 -0
  71. package/dist/unicode-regex.d.ts.map +1 -0
  72. package/dist/util.d.ts +174 -0
  73. package/dist/util.d.ts.map +1 -0
  74. package/package.json +40 -27
  75. package/src/CFG.js +89 -11
  76. package/src/DOMException.js +116 -29
  77. package/src/DOMStringList.js +92 -2
  78. package/src/Event.js +19 -4
  79. package/src/IDBCursor.js +339 -67
  80. package/src/IDBDatabase.js +87 -10
  81. package/src/IDBFactory.js +319 -56
  82. package/src/IDBIndex.js +385 -96
  83. package/src/IDBKeyRange.js +86 -13
  84. package/src/IDBObjectStore.js +326 -68
  85. package/src/IDBRequest.js +59 -1
  86. package/src/IDBTransaction.js +247 -38
  87. package/src/IDBVersionChangeEvent.js +28 -3
  88. package/src/Key.js +273 -156
  89. package/src/Sca.js +29 -4
  90. package/src/browser-UnicodeIdentifiers.js +5 -1
  91. package/src/cmp.js +5 -5
  92. package/src/node-UnicodeIdentifiers.js +9 -0
  93. package/src/node.js +5 -0
  94. package/src/nodeWebSQL.js +11 -5
  95. package/src/setGlobalVars.js +156 -21
  96. package/src/unicode-regex.js +9 -1
  97. package/src/util.js +228 -40
  98. package/typings/shimIndexedDB.d.ts +9 -0
@@ -1,4 +1,4 @@
1
- /*! indexeddbshim - v11.0.0 - 4/9/2023 */
1
+ /*! indexeddbshim - v12.0.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 || [];
@@ -1007,18 +1305,29 @@
1007
1305
  invalid: true
1008
1306
  };
1009
1307
  }
1010
- return ret;
1308
+
1309
+ // https://github.com/w3c/IndexedDB/issues/375
1310
+ // https://github.com/w3c/IndexedDB/pull/386
1311
+ if (Object.is(input, -0)) {
1312
+ return {
1313
+ type: type,
1314
+ value: 0
1315
+ };
1316
+ }
1317
+ return (/** @type {{type: KeyType; value: Value}} */ret
1318
+ );
1011
1319
  }
1012
1320
  case 'string':
1013
1321
  {
1014
- return ret;
1322
+ return (/** @type {{type: KeyType; value: Value}} */ret
1323
+ );
1015
1324
  }
1016
1325
  case 'binary':
1017
1326
  {
1018
1327
  // May throw (if detached)
1019
1328
  // Get a copy of the bytes held by the buffer source
1020
1329
  // https://heycam.github.io/webidl/#ref-for-dfn-get-buffer-source-copy-2
1021
- var octets = getCopyBytesHeldByBufferSource(input);
1330
+ var octets = getCopyBytesHeldByBufferSource( /** @type {BufferSource} */input);
1022
1331
  return {
1023
1332
  type: 'binary',
1024
1333
  value: octets
@@ -1027,12 +1336,15 @@
1027
1336
  case 'array':
1028
1337
  {
1029
1338
  // May throw (from binary)
1030
- var len = input.length;
1339
+ var arr = /** @type {Array<any>} */input;
1340
+ var len = arr.length;
1031
1341
  seen.push(input);
1342
+
1343
+ /** @type {(KeyValueObject|Value)[]} */
1032
1344
  var keys = [];
1033
1345
  var _loop = function _loop() {
1034
1346
  // We cannot iterate here with array extras as we must ensure sparse arrays are invalidated
1035
- if (!multiEntry && !Object.prototype.hasOwnProperty.call(input, i)) {
1347
+ if (!multiEntry && !Object.hasOwn(arr, i)) {
1036
1348
  return {
1037
1349
  v: {
1038
1350
  type: type,
@@ -1042,7 +1354,7 @@
1042
1354
  };
1043
1355
  }
1044
1356
  try {
1045
- var entry = input[i];
1357
+ var entry = arr[i];
1046
1358
  var key = convertValueToKeyValueDecoded(entry, seen, false, fullKeys); // Though steps do not list rethrowing, the next is returnifabrupt when not multiEntry
1047
1359
  if (key.invalid) {
1048
1360
  if (multiEntry) {
@@ -1081,13 +1393,14 @@
1081
1393
  }
1082
1394
  case 'date':
1083
1395
  {
1084
- if (!Number.isNaN(input.getTime())) {
1396
+ var date = /** @type {Date} */input;
1397
+ if (!Number.isNaN(date.getTime())) {
1085
1398
  return fullKeys ? {
1086
1399
  type: type,
1087
- value: input.getTime()
1400
+ value: date.getTime()
1088
1401
  } : {
1089
1402
  type: type,
1090
- value: new Date(input.getTime())
1403
+ value: new Date(date.getTime())
1091
1404
  };
1092
1405
  }
1093
1406
  return {
@@ -1101,7 +1414,7 @@
1101
1414
  default:
1102
1415
  {
1103
1416
  // Other `typeof` types which are not valid keys:
1104
- // 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function
1417
+ // 'undefined', 'boolean', 'object' (including `null`), 'symbol', 'function'
1105
1418
  var _type = input === null ? 'null' : _typeof(input); // Convert `null` for convenience of consumers in reporting errors
1106
1419
  return {
1107
1420
  type: _type,
@@ -1112,16 +1425,11 @@
1112
1425
  }
1113
1426
  }
1114
1427
 
1115
- /**
1116
- * @typedef {*} module:Key.Key
1117
- * @todo Specify possible value more precisely
1118
- */
1119
-
1120
1428
  /**
1121
1429
  *
1122
- * @param {module:Key.Key} key
1123
- * @param {boolean} fullKeys
1124
- * @returns {module:Key.keyValueObject}
1430
+ * @param {Key} key
1431
+ * @param {boolean} [fullKeys]
1432
+ * @returns {KeyValueObject}
1125
1433
  * @todo Document other allowable `key`?
1126
1434
  */
1127
1435
  function convertValueToMultiEntryKeyDecoded(key, fullKeys) {
@@ -1130,10 +1438,10 @@
1130
1438
 
1131
1439
  /**
1132
1440
  * An internal utility.
1133
- * @param input
1134
- * @param {boolean} seen
1441
+ * @param {Value} input
1442
+ * @param {Value[]|null|undefined} [seen]
1135
1443
  * @throws {DOMException} `DataError`
1136
- * @returns {module:Key.keyValueObject}
1444
+ * @returns {KeyValueObject}
1137
1445
  */
1138
1446
  function convertValueToKeyRethrowingAndIfInvalid(input, seen) {
1139
1447
  var key = convertValueToKey(input, seen);
@@ -1145,10 +1453,10 @@
1145
1453
 
1146
1454
  /**
1147
1455
  *
1148
- * @param value
1149
- * @param keyPath
1456
+ * @param {Value} value
1457
+ * @param {KeyPath} keyPath
1150
1458
  * @param {boolean} multiEntry
1151
- * @returns {module:Key.keyValueObject|module:Key.KeyPathEvaluateValue}
1459
+ * @returns {KeyValueObject|KeyPathEvaluateValue}
1152
1460
  * @todo Document other possible return?
1153
1461
  */
1154
1462
  function extractKeyFromValueUsingKeyPath(value, keyPath, multiEntry) {
@@ -1156,10 +1464,10 @@
1156
1464
  }
1157
1465
  /**
1158
1466
  * Not currently in use.
1159
- * @param value
1160
- * @param keyPath
1467
+ * @param {Value} value
1468
+ * @param {KeyPath} keyPath
1161
1469
  * @param {boolean} multiEntry
1162
- * @returns {module:Key.KeyPathEvaluateValue}
1470
+ * @returns {KeyPathEvaluateValue}
1163
1471
  */
1164
1472
  function evaluateKeyPathOnValue(value, keyPath, multiEntry) {
1165
1473
  return evaluateKeyPathOnValueToDecodedValue(value, keyPath);
@@ -1168,11 +1476,11 @@
1168
1476
  /**
1169
1477
  * May throw, return `{failure: true}` (e.g., non-object on keyPath resolution)
1170
1478
  * or `{invalid: true}` (e.g., `NaN`).
1171
- * @param value
1172
- * @param keyPath
1173
- * @param {boolean} multiEntry
1174
- * @param {boolean} fullKeys
1175
- * @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}
1176
1484
  * @todo Document other possible return?
1177
1485
  */
1178
1486
  function extractKeyValueDecodedFromValueUsingKeyPath(value, keyPath, multiEntry, fullKeys) {
@@ -1187,26 +1495,37 @@
1187
1495
  }
1188
1496
 
1189
1497
  /**
1190
- * @typedef {PlainObject} module:Key.KeyPathEvaluateFailure
1191
- * @property {boolean} failure
1192
- */
1498
+ * Unused?
1499
+ * @typedef {object} KeyPathEvaluateFailure
1500
+ * @property {boolean} failure
1501
+ */
1193
1502
 
1194
1503
  /**
1195
- * @typedef {PlainObject} module:Key.KeyPathEvaluateValue
1196
- * @property {undefined|array|string} value
1197
- */
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
+ */
1198
1516
 
1199
1517
  /**
1200
1518
  * Returns the value of an inline key based on a key path (wrapped in an
1201
1519
  * object with key `value`) or `{failure: true}`
1202
- * @param {object} value
1203
- * @param {string|array} keyPath
1204
- * @param {boolean} multiEntry
1520
+ * @param {Value} value
1521
+ * @param {KeyPath} keyPath
1522
+ * @param {boolean} [multiEntry]
1205
1523
  * @param {boolean} [fullKeys]
1206
- * @returns {module:Key.KeyPathEvaluateValue}
1524
+ * @returns {KeyPathEvaluateValue}
1207
1525
  */
1208
1526
  function evaluateKeyPathOnValueToDecodedValue(value, keyPath, multiEntry, fullKeys) {
1209
1527
  if (Array.isArray(keyPath)) {
1528
+ /** @type {KeyPathEvaluateValueValueArray} */
1210
1529
  var result = [];
1211
1530
  return keyPath.some(function (item) {
1212
1531
  var key = evaluateKeyPathOnValueToDecodedValue(value, item);
@@ -1234,23 +1553,23 @@
1234
1553
  switch (idntfr) {
1235
1554
  case 'size':
1236
1555
  case 'type':
1237
- value = value[idntfr];
1556
+ value = /** @type {Blob} */value[idntfr];
1238
1557
  break;
1239
1558
  }
1240
1559
  } else if (isFile(value)) {
1241
1560
  switch (idntfr) {
1242
1561
  case 'name':
1243
1562
  case 'lastModified':
1244
- value = value[idntfr];
1563
+ value = /** @type {File} */value[idntfr];
1245
1564
  break;
1246
1565
  case 'lastModifiedDate':
1247
- value = new Date(value.lastModified);
1566
+ value = new Date( /** @type {File} */value.lastModified);
1248
1567
  break;
1249
1568
  }
1250
- } else if (!isObj(value) || !Object.prototype.hasOwnProperty.call(value, idntfr)) {
1569
+ } else if (!isObj(value) || !Object.hasOwn(value, idntfr)) {
1251
1570
  return true;
1252
1571
  } else {
1253
- value = value[idntfr];
1572
+ value = /** @type {{[key: string]: KeyPathEvaluateValueValue}} */value[idntfr];
1254
1573
  return value === undefined;
1255
1574
  }
1256
1575
  return false;
@@ -1263,8 +1582,8 @@
1263
1582
 
1264
1583
  /**
1265
1584
  * Sets the inline key value.
1266
- * @param {object} value
1267
- * @param {*} key
1585
+ * @param {{[key: string]: AnyValue}} value
1586
+ * @param {Key} key
1268
1587
  * @param {string} keyPath
1269
1588
  * @returns {void}
1270
1589
  */
@@ -1272,19 +1591,19 @@
1272
1591
  var identifiers = keyPath.split('.');
1273
1592
  var last = identifiers.pop();
1274
1593
  identifiers.forEach(function (identifier) {
1275
- var hop = Object.prototype.hasOwnProperty.call(value, identifier);
1594
+ var hop = Object.hasOwn(value, identifier);
1276
1595
  if (!hop) {
1277
1596
  value[identifier] = {};
1278
1597
  }
1279
1598
  value = value[identifier];
1280
1599
  });
1281
- 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
1282
1601
  }
1283
1602
 
1284
1603
  /**
1285
1604
  *
1286
- * @param value
1287
- * @param keyPath
1605
+ * @param {Value} value
1606
+ * @param {string} keyPath
1288
1607
  * @see https://github.com/w3c/IndexedDB/pull/146
1289
1608
  * @returns {boolean}
1290
1609
  */
@@ -1299,11 +1618,11 @@
1299
1618
  if (!isObj(value)) {
1300
1619
  return false;
1301
1620
  }
1302
- var hop = Object.prototype.hasOwnProperty.call(value, identifier);
1621
+ var hop = Object.hasOwn(value, identifier);
1303
1622
  if (!hop) {
1304
1623
  return true;
1305
1624
  }
1306
- value = value[identifier];
1625
+ value = /** @type {{[key: string]: Value}} */value[identifier];
1307
1626
  }
1308
1627
  } catch (err) {
1309
1628
  _iterator3.e(err);
@@ -1315,9 +1634,9 @@
1315
1634
 
1316
1635
  /**
1317
1636
  *
1318
- * @param {module:Key.Key} key
1319
- * @param {IDBKeyRange} range
1320
- * @param {boolean} checkCached
1637
+ * @param {Key} key
1638
+ * @param {import('./IDBKeyRange.js').IDBKeyRangeFull} range
1639
+ * @param {boolean} [checkCached]
1321
1640
  * @returns {boolean}
1322
1641
  */
1323
1642
  function isKeyInRange(key, range, checkCached) {
@@ -1326,21 +1645,11 @@
1326
1645
  var encodedKey = _encode(key, true);
1327
1646
  var lower = checkCached ? range.__lowerCached : _encode(range.lower, true);
1328
1647
  var upper = checkCached ? range.__upperCached : _encode(range.upper, true);
1329
- if (range.lower !== undefined) {
1330
- if (range.lowerOpen && encodedKey > lower) {
1331
- lowerMatch = true;
1332
- }
1333
- if (!range.lowerOpen && encodedKey >= lower) {
1334
- lowerMatch = true;
1335
- }
1648
+ if (!lowerMatch && (range.lowerOpen && encodedKey !== null && lower !== null && encodedKey > lower || !range.lowerOpen && (!encodedKey && !lower || encodedKey !== null && lower !== null && encodedKey >= lower))) {
1649
+ lowerMatch = true;
1336
1650
  }
1337
- if (range.upper !== undefined) {
1338
- if (range.upperOpen && encodedKey < upper) {
1339
- upperMatch = true;
1340
- }
1341
- if (!range.upperOpen && encodedKey <= upper) {
1342
- upperMatch = true;
1343
- }
1651
+ if (!upperMatch && (range.upperOpen && encodedKey !== null && upper !== null && encodedKey < upper || !range.upperOpen && (!encodedKey && !upper || encodedKey !== null && upper !== null && encodedKey <= upper))) {
1652
+ upperMatch = true;
1344
1653
  }
1345
1654
  return lowerMatch && upperMatch;
1346
1655
  }
@@ -1361,9 +1670,9 @@
1361
1670
 
1362
1671
  /**
1363
1672
  *
1364
- * @param {module:Key.Key} keyEntry
1365
- * @param {IDBKeyRange} range
1366
- * @returns {module:Key.Key[]}
1673
+ * @param {Key} keyEntry
1674
+ * @param {import('./IDBKeyRange.js').IDBKeyRangeFull|undefined} range
1675
+ * @returns {Key[]}
1367
1676
  */
1368
1677
  function findMultiEntryMatches(keyEntry, range) {
1369
1678
  var matches = [];
@@ -1402,15 +1711,11 @@
1402
1711
  return matches;
1403
1712
  }
1404
1713
 
1405
- /**
1406
- * @typedef {number|string|Date|ArrayBuffer|module:Key.ValueTypes[]} module:Key.ValueTypes
1407
- */
1408
-
1409
1714
  /**
1410
1715
  * Not currently in use but keeping for spec parity.
1411
- * @param {module:Key.Key} key
1716
+ * @param {Key} key
1412
1717
  * @throws {Error} Upon a "bad key"
1413
- * @returns {module:Key.ValueTypes}
1718
+ * @returns {ValueType}
1414
1719
  */
1415
1720
  function convertKeyToValue(key) {
1416
1721
  var type = key.type,
@@ -1454,8 +1759,8 @@
1454
1759
 
1455
1760
  /**
1456
1761
  *
1457
- * @param {module:Key.Key} key
1458
- * @param {boolean} inArray
1762
+ * @param {Key} key
1763
+ * @param {boolean} [inArray]
1459
1764
  * @returns {string|null}
1460
1765
  */
1461
1766
  function _encode(key, inArray) {
@@ -1469,10 +1774,10 @@
1469
1774
 
1470
1775
  /**
1471
1776
  *
1472
- * @param {module:Key.Key} key
1473
- * @param {boolean} inArray
1777
+ * @param {Key} key
1778
+ * @param {boolean} [inArray]
1474
1779
  * @throws {Error} Invalid number
1475
- * @returns {undefined|module:Key.ValueTypes}
1780
+ * @returns {undefined|ValueType}
1476
1781
  */
1477
1782
  function _decode(key, inArray) {
1478
1783
  if (typeof key !== 'string') {
@@ -1483,9 +1788,9 @@
1483
1788
 
1484
1789
  /**
1485
1790
  *
1486
- * @param {module:Key.Key} key
1487
- * @param {boolean} inArray
1488
- * @returns {undefined|module:Key.ValueTypes}
1791
+ * @param {Key} key
1792
+ * @param {boolean} [inArray]
1793
+ * @returns {undefined|ValueType}
1489
1794
  */
1490
1795
  function roundTrip(key, inArray) {
1491
1796
  return _decode(_encode(key, inArray), inArray);
@@ -1493,30 +1798,25 @@
1493
1798
  var MAX_ALLOWED_CURRENT_NUMBER = 9007199254740992; // 2 ^ 53 (Also equal to `Number.MAX_SAFE_INTEGER + 1`)
1494
1799
 
1495
1800
  /**
1496
- * @external WebSQLTransaction
1801
+ * @typedef {number} Integer
1497
1802
  */
1498
1803
 
1499
- /**
1500
- * @typedef {IDBObjectStore} IDBObjectStoreWithCurrentName
1501
- * @property {string} __currentName
1502
- */
1503
-
1504
1804
  /**
1505
1805
  * @callback CurrentNumberCallback
1506
- * @param {Integer} The current number
1806
+ * @param {Integer} cn The current number
1507
1807
  * @returns {void}
1508
1808
  */
1509
1809
 
1510
1810
  /**
1511
1811
  * @callback SQLFailureCallback
1512
- * @param {DOMException} exception
1812
+ * @param {DOMException|Error} exception
1513
1813
  * @returns {void}
1514
1814
  */
1515
1815
 
1516
1816
  /**
1517
1817
  *
1518
- * @param {external:WebSQLTransaction} tx
1519
- * @param {IDBObjectStoreWithCurrentName} store
1818
+ * @param {SQLTransaction} tx
1819
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1520
1820
  * @param {CurrentNumberCallback} func
1521
1821
  * @param {SQLFailureCallback} sqlFailCb
1522
1822
  * @returns {void}
@@ -1530,13 +1830,14 @@
1530
1830
  }
1531
1831
  }, function (tx, error) {
1532
1832
  sqlFailCb(createDOMException('DataError', 'Could not get the auto increment value for key', error));
1833
+ return true;
1533
1834
  });
1534
1835
  }
1535
1836
 
1536
1837
  /**
1537
1838
  *
1538
- * @param {external:WebSQLTransaction} tx
1539
- * @param {IDBObjectStoreWithCurrentName} store
1839
+ * @param {SQLTransaction} tx
1840
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1540
1841
  * @param {Integer} num
1541
1842
  * @param {CurrentNumberCallback} successCb
1542
1843
  * @param {SQLFailureCallback} failCb
@@ -1550,6 +1851,7 @@
1550
1851
  successCb(num);
1551
1852
  }, function (tx, err) {
1552
1853
  failCb(createDOMException('UnknownError', 'Could not set the auto increment value for key', err));
1854
+ return true;
1553
1855
  });
1554
1856
  }
1555
1857
 
@@ -1557,8 +1859,8 @@
1557
1859
  * Bump up the auto-inc counter if the key path-resolved value is valid
1558
1860
  * (greater than old value and >=1) OR if a manually passed in key is
1559
1861
  * valid (numeric and >= 1) and >= any primaryKey.
1560
- * @param {external:WebSQLTransaction} tx
1561
- * @param {IDBObjectStoreWithCurrentName} store
1862
+ * @param {SQLTransaction} tx
1863
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1562
1864
  * @param {Integer} num
1563
1865
  * @param {CurrentNumberCallback} successCb
1564
1866
  * @param {SQLFailureCallback} failCb
@@ -1580,8 +1882,8 @@
1580
1882
 
1581
1883
  /**
1582
1884
  *
1583
- * @param {external:WebSQLTransaction} tx
1584
- * @param {IDBObjectStoreWithCurrentName} store
1885
+ * @param {SQLTransaction} tx
1886
+ * @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
1585
1887
  * @param {KeyForStoreCallback} cb
1586
1888
  * @param {SQLFailureCallback} sqlFailCb
1587
1889
  * @returns {void}
@@ -1607,10 +1909,10 @@
1607
1909
  // so we do not return a key
1608
1910
  /**
1609
1911
  *
1610
- * @param {external:WebSQLTransaction} tx
1611
- * @param {IDBObjectStoreWithCurrentName} store
1612
- * @param {*|Integer} key
1613
- * @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
1614
1916
  * @param {SQLFailureCallback} sqlFailCb
1615
1917
  * @returns {void}
1616
1918
  */