fake-indexeddb 6.2.2 → 6.2.3
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.
- package/build/cjs/FDBFactory.js +276 -136
- package/build/cjs/FDBTransaction.js +49 -11
- package/build/cjs/lib/Database.js +21 -12
- package/build/cjs/lib/FakeEventTarget.js +17 -5
- package/build/cjs/lib/extractGetAllOptions.js +2 -2
- package/build/cjs/lib/intersection.js +18 -0
- package/build/cjs/lib/isPotentiallyValidKeyRange.js +13 -20
- package/build/cjs/lib/scheduling.js +4 -4
- package/build/cjs/lib/valueToKey.js +8 -53
- package/build/cjs/lib/valueToKeyWithoutThrowing.js +82 -0
- package/build/esm/FDBFactory.js +276 -136
- package/build/esm/FDBTransaction.js +49 -11
- package/build/esm/lib/Database.js +21 -12
- package/build/esm/lib/FakeEventTarget.js +17 -5
- package/build/esm/lib/extractGetAllOptions.js +2 -2
- package/build/esm/lib/intersection.js +12 -0
- package/build/esm/lib/isPotentiallyValidKeyRange.js +12 -20
- package/build/esm/lib/scheduling.js +4 -4
- package/build/esm/lib/valueToKey.js +7 -52
- package/build/esm/lib/valueToKeyWithoutThrowing.js +75 -0
- package/package.json +1 -1
|
@@ -12,6 +12,15 @@ const stopped = (event, listener) => {
|
|
|
12
12
|
// http://www.w3.org/TR/dom/#concept-event-listener-invoke
|
|
13
13
|
const invokeEventListeners = (event, obj) => {
|
|
14
14
|
event.currentTarget = obj;
|
|
15
|
+
const errors = [];
|
|
16
|
+
const invoke = callback => {
|
|
17
|
+
try {
|
|
18
|
+
// @ts-expect-error EventCallback's types are not quite right here
|
|
19
|
+
callback.call(event.currentTarget, event);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
errors.push(err);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
15
24
|
|
|
16
25
|
// The callback might cause obj.listeners to mutate as we traverse it.
|
|
17
26
|
// Take a copy of the array so that nothing sneaks in and we don't lose
|
|
@@ -20,9 +29,7 @@ const invokeEventListeners = (event, obj) => {
|
|
|
20
29
|
if (event.type !== listener.type || stopped(event, listener)) {
|
|
21
30
|
continue;
|
|
22
31
|
}
|
|
23
|
-
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
listener.callback.call(event.currentTarget, event);
|
|
32
|
+
invoke(listener.callback);
|
|
26
33
|
}
|
|
27
34
|
const typeToProp = {
|
|
28
35
|
abort: "onabort",
|
|
@@ -46,10 +53,15 @@ const invokeEventListeners = (event, obj) => {
|
|
|
46
53
|
type: event.type
|
|
47
54
|
};
|
|
48
55
|
if (!stopped(event, listener)) {
|
|
49
|
-
|
|
50
|
-
listener.callback.call(event.currentTarget, event);
|
|
56
|
+
invoke(listener.callback);
|
|
51
57
|
}
|
|
52
58
|
}
|
|
59
|
+
|
|
60
|
+
// we want to execute all listeners before deciding if we want to throw, because there could be an error thrown by
|
|
61
|
+
// the first listener, but the second should still be invoked
|
|
62
|
+
if (errors.length) {
|
|
63
|
+
throw new AggregateError(errors);
|
|
64
|
+
}
|
|
53
65
|
};
|
|
54
66
|
class FakeEventTarget {
|
|
55
67
|
listeners = [];
|
|
@@ -11,8 +11,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
11
11
|
const extractGetAllOptions = (queryOrOptions, count, numArguments) => {
|
|
12
12
|
let query;
|
|
13
13
|
let direction;
|
|
14
|
-
if ((0, _isPotentiallyValidKeyRange.default)(queryOrOptions)) {
|
|
15
|
-
// queryOrOptions is FDBKeyRange | Key
|
|
14
|
+
if (queryOrOptions === undefined || queryOrOptions === null || (0, _isPotentiallyValidKeyRange.default)(queryOrOptions)) {
|
|
15
|
+
// queryOrOptions is FDBKeyRange | Key | null | undefined
|
|
16
16
|
query = queryOrOptions;
|
|
17
17
|
if (numArguments > 1 && count !== undefined) {
|
|
18
18
|
count = (0, _enforceRange.default)(count, "unsigned long");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.intersection = intersection;
|
|
7
|
+
/**
|
|
8
|
+
* Minimal polyfill of `Set.prototype.intersection`, available in Node 22+.
|
|
9
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection
|
|
10
|
+
* @param set1
|
|
11
|
+
* @param set2
|
|
12
|
+
*/
|
|
13
|
+
function intersection(set1, set2) {
|
|
14
|
+
if ("intersection" in set1) {
|
|
15
|
+
return set1.intersection(set2);
|
|
16
|
+
}
|
|
17
|
+
return new Set([...set1].filter(item => set2.has(item)));
|
|
18
|
+
}
|
|
@@ -5,29 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _FDBKeyRange = _interopRequireDefault(require("../FDBKeyRange.js"));
|
|
8
|
-
var
|
|
8
|
+
var _valueToKeyWithoutThrowing = _interopRequireWildcard(require("./valueToKeyWithoutThrowing.js"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
// https://www.w3.org/TR/IndexedDB/#is-a-potentially-valid-key-range
|
|
11
12
|
const isPotentiallyValidKeyRange = value => {
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
typeof value === "string" ||
|
|
24
|
-
// buffer source type
|
|
25
|
-
// note: we are explicitly _not_ checking for detachedness here, to match Chromium's behavior
|
|
26
|
-
// see: https://github.com/w3c/IndexedDB/issues/465
|
|
27
|
-
value instanceof ArrayBuffer || (0, _isSharedArrayBuffer.default)(value) || typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView && ArrayBuffer.isView(value) ||
|
|
28
|
-
// array exotic type
|
|
29
|
-
Array.isArray(value)
|
|
30
|
-
);
|
|
13
|
+
// If value is a key range, return true.
|
|
14
|
+
if (value instanceof _FDBKeyRange.default) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Let key be the result of converting a value to a key with value.
|
|
19
|
+
const key = (0, _valueToKeyWithoutThrowing.default)(value);
|
|
20
|
+
|
|
21
|
+
// If key is "invalid type" return false.
|
|
22
|
+
// Else return true.
|
|
23
|
+
return key !== _valueToKeyWithoutThrowing.INVALID_TYPE;
|
|
31
24
|
};
|
|
32
25
|
var _default = exports.default = isPotentiallyValidKeyRange;
|
|
33
26
|
module.exports = exports.default;
|
|
@@ -25,10 +25,10 @@ function getSetImmediateFromJsdom() {
|
|
|
25
25
|
|
|
26
26
|
// waiting on this PR for typescript types: https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1249
|
|
27
27
|
|
|
28
|
-
// '
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
// 'postTask' runs right after microtasks, so equivalent to setTimeout but without the 4ms clamping.
|
|
29
|
+
// Using the default priority of 'user-visible' to avoid blocking input while still running fairly quickly.
|
|
30
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/API/Prioritized_Task_Scheduling_API#task_priorities
|
|
31
|
+
const schedulerPostTask = typeof scheduler !== "undefined" && (fn => scheduler.postTask(fn));
|
|
32
32
|
|
|
33
33
|
// fallback for environments that don't support any of the above
|
|
34
34
|
const doSetTimeout = fn => setTimeout(fn, 0);
|
|
@@ -5,63 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _errors = require("./errors.js");
|
|
8
|
-
var
|
|
9
|
-
function
|
|
8
|
+
var _valueToKeyWithoutThrowing = _interopRequireWildcard(require("./valueToKeyWithoutThrowing.js"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
10
|
// https://w3c.github.io/IndexedDB/#convert-value-to-key
|
|
11
|
+
// Plus throwing a DataError for invalid value/invalid key, which is commonly done
|
|
12
|
+
// in lots of IndexedDB operations
|
|
11
13
|
const valueToKey = (input, seen) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return input;
|
|
17
|
-
} else if (Object.prototype.toString.call(input) === "[object Date]") {
|
|
18
|
-
const ms = input.valueOf();
|
|
19
|
-
if (isNaN(ms)) {
|
|
20
|
-
throw new _errors.DataError();
|
|
21
|
-
}
|
|
22
|
-
return new Date(ms);
|
|
23
|
-
} else if (typeof input === "string") {
|
|
24
|
-
return input;
|
|
25
|
-
} else if (
|
|
26
|
-
// https://w3c.github.io/IndexedDB/#ref-for-dfn-buffer-source-type
|
|
27
|
-
(input instanceof ArrayBuffer || (0, _isSharedArrayBuffer.default)(input) || typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView && ArrayBuffer.isView(input)) &&
|
|
28
|
-
// We can't consistently test detachedness, so instead we check if byteLength === 0
|
|
29
|
-
// This isn't foolproof, but there's no perfect way to detect if Uint8Arrays or
|
|
30
|
-
// SharedArrayBuffers are detached
|
|
31
|
-
!("detached" in input ? input.detached : input.byteLength === 0)) {
|
|
32
|
-
let arrayBuffer;
|
|
33
|
-
let offset = 0;
|
|
34
|
-
let length = 0;
|
|
35
|
-
if (input instanceof ArrayBuffer || (0, _isSharedArrayBuffer.default)(input)) {
|
|
36
|
-
arrayBuffer = input;
|
|
37
|
-
length = input.byteLength;
|
|
38
|
-
} else {
|
|
39
|
-
arrayBuffer = input.buffer;
|
|
40
|
-
offset = input.byteOffset;
|
|
41
|
-
length = input.byteLength;
|
|
42
|
-
}
|
|
43
|
-
return arrayBuffer.slice(offset, offset + length);
|
|
44
|
-
} else if (Array.isArray(input)) {
|
|
45
|
-
if (seen === undefined) {
|
|
46
|
-
seen = new Set();
|
|
47
|
-
} else if (seen.has(input)) {
|
|
48
|
-
throw new _errors.DataError();
|
|
49
|
-
}
|
|
50
|
-
seen.add(input);
|
|
51
|
-
const keys = [];
|
|
52
|
-
for (let i = 0; i < input.length; i++) {
|
|
53
|
-
const hop = Object.hasOwn(input, i);
|
|
54
|
-
if (!hop) {
|
|
55
|
-
throw new _errors.DataError();
|
|
56
|
-
}
|
|
57
|
-
const entry = input[i];
|
|
58
|
-
const key = valueToKey(entry, seen);
|
|
59
|
-
keys.push(key);
|
|
60
|
-
}
|
|
61
|
-
return keys;
|
|
62
|
-
} else {
|
|
14
|
+
const result = (0, _valueToKeyWithoutThrowing.default)(input, seen);
|
|
15
|
+
if (result === _valueToKeyWithoutThrowing.INVALID_VALUE || result === _valueToKeyWithoutThrowing.INVALID_TYPE) {
|
|
16
|
+
// If key is "invalid value" or "invalid type", throw a "DataError" DOMException
|
|
63
17
|
throw new _errors.DataError();
|
|
64
18
|
}
|
|
19
|
+
return result;
|
|
65
20
|
};
|
|
66
21
|
var _default = exports.default = valueToKey;
|
|
67
22
|
module.exports = exports.default;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.INVALID_VALUE = exports.INVALID_TYPE = void 0;
|
|
7
|
+
var _isSharedArrayBuffer = _interopRequireDefault(require("./isSharedArrayBuffer.js"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const INVALID_TYPE = exports.INVALID_TYPE = Symbol("INVALID_TYPE");
|
|
10
|
+
const INVALID_VALUE = exports.INVALID_VALUE = Symbol("INVALID_VALUE");
|
|
11
|
+
|
|
12
|
+
// https://w3c.github.io/IndexedDB/#convert-value-to-key
|
|
13
|
+
// The "without exceptions" version is because we typically want to throw exceptions (DataError) but not for
|
|
14
|
+
// the "is potentially valid key range" routine.
|
|
15
|
+
const valueToKeyWithoutThrowing = (input, seen) => {
|
|
16
|
+
if (typeof input === "number") {
|
|
17
|
+
if (isNaN(input)) {
|
|
18
|
+
// If input is NaN then return "invalid value".
|
|
19
|
+
return INVALID_VALUE;
|
|
20
|
+
}
|
|
21
|
+
return input;
|
|
22
|
+
} else if (Object.prototype.toString.call(input) === "[object Date]") {
|
|
23
|
+
const ms = input.valueOf();
|
|
24
|
+
if (isNaN(ms)) {
|
|
25
|
+
// If ms is NaN then return "invalid value".
|
|
26
|
+
return INVALID_VALUE;
|
|
27
|
+
}
|
|
28
|
+
return new Date(ms);
|
|
29
|
+
} else if (typeof input === "string") {
|
|
30
|
+
return input;
|
|
31
|
+
} else if (
|
|
32
|
+
// https://w3c.github.io/IndexedDB/#ref-for-dfn-buffer-source-type
|
|
33
|
+
input instanceof ArrayBuffer || (0, _isSharedArrayBuffer.default)(input) || typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView && ArrayBuffer.isView(input)) {
|
|
34
|
+
// We can't consistently test detachedness, so instead we check if byteLength === 0
|
|
35
|
+
// This isn't foolproof, but there's no perfect way to detect if Uint8Arrays or
|
|
36
|
+
// SharedArrayBuffers are detached
|
|
37
|
+
if ("detached" in input ? input.detached : input.byteLength === 0) {
|
|
38
|
+
// If input is detached then return "invalid value".
|
|
39
|
+
return INVALID_VALUE;
|
|
40
|
+
}
|
|
41
|
+
let arrayBuffer;
|
|
42
|
+
let offset = 0;
|
|
43
|
+
let length = 0;
|
|
44
|
+
if (input instanceof ArrayBuffer || (0, _isSharedArrayBuffer.default)(input)) {
|
|
45
|
+
arrayBuffer = input;
|
|
46
|
+
length = input.byteLength;
|
|
47
|
+
} else {
|
|
48
|
+
arrayBuffer = input.buffer;
|
|
49
|
+
offset = input.byteOffset;
|
|
50
|
+
length = input.byteLength;
|
|
51
|
+
}
|
|
52
|
+
return arrayBuffer.slice(offset, offset + length);
|
|
53
|
+
} else if (Array.isArray(input)) {
|
|
54
|
+
if (seen === undefined) {
|
|
55
|
+
seen = new Set();
|
|
56
|
+
} else if (seen.has(input)) {
|
|
57
|
+
// If seen contains input, then return "invalid value".
|
|
58
|
+
return INVALID_VALUE;
|
|
59
|
+
}
|
|
60
|
+
seen.add(input);
|
|
61
|
+
const keys = [];
|
|
62
|
+
for (let i = 0; i < input.length; i++) {
|
|
63
|
+
const hop = Object.hasOwn(input, i);
|
|
64
|
+
if (!hop) {
|
|
65
|
+
// If hop is false, return "invalid value".
|
|
66
|
+
return INVALID_VALUE;
|
|
67
|
+
}
|
|
68
|
+
const entry = input[i];
|
|
69
|
+
const key = valueToKeyWithoutThrowing(entry, seen);
|
|
70
|
+
// If key is "invalid value" or "invalid type" abort these steps and return "invalid value".
|
|
71
|
+
if (key === INVALID_VALUE || key === INVALID_TYPE) {
|
|
72
|
+
return INVALID_VALUE;
|
|
73
|
+
}
|
|
74
|
+
keys.push(key);
|
|
75
|
+
}
|
|
76
|
+
return keys;
|
|
77
|
+
} else {
|
|
78
|
+
// Otherwise: Return "invalid type".
|
|
79
|
+
return INVALID_TYPE;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var _default = exports.default = valueToKeyWithoutThrowing;
|