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
@@ -8,6 +8,7 @@ import CFG from './CFG.js';
8
8
  * @returns {DOMException}
9
9
  */
10
10
  function createNativeDOMException (name, message) {
11
+ // @ts-expect-error It's ok
11
12
  return new DOMException.prototype.constructor(
12
13
  message,
13
14
  name || 'DOMException'
@@ -15,6 +16,20 @@ function createNativeDOMException (name, message) {
15
16
  }
16
17
 
17
18
  // From web-platform-tests testharness.js name_code_map (though not in new spec)
19
+
20
+ /**
21
+ * @typedef {"IndexSizeError"|"HierarchyRequestError"|"WrongDocumentError"|
22
+ * "InvalidCharacterError"|"NoModificationAllowedError"|"NotFoundError"|
23
+ * "NotSupportedError"|"InUseAttributeError"|"InvalidStateError"|
24
+ * "SyntaxError"|"InvalidModificationError"|"NamespaceError"|
25
+ * "InvalidAccessError"|"TypeMismatchError"|"SecurityError"|
26
+ * "NetworkError"|"AbortError"|"URLMismatchError"|"QuotaExceededError"|
27
+ * "TimeoutError"|"InvalidNodeTypeError"|"DataCloneError"|"EncodingError"|
28
+ * "NotReadableError"|"UnknownError"|"ConstraintError"|"DataError"|
29
+ * "TransactionInactiveError"|"ReadOnlyError"|"VersionError"|
30
+ * "OperationError"|"NotAllowedError"} Code
31
+ */
32
+
18
33
  const codes = {
19
34
  IndexSizeError: 1,
20
35
  HierarchyRequestError: 3,
@@ -51,6 +66,17 @@ const codes = {
51
66
  NotAllowedError: 0
52
67
  };
53
68
 
69
+ /**
70
+ * @typedef {"INDEX_SIZE_ERR"|"DOMSTRING_SIZE_ERR"|"HIERARCHY_REQUEST_ERR"|
71
+ * "WRONG_DOCUMENT_ERR"|"INVALID_CHARACTER_ERR"|"NO_DATA_ALLOWED_ERR"|
72
+ * "NO_MODIFICATION_ALLOWED_ERR"|"NOT_FOUND_ERR"|"NOT_SUPPORTED_ERR"|
73
+ * "INUSE_ATTRIBUTE_ERR"|"INVALID_STATE_ERR"|"SYNTAX_ERR"|
74
+ * "INVALID_MODIFICATION_ERR"|"NAMESPACE_ERR"|"INVALID_ACCESS_ERR"|
75
+ * "VALIDATION_ERR"|"TYPE_MISMATCH_ERR"|"SECURITY_ERR"|"NETWORK_ERR"|
76
+ * "ABORT_ERR"|"URL_MISMATCH_ERR"|"QUOTA_EXCEEDED_ERR"|"TIMEOUT_ERR"|
77
+ * "INVALID_NODE_TYPE_ERR"|"DATA_CLONE_ERR"} LegacyCode
78
+ */
79
+
54
80
  const legacyCodes = {
55
81
  INDEX_SIZE_ERR: 1,
56
82
  DOMSTRING_SIZE_ERR: 2,
@@ -81,13 +107,20 @@ const legacyCodes = {
81
107
 
82
108
  /**
83
109
  *
84
- * @returns {DOMException}
110
+ * @returns {typeof DOMException}
85
111
  */
86
112
  function createNonNativeDOMExceptionClass () {
113
+ /**
114
+ * @param {string|undefined} message
115
+ * @param {Code|LegacyCode} name
116
+ * @returns {void}
117
+ */
87
118
  function DOMException (message, name) {
88
119
  // const err = Error.prototype.constructor.call(this, message); // Any use to this? Won't set this.message
89
120
  this[Symbol.toStringTag] = 'DOMException';
90
- this._code = name in codes ? codes[name] : (legacyCodes[name] || 0);
121
+ this._code = name in codes
122
+ ? codes[/** @type {Code} */ (name)]
123
+ : (legacyCodes[/** @type {LegacyCode} */ (name)] || 0);
91
124
  this._name = name || 'Error';
92
125
  // We avoid `String()` in this next line as it converts Symbols
93
126
  this._message = message === undefined ? '' : ('' + message); // eslint-disable-line no-implicit-coercion
@@ -118,19 +151,29 @@ function createNonNativeDOMExceptionClass () {
118
151
  // Necessary for W3C tests which complains if `DOMException` has properties on its "own" prototype
119
152
 
120
153
  // class DummyDOMException extends Error {}; // Sometimes causing problems in Node
121
- // eslint-disable-next-line func-name-matching
154
+ /* eslint-disable func-name-matching */
155
+ /**
156
+ * @class
157
+ */
122
158
  const DummyDOMException = function DOMException () { /* */ };
159
+ /* eslint-enable func-name-matching */
123
160
  DummyDOMException.prototype = Object.create(Error.prototype); // Intended for subclassing
124
- ['name', 'message'].forEach((prop) => {
161
+ /** @type {const} */ (['name', 'message']).forEach((prop) => {
125
162
  Object.defineProperty(DummyDOMException.prototype, prop, {
126
163
  enumerable: true,
164
+ /**
165
+ * @this {DOMException}
166
+ * @returns {string}
167
+ */
127
168
  get () {
128
169
  if (!(this instanceof DOMException ||
170
+ // @ts-expect-error Just checking
129
171
  this instanceof DummyDOMException ||
172
+ // @ts-expect-error Just checking
130
173
  this instanceof Error)) {
131
174
  throw new TypeError('Illegal invocation');
132
175
  }
133
- return this['_' + prop];
176
+ return this[prop === 'name' ? '_name' : '_message'];
134
177
  }
135
178
  });
136
179
  });
@@ -142,6 +185,7 @@ function createNonNativeDOMExceptionClass () {
142
185
  throw new TypeError('Illegal invocation');
143
186
  }
144
187
  });
188
+ // @ts-expect-error It's ok
145
189
  DOMException.prototype = new DummyDOMException();
146
190
 
147
191
  DOMException.prototype[Symbol.toStringTag] = 'DOMExceptionPrototype';
@@ -149,19 +193,25 @@ function createNonNativeDOMExceptionClass () {
149
193
  writable: false
150
194
  });
151
195
 
152
- Object.keys(codes).forEach((codeName) => {
153
- Object.defineProperty(DOMException.prototype, codeName, {
154
- enumerable: true,
155
- configurable: false,
156
- value: codes[codeName]
157
- });
158
- Object.defineProperty(DOMException, codeName, {
159
- enumerable: true,
160
- configurable: false,
161
- value: codes[codeName]
162
- });
163
- });
164
- Object.keys(legacyCodes).forEach((codeName) => {
196
+ const keys = Object.keys(codes);
197
+
198
+ /** @type {(keyof codes)[]} */ (keys).forEach(
199
+ (codeName) => {
200
+ Object.defineProperty(DOMException.prototype, codeName, {
201
+ enumerable: true,
202
+ configurable: false,
203
+ value: codes[codeName]
204
+ });
205
+ Object.defineProperty(DOMException, codeName, {
206
+ enumerable: true,
207
+ configurable: false,
208
+ value: codes[codeName]
209
+ });
210
+ }
211
+ );
212
+ /** @type {(keyof legacyCodes)[]} */ (Object.keys(legacyCodes)).forEach((
213
+ codeName
214
+ ) => {
165
215
  Object.defineProperty(DOMException.prototype, codeName, {
166
216
  enumerable: true,
167
217
  configurable: false,
@@ -180,6 +230,7 @@ function createNonNativeDOMExceptionClass () {
180
230
  value: DOMException
181
231
  });
182
232
 
233
+ // @ts-expect-error We don't need all its properties
183
234
  return DOMException;
184
235
  }
185
236
 
@@ -195,25 +246,39 @@ function createNonNativeDOMException (name, message) {
195
246
  return new ShimNonNativeDOMException(message, name);
196
247
  }
197
248
 
249
+ /**
250
+ * @typedef {{
251
+ * message: string|DOMString
252
+ * }} ErrorLike
253
+ */
254
+
198
255
  /**
199
256
  * Logs detailed error information to the console.
200
257
  * @param {string} name
201
258
  * @param {string} message
202
- * @param {string|Error|null} error
259
+ * @param {string|ErrorLike|boolean|null} [error]
203
260
  * @returns {void}
204
261
  */
205
262
  function logError (name, message, error) {
206
263
  if (CFG.DEBUG) {
207
- if (error && error.message) {
208
- error = error.message;
209
- }
264
+ const msg = error && typeof error === 'object' && error.message
265
+ ? error.message
266
+ : /** @type {string} */ (error);
210
267
 
211
268
  const method = typeof (console.error) === 'function' ? 'error' : 'log';
212
- console[method](name + ': ' + message + '. ' + (error || ''));
269
+ console[method](name + ': ' + message + '. ' + (msg || ''));
213
270
  console.trace && console.trace();
214
271
  }
215
272
  }
216
273
 
274
+ /**
275
+ * @typedef {any} ArbitraryValue
276
+ */
277
+
278
+ /**
279
+ * @param {ArbitraryValue} obj
280
+ * @returns {boolean}
281
+ */
217
282
  function isErrorOrDOMErrorOrDOMException (obj) {
218
283
  return obj && typeof obj === 'object' && // We don't use util.isObj here as mutual dependency causing problems in Babel with browser
219
284
  typeof obj.name === 'string';
@@ -223,7 +288,7 @@ function isErrorOrDOMErrorOrDOMException (obj) {
223
288
  * Finds the error argument. This is useful because some WebSQL callbacks
224
289
  * pass the error as the first argument, and some pass it as the second
225
290
  * argument.
226
- * @param {Array} args
291
+ * @param {(Error|{message?: string, name?: string}|any)[]} args
227
292
  * @returns {Error|DOMException|undefined}
228
293
  */
229
294
  function findError (args) {
@@ -246,8 +311,10 @@ function findError (args) {
246
311
 
247
312
  /**
248
313
  *
249
- * @param {external:WebSQLError} webSQLErr
250
- * @returns {DOMException}
314
+ * @param {SQLError} webSQLErr
315
+ * @returns {(DOMException|Error) & {
316
+ * sqlError: SQLError
317
+ * }}
251
318
  */
252
319
  function webSQLErrback (webSQLErr) {
253
320
  let name, message;
@@ -275,7 +342,13 @@ function webSQLErrback (webSQLErr) {
275
342
  }
276
343
  }
277
344
  message += ' (' + webSQLErr.message + ')--(' + webSQLErr.code + ')';
278
- const err = createDOMException(name, message);
345
+ const err =
346
+ /**
347
+ * @type {(Error | DOMException) & {
348
+ * sqlError: SQLError
349
+ * }}
350
+ */
351
+ (createDOMException(name, message));
279
352
  err.sqlError = webSQLErr;
280
353
  return err;
281
354
  }
@@ -292,11 +365,25 @@ try {
292
365
  } catch (e) {}
293
366
 
294
367
  const createDOMException = useNativeDOMException
295
- ? function (name, message, error) {
368
+ // eslint-disable-next-line operator-linebreak -- Need JSDoc
369
+ ? /**
370
+ * @param {string} name
371
+ * @param {string} message
372
+ * @param {ErrorLike} [error]
373
+ * @returns {DOMException}
374
+ */
375
+ function (name, message, error) {
296
376
  logError(name, message, error);
297
377
  return createNativeDOMException(name, message);
298
378
  }
299
- : function (name, message, error) {
379
+ // eslint-disable-next-line operator-linebreak -- Need JSDoc
380
+ : /**
381
+ * @param {string} name
382
+ * @param {string} message
383
+ * @param {ErrorLike} [error]
384
+ * @returns {Error}
385
+ */
386
+ function (name, message, error) {
300
387
  logError(name, message, error);
301
388
  return createNonNativeDOMException(name, message);
302
389
  };
@@ -1,3 +1,23 @@
1
+ /**
2
+ * @typedef {number} Integer
3
+ */
4
+
5
+ /**
6
+ * @typedef {{
7
+ * _items: string[],
8
+ * _length: Integer,
9
+ * [key: number]: string,
10
+ * addIndexes: () => void,
11
+ * sortList: () => string[],
12
+ * push: (item: string) => void,
13
+ * clone: () => DOMStringListFull,
14
+ * contains: (str: string) => boolean,
15
+ * indexOf: (str: string) => Integer,
16
+ * splice: (index: Integer, howmany: Integer, ...args: any) => void
17
+ * length: Integer
18
+ * }} DOMStringListFull
19
+ */
20
+
1
21
  let cleanInterface = false;
2
22
 
3
23
  const testObject = {test: true};
@@ -19,17 +39,33 @@ if (Object.defineProperty) {
19
39
  * @class
20
40
  */
21
41
  const DOMStringList = function () {
42
+ /** @type {string[]} */
43
+ this._items = [];
44
+ /** @type {Integer} */
45
+ this._length = 0;
22
46
  throw new TypeError('Illegal constructor');
23
47
  };
48
+
49
+ // @ts-expect-error It's ok
24
50
  DOMStringList.prototype = {
25
51
  constructor: DOMStringList,
26
52
  // Interface.
53
+
54
+ /**
55
+ * @param {string} str
56
+ * @returns {boolean}
57
+ */
27
58
  contains (str) {
28
59
  if (!arguments.length) {
29
60
  throw new TypeError('DOMStringList.contains must be supplied a value');
30
61
  }
31
62
  return this._items.includes(str);
32
63
  },
64
+
65
+ /**
66
+ * @param {number} key
67
+ * @returns {string|null}
68
+ */
33
69
  item (key) {
34
70
  if (!arguments.length) {
35
71
  throw new TypeError('DOMStringList.item must be supplied a value');
@@ -41,6 +77,9 @@ DOMStringList.prototype = {
41
77
  },
42
78
 
43
79
  // Helpers. Should only be used internally.
80
+ /**
81
+ * @returns {DOMStringListFull}
82
+ */
44
83
  clone () {
45
84
  const stringList = DOMStringList.__createInstance();
46
85
  stringList._items = this._items.slice();
@@ -48,11 +87,19 @@ DOMStringList.prototype = {
48
87
  stringList.addIndexes();
49
88
  return stringList;
50
89
  },
90
+ /**
91
+ * @this {DOMStringListFull}
92
+ * @returns {void}
93
+ */
51
94
  addIndexes () {
52
95
  for (let i = 0; i < this._items.length; i++) {
53
96
  this[i] = this._items[i];
54
97
  }
55
98
  },
99
+ /**
100
+ * @this {DOMStringListFull}
101
+ * @returns {string[]}
102
+ */
56
103
  sortList () {
57
104
  // http://w3c.github.io/IndexedDB/#sorted-list
58
105
  // https://tc39.github.io/ecma262/#sec-abstract-relational-comparison
@@ -60,22 +107,49 @@ DOMStringList.prototype = {
60
107
  this.addIndexes();
61
108
  return this._items;
62
109
  },
110
+ /**
111
+ * @param {(value: string, i: Integer, arr: string[]) => void} cb
112
+ * @param {object} thisArg
113
+ * @returns {void}
114
+ */
63
115
  forEach (cb, thisArg) {
64
116
  // eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
65
117
  this._items.forEach(cb, thisArg);
66
118
  },
119
+ /**
120
+ * @param {(value: string, i: Integer, arr: string[]) => any[]} cb
121
+ * @param {object} thisArg
122
+ * @returns {any[]}
123
+ */
67
124
  map (cb, thisArg) {
68
125
  // eslint-disable-next-line unicorn/no-array-callback-reference, unicorn/no-array-method-this-argument
69
126
  return this._items.map(cb, thisArg);
70
127
  },
128
+ /**
129
+ * @param {string} str
130
+ * @returns {Integer}
131
+ */
71
132
  indexOf (str) {
72
133
  return this._items.indexOf(str);
73
134
  },
135
+ /**
136
+ * @param {string} item
137
+ * @this {DOMStringListFull}
138
+ * @returns {void}
139
+ */
74
140
  push (item) {
75
141
  this._items.push(item);
76
142
  this._length++;
77
143
  this.sortList();
78
144
  },
145
+ /**
146
+ * @typedef {any} AnyArgs
147
+ */
148
+ /**
149
+ * @param {[index: Integer, howmany: Integer, ...args: any]} args
150
+ * @this {DOMStringListFull}
151
+ * @returns {void}
152
+ */
79
153
  splice (...args /* index, howmany, item1, ..., itemX */) {
80
154
  this._items.splice(...args);
81
155
  this._length = this._items.length;
@@ -99,14 +173,29 @@ DOMStringList.prototype = {
99
173
  }
100
174
  }
101
175
  };
176
+
177
+ /**
178
+ * @typedef {any} AnyValue
179
+ */
102
180
  Object.defineProperty(DOMStringList, Symbol.hasInstance, {
181
+ /**
182
+ * @param {AnyValue} obj
183
+ * @returns {boolean}
184
+ */
103
185
  value (obj) {
104
186
  return Object.prototype.toString.call(obj) === 'DOMStringListPrototype';
105
187
  }
106
188
  });
107
189
  const DOMStringListAlias = DOMStringList;
108
190
  Object.defineProperty(DOMStringList, '__createInstance', {
191
+ /**
192
+ * @returns {DOMStringListFull}
193
+ */
109
194
  value () {
195
+ /**
196
+ * @class
197
+ * @this {DOMStringList}
198
+ */
110
199
  const DOMStringList = function DOMStringList () {
111
200
  this.toString = function () {
112
201
  return '[object DOMStringList]';
@@ -118,11 +207,11 @@ Object.defineProperty(DOMStringList, '__createInstance', {
118
207
  return this._length;
119
208
  }
120
209
  });
121
- this._items = [];
210
+ this._items = /** @type {string[]} */ ([]);
122
211
  this._length = 0;
123
212
  };
124
213
  DOMStringList.prototype = DOMStringListAlias.prototype;
125
- return new DOMStringList();
214
+ return /** @type {DOMStringListFull} */ (new DOMStringList());
126
215
  }
127
216
  });
128
217
 
@@ -139,6 +228,7 @@ if (cleanInterface) {
139
228
  });
140
229
 
141
230
  // Illegal invocations
231
+ // @ts-expect-error No return value
142
232
  Object.defineProperty(DOMStringList.prototype, 'length', {
143
233
  configurable: true,
144
234
  enumerable: true,
package/src/Event.js CHANGED
@@ -1,14 +1,21 @@
1
1
  import {ShimEventTarget, ShimEvent, ShimCustomEvent} from 'eventtargeter';
2
2
  import * as util from './util.js';
3
3
 
4
+ /**
5
+ * @typedef {Error} DebuggingError
6
+ */
7
+
4
8
  /**
5
9
  *
6
10
  * @param {string} type
7
- * @param {Any} debug
8
- * @param {EventInit} evInit
9
- * @returns {Event}
11
+ * @param {DebuggingError|null} [debug]
12
+ * @param {EventInit} [evInit]
13
+ * @returns {Event & {
14
+ * __legacyOutputDidListenersThrowError?: boolean
15
+ * }}
10
16
  */
11
17
  function createEvent (type, debug, evInit) {
18
+ // @ts-expect-error It's ok
12
19
  const ev = new ShimEvent(type, evInit);
13
20
  ev.debug = debug;
14
21
  return ev;
@@ -16,7 +23,15 @@ function createEvent (type, debug, evInit) {
16
23
 
17
24
  // We don't add within polyfill repo as might not always be the desired implementation
18
25
  Object.defineProperty(ShimEvent, Symbol.hasInstance, {
19
- value: (obj) => util.isObj(obj) && 'target' in obj && typeof obj.bubbles === 'boolean'
26
+ /**
27
+ * @typedef {any} AnyValue
28
+ */
29
+ value:
30
+ /**
31
+ * @param {AnyValue} obj
32
+ * @returns {boolean}
33
+ */
34
+ (obj) => util.isObj(obj) && 'target' in obj && 'bubbles' in obj && typeof obj.bubbles === 'boolean'
20
35
  });
21
36
 
22
37
  export {createEvent, ShimEvent, ShimCustomEvent, ShimEventTarget};