indexeddbshim 12.0.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +1 -1
  2. package/badges/licenses-badge-dev.svg +1 -1
  3. package/dist/CFG.d.ts +80 -0
  4. package/dist/CFG.d.ts.map +1 -0
  5. package/dist/DOMException.d.ts +71 -0
  6. package/dist/DOMException.d.ts.map +1 -0
  7. package/dist/DOMStringList.d.ts +20 -0
  8. package/dist/DOMStringList.d.ts.map +1 -0
  9. package/dist/Event.d.ts +21 -0
  10. package/dist/Event.d.ts.map +1 -0
  11. package/dist/IDBCursor.d.ts +288 -0
  12. package/dist/IDBCursor.d.ts.map +1 -0
  13. package/dist/IDBDatabase.d.ts +143 -0
  14. package/dist/IDBDatabase.d.ts.map +1 -0
  15. package/dist/IDBFactory.d.ts +96 -0
  16. package/dist/IDBFactory.d.ts.map +1 -0
  17. package/dist/IDBIndex.d.ts +243 -0
  18. package/dist/IDBIndex.d.ts.map +1 -0
  19. package/dist/IDBKeyRange.d.ts +79 -0
  20. package/dist/IDBKeyRange.d.ts.map +1 -0
  21. package/dist/IDBObjectStore.d.ts +273 -0
  22. package/dist/IDBObjectStore.d.ts.map +1 -0
  23. package/dist/IDBRequest.d.ts +88 -0
  24. package/dist/IDBRequest.d.ts.map +1 -0
  25. package/dist/IDBTransaction.d.ts +270 -0
  26. package/dist/IDBTransaction.d.ts.map +1 -0
  27. package/dist/IDBVersionChangeEvent.d.ts +22 -0
  28. package/dist/IDBVersionChangeEvent.d.ts.map +1 -0
  29. package/dist/Key.d.ts +214 -0
  30. package/dist/Key.d.ts.map +1 -0
  31. package/dist/Sca.d.ts +31 -0
  32. package/dist/Sca.d.ts.map +1 -0
  33. package/dist/UnicodeIdentifiers.d.ts +3 -0
  34. package/dist/UnicodeIdentifiers.d.ts.map +1 -0
  35. package/dist/browser-UnicodeIdentifiers.d.ts +2 -0
  36. package/dist/browser-UnicodeIdentifiers.d.ts.map +1 -0
  37. package/dist/browser-noninvasive.d.ts +3 -0
  38. package/dist/browser-noninvasive.d.ts.map +1 -0
  39. package/dist/browser.d.ts +2 -0
  40. package/dist/browser.d.ts.map +1 -0
  41. package/dist/cmp.d.ts +9 -0
  42. package/dist/cmp.d.ts.map +1 -0
  43. package/dist/indexeddbshim-Key.js +553 -252
  44. package/dist/indexeddbshim-Key.js.map +1 -1
  45. package/dist/indexeddbshim-Key.min.js +2 -2
  46. package/dist/indexeddbshim-Key.min.js.map +1 -1
  47. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +17560 -1302
  48. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
  49. package/dist/indexeddbshim-UnicodeIdentifiers.js +4367 -1604
  50. package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
  51. package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -2
  52. package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
  53. package/dist/indexeddbshim-node.cjs +17556 -1302
  54. package/dist/indexeddbshim-node.cjs.map +1 -1
  55. package/dist/indexeddbshim-noninvasive.js +4362 -1604
  56. package/dist/indexeddbshim-noninvasive.js.map +1 -1
  57. package/dist/indexeddbshim-noninvasive.min.js +2 -2
  58. package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
  59. package/dist/indexeddbshim.js +4362 -1604
  60. package/dist/indexeddbshim.js.map +1 -1
  61. package/dist/indexeddbshim.min.js +2 -2
  62. package/dist/indexeddbshim.min.js.map +1 -1
  63. package/dist/node-UnicodeIdentifiers.d.ts +8 -0
  64. package/dist/node-UnicodeIdentifiers.d.ts.map +1 -0
  65. package/dist/node.d.ts +8 -0
  66. package/dist/node.d.ts.map +1 -0
  67. package/dist/nodeWebSQL.d.ts +3 -0
  68. package/dist/nodeWebSQL.d.ts.map +1 -0
  69. package/dist/setGlobalVars.d.ts +79 -0
  70. package/dist/setGlobalVars.d.ts.map +1 -0
  71. package/dist/unicode-regex.d.ts +3 -0
  72. package/dist/unicode-regex.d.ts.map +1 -0
  73. package/dist/util.d.ts +174 -0
  74. package/dist/util.d.ts.map +1 -0
  75. package/index.html +1 -1
  76. package/package.json +51 -37
  77. package/src/CFG.js +89 -11
  78. package/src/DOMException.js +117 -31
  79. package/src/DOMStringList.js +93 -3
  80. package/src/Event.js +19 -4
  81. package/src/IDBCursor.js +350 -76
  82. package/src/IDBDatabase.js +88 -10
  83. package/src/IDBFactory.js +331 -61
  84. package/src/IDBIndex.js +393 -110
  85. package/src/IDBKeyRange.js +90 -17
  86. package/src/IDBObjectStore.js +347 -86
  87. package/src/IDBRequest.js +59 -1
  88. package/src/IDBTransaction.js +254 -46
  89. package/src/IDBVersionChangeEvent.js +28 -3
  90. package/src/Key.d.ts +1 -0
  91. package/src/Key.js +272 -162
  92. package/src/Sca.js +29 -4
  93. package/src/browser-UnicodeIdentifiers.js +5 -1
  94. package/src/cmp.js +5 -5
  95. package/src/node-UnicodeIdentifiers.js +9 -0
  96. package/src/node.js +5 -0
  97. package/src/nodeWebSQL.js +11 -5
  98. package/src/setGlobalVars.js +159 -22
  99. package/src/unicode-regex.js +2 -0
  100. package/src/util.js +229 -40
  101. package/typings/shimIndexedDB.d.ts +9 -0
@@ -2,25 +2,40 @@ import {createDOMException} from './DOMException.js';
2
2
  import * as Key from './Key.js';
3
3
  import * as util from './util.js';
4
4
 
5
- const readonlyProperties = ['lower', 'upper', 'lowerOpen', 'upperOpen'];
5
+ const readonlyProperties = /** @type {const} */ (['lower', 'upper', 'lowerOpen', 'upperOpen']);
6
+
7
+ /**
8
+ * @typedef {globalThis.IDBKeyRange & {
9
+ * __lowerCached: string|null|false,
10
+ * __upperCached: string|null|false,
11
+ * __lowerOpen: boolean,
12
+ * }} IDBKeyRangeFull
13
+ */
6
14
 
7
- /* eslint-disable jsdoc/check-param-names */
8
15
  /**
9
16
  * The IndexedDB KeyRange object.
10
17
  * @see http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#dfn-key-range
11
- * @param {Object} lower
12
- * @param {Object} upper
13
- * @param {Object} lowerOpen
14
- * @param {Object} upperOpen
15
18
  * @throws {TypeError}
16
19
  * @class
17
20
  */
18
21
  function IDBKeyRange () {
19
- /* eslint-enable jsdoc/check-param-names */
22
+ this.__lowerOpen = false;
23
+ this.__upperOpen = false;
20
24
  throw new TypeError('Illegal constructor');
21
25
  }
22
26
  const IDBKeyRangeAlias = IDBKeyRange;
27
+
28
+ /**
29
+ * @param {import('./Key.js').Key|null} lower
30
+ * @param {import('./Key.js').Key|null} upper
31
+ * @param {boolean} lowerOpen
32
+ * @param {boolean} upperOpen
33
+ * @returns {import('./IDBKeyRange.js').IDBKeyRangeFull}
34
+ */
23
35
  IDBKeyRange.__createInstance = function (lower, upper, lowerOpen, upperOpen) {
36
+ /**
37
+ * @class
38
+ */
24
39
  function IDBKeyRange () {
25
40
  this[Symbol.toStringTag] = 'IDBKeyRange';
26
41
  if (lower === undefined && upper === undefined) {
@@ -36,7 +51,10 @@ IDBKeyRange.__createInstance = function (lower, upper, lowerOpen, upperOpen) {
36
51
  Key.convertValueToKeyRethrowingAndIfInvalid(upper);
37
52
  }
38
53
  if (lower !== undefined && upper !== undefined && lower !== upper) {
39
- if (Key.encode(lower) > Key.encode(upper)) {
54
+ if (
55
+ /** @type {string} */ (Key.encode(lower)) >
56
+ /** @type {string} */ (Key.encode(upper))
57
+ ) {
40
58
  throw createDOMException('DataError', '`lower` must not be greater than `upper` argument in `bound()` call.');
41
59
  }
42
60
  }
@@ -47,8 +65,16 @@ IDBKeyRange.__createInstance = function (lower, upper, lowerOpen, upperOpen) {
47
65
  this.__upperOpen = Boolean(upperOpen);
48
66
  }
49
67
  IDBKeyRange.prototype = IDBKeyRangeAlias.prototype;
68
+
69
+ // @ts-expect-error Properties added by `defineProperty/ies`
50
70
  return new IDBKeyRange();
51
71
  };
72
+
73
+ /**
74
+ * @param {import('./Key.js').Key} key
75
+ * @this {IDBKeyRangeFull}
76
+ * @returns {boolean}
77
+ */
52
78
  IDBKeyRange.prototype.includes = function (key) {
53
79
  // We can't do a regular instanceof check as it will create a loop given our hasInstance implementation
54
80
  if (!util.isObj(this) || typeof this.__lowerOpen !== 'boolean') {
@@ -61,6 +87,10 @@ IDBKeyRange.prototype.includes = function (key) {
61
87
  return Key.isKeyInRange(key, this);
62
88
  };
63
89
 
90
+ /**
91
+ * @param {import('./Key.js').Value} value
92
+ * @returns {import('./IDBKeyRange.js').IDBKeyRangeFull}
93
+ */
64
94
  IDBKeyRange.only = function (value) {
65
95
  if (!arguments.length) {
66
96
  throw new TypeError('IDBKeyRange.only requires a value argument');
@@ -68,20 +98,35 @@ IDBKeyRange.only = function (value) {
68
98
  return IDBKeyRange.__createInstance(value, value, false, false);
69
99
  };
70
100
 
71
- IDBKeyRange.lowerBound = function (value /*, open */) {
101
+ /**
102
+ * @param {import('./Key.js').Value} value
103
+ * @returns {globalThis.IDBKeyRange}
104
+ */
105
+ IDBKeyRange.lowerBound = function (value /* , open */) {
72
106
  if (!arguments.length) {
73
107
  throw new TypeError('IDBKeyRange.lowerBound requires a value argument');
74
108
  }
75
109
  // eslint-disable-next-line prefer-rest-params
76
110
  return IDBKeyRange.__createInstance(value, undefined, arguments[1], true);
77
111
  };
78
- IDBKeyRange.upperBound = function (value /*, open */) {
112
+
113
+ /**
114
+ * @param {import('./Key.js').Value} value
115
+ * @returns {globalThis.IDBKeyRange}
116
+ */
117
+ IDBKeyRange.upperBound = function (value /* , open */) {
79
118
  if (!arguments.length) {
80
119
  throw new TypeError('IDBKeyRange.upperBound requires a value argument');
81
120
  }
82
121
  // eslint-disable-next-line prefer-rest-params
83
122
  return IDBKeyRange.__createInstance(undefined, value, true, arguments[1]);
84
123
  };
124
+
125
+ /**
126
+ * @param {import('./Key.js').Value} lower
127
+ * @param {import('./Key.js').Value} upper
128
+ * @returns {globalThis.IDBKeyRange}
129
+ */
85
130
  IDBKeyRange.bound = function (lower, upper /* , lowerOpen, upperOpen */) {
86
131
  if (arguments.length <= 1) {
87
132
  throw new TypeError('IDBKeyRange.bound requires lower and upper arguments');
@@ -99,6 +144,9 @@ readonlyProperties.forEach((prop) => {
99
144
  });
100
145
  // Ensure for proper interface testing that "get <name>" is the function name
101
146
  const o = {
147
+ /**
148
+ * @returns {import('./Key.js').Key|null|boolean}
149
+ */
102
150
  get [prop] () {
103
151
  // We can't do a regular instanceof check as it will create a loop given our hasInstance implementation
104
152
  if (!util.isObj(this) || typeof this.__lowerOpen !== 'boolean') {
@@ -107,23 +155,42 @@ readonlyProperties.forEach((prop) => {
107
155
  return this['__' + prop];
108
156
  }
109
157
  };
110
- const desc = Object.getOwnPropertyDescriptor(o, prop);
158
+ const desc = /** @type {PropertyDescriptor} */ (
159
+ Object.getOwnPropertyDescriptor(o, prop)
160
+ );
111
161
  // desc.enumerable = true; // Default
112
162
  // desc.configurable = true; // Default
113
163
  Object.defineProperty(IDBKeyRange.prototype, prop, desc);
114
164
  });
115
165
 
116
166
  Object.defineProperty(IDBKeyRange, Symbol.hasInstance, {
117
- value: (obj) => util.isObj(obj) && 'upper' in obj && typeof obj.lowerOpen === 'boolean'
167
+ value:
168
+ /**
169
+ * @param {object} obj
170
+ * @returns {boolean}
171
+ */
172
+ (obj) => util.isObj(obj) && 'upper' in obj && 'lowerOpen' in obj &&
173
+ typeof obj.lowerOpen === 'boolean'
118
174
  });
119
175
 
120
176
  Object.defineProperty(IDBKeyRange, 'prototype', {
121
177
  writable: false
122
178
  });
123
179
 
124
- function setSQLForKeyRange (range, quotedKeyColumnName, sql, sqlValues, addAnd, checkCached) {
180
+ /**
181
+ * @param {IDBKeyRangeFull|undefined} range
182
+ * @param {string} quotedKeyColumnName
183
+ * @param {string[]} sql
184
+ * @param {string[]} sqlValues
185
+ * @param {boolean} [addAnd]
186
+ * @param {boolean} [checkCached]
187
+ * @returns {void}
188
+ */
189
+ function setSQLForKeyRange (
190
+ range, quotedKeyColumnName, sql, sqlValues, addAnd, checkCached
191
+ ) {
125
192
  if (range && (range.lower !== undefined || range.upper !== undefined)) {
126
- if (addAnd) sql.push('AND');
193
+ if (addAnd) { sql.push('AND'); }
127
194
  let encodedLowerKey, encodedUpperKey;
128
195
  const hasLower = range.lower !== undefined;
129
196
  const hasUpper = range.upper !== undefined;
@@ -134,21 +201,27 @@ function setSQLForKeyRange (range, quotedKeyColumnName, sql, sqlValues, addAnd,
134
201
  encodedUpperKey = checkCached ? range.__upperCached : Key.encode(range.upper);
135
202
  }
136
203
  if (hasLower) {
137
- sqlValues.push(util.escapeSQLiteStatement(encodedLowerKey));
204
+ sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedLowerKey)));
138
205
  if (hasUpper && encodedLowerKey === encodedUpperKey && !range.lowerOpen && !range.upperOpen) {
139
206
  sql.push(quotedKeyColumnName, '=', '?');
140
207
  return;
141
208
  }
142
209
  sql.push(quotedKeyColumnName, (range.lowerOpen ? '>' : '>='), '?');
143
210
  }
144
- (hasLower && hasUpper) && sql.push('AND');
211
+ if (hasLower && hasUpper) { sql.push('AND'); }
145
212
  if (hasUpper) {
146
213
  sql.push(quotedKeyColumnName, (range.upperOpen ? '<' : '<='), '?');
147
- sqlValues.push(util.escapeSQLiteStatement(encodedUpperKey));
214
+ sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedUpperKey)));
148
215
  }
149
216
  }
150
217
  }
151
218
 
219
+ /**
220
+ * @param {import('./Key.js').Value} value
221
+ * @param {boolean} [nullDisallowed]
222
+ * @throws {DOMException}
223
+ * @returns {import('./IDBKeyRange.js').IDBKeyRangeFull|undefined}
224
+ */
152
225
  function convertValueToKeyRange (value, nullDisallowed) {
153
226
  if (util.instanceOf(value, IDBKeyRange)) {
154
227
  // We still need to validate IDBKeyRange-like objects (the above check is based on loose duck-typing)