fake-indexeddb 4.0.0-beta.2 → 4.0.0-beta.6
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/README.md +6 -10
- package/auto/index.js +35 -0
- package/{auto.js → auto/index.mjs} +12 -12
- package/auto/package.json +3 -0
- package/build/cjs/FDBCursor.js +591 -0
- package/build/cjs/FDBCursorWithValue.js +27 -0
- package/build/cjs/FDBDatabase.js +226 -0
- package/build/cjs/FDBFactory.js +310 -0
- package/build/cjs/FDBIndex.js +252 -0
- package/build/cjs/FDBKeyRange.js +103 -0
- package/build/cjs/FDBObjectStore.js +508 -0
- package/build/cjs/FDBOpenDBRequest.js +24 -0
- package/build/cjs/FDBRequest.js +55 -0
- package/build/cjs/FDBTransaction.js +260 -0
- package/build/cjs/FDBVersionChangeEvent.js +27 -0
- package/build/cjs/fakeIndexedDB.js +15 -0
- package/build/cjs/index.js +107 -0
- package/build/cjs/lib/Database.js +48 -0
- package/build/cjs/lib/FakeDOMStringList.js +86 -0
- package/build/cjs/lib/FakeEvent.js +52 -0
- package/build/cjs/lib/FakeEventTarget.js +128 -0
- package/build/cjs/lib/Index.js +187 -0
- package/build/cjs/lib/KeyGenerator.js +38 -0
- package/build/cjs/lib/ObjectStore.js +210 -0
- package/build/cjs/lib/RecordStore.js +180 -0
- package/build/cjs/lib/binarySearch.js +104 -0
- package/build/cjs/lib/canInjectKey.js +42 -0
- package/build/cjs/lib/cmp.js +111 -0
- package/build/cjs/lib/enforceRange.js +24 -0
- package/build/cjs/lib/errors.js +130 -0
- package/build/cjs/lib/extractKey.js +61 -0
- package/build/cjs/lib/scheduling.js +35 -0
- package/build/cjs/lib/structuredClone.js +30 -0
- package/build/cjs/lib/types.js +1 -0
- package/build/cjs/lib/validateKeyPath.js +65 -0
- package/build/cjs/lib/valueToKey.js +64 -0
- package/build/cjs/lib/valueToKeyRange.js +36 -0
- package/build/cjs/package.json +1 -0
- package/build/esm/FDBCursor.js +574 -0
- package/build/esm/FDBCursorWithValue.js +16 -0
- package/build/esm/FDBDatabase.js +209 -0
- package/build/esm/FDBFactory.js +291 -0
- package/build/esm/FDBIndex.js +233 -0
- package/build/esm/FDBKeyRange.js +89 -0
- package/build/esm/FDBObjectStore.js +483 -0
- package/build/esm/FDBOpenDBRequest.js +13 -0
- package/build/esm/FDBRequest.js +43 -0
- package/build/esm/FDBTransaction.js +243 -0
- package/build/esm/FDBVersionChangeEvent.js +16 -0
- package/build/{fakeIndexedDB.js → esm/fakeIndexedDB.js} +1 -1
- package/build/{index.js → esm/index.js} +1 -1
- package/build/esm/lib/Database.js +38 -0
- package/build/{lib → esm/lib}/FakeDOMStringList.js +35 -24
- package/build/esm/lib/FakeEvent.js +43 -0
- package/build/esm/lib/FakeEventTarget.js +119 -0
- package/build/esm/lib/Index.js +171 -0
- package/build/esm/lib/KeyGenerator.js +28 -0
- package/build/esm/lib/ObjectStore.js +195 -0
- package/build/esm/lib/RecordStore.js +167 -0
- package/build/esm/lib/binarySearch.js +87 -0
- package/build/esm/lib/canInjectKey.js +33 -0
- package/build/esm/lib/cmp.js +99 -0
- package/build/esm/lib/enforceRange.js +15 -0
- package/build/esm/lib/errors.js +93 -0
- package/build/esm/lib/extractKey.js +49 -0
- package/build/{lib → esm/lib}/scheduling.js +10 -12
- package/build/esm/lib/structuredClone.js +18 -0
- package/build/esm/lib/types.js +1 -0
- package/build/esm/lib/validateKeyPath.js +56 -0
- package/build/esm/lib/valueToKey.js +55 -0
- package/build/esm/lib/valueToKeyRange.js +22 -0
- package/lib/FDBCursor.js +1 -0
- package/lib/FDBCursorWithValue.js +1 -0
- package/lib/FDBDatabase.js +1 -0
- package/lib/FDBFactory.js +1 -0
- package/lib/FDBIndex.js +1 -0
- package/lib/FDBKeyRange.js +1 -0
- package/lib/FDBObjectStore.js +1 -0
- package/lib/FDBOpenDBRequest.js +1 -0
- package/lib/FDBRequest.js +1 -0
- package/lib/FDBTransaction.js +1 -0
- package/lib/FDBVersionChangeEvent.js +1 -0
- package/lib/README.md +5 -0
- package/lib/package.json +3 -0
- package/package.json +90 -40
- package/build/FDBCursor.js +0 -486
- package/build/FDBCursorWithValue.js +0 -11
- package/build/FDBDatabase.js +0 -160
- package/build/FDBFactory.js +0 -256
- package/build/FDBIndex.js +0 -185
- package/build/FDBKeyRange.js +0 -69
- package/build/FDBObjectStore.js +0 -381
- package/build/FDBOpenDBRequest.js +0 -12
- package/build/FDBRequest.js +0 -36
- package/build/FDBTransaction.js +0 -204
- package/build/FDBVersionChangeEvent.js +0 -14
- package/build/lib/Database.js +0 -32
- package/build/lib/FakeEvent.js +0 -41
- package/build/lib/FakeEventTarget.js +0 -103
- package/build/lib/Index.js +0 -152
- package/build/lib/KeyGenerator.js +0 -23
- package/build/lib/ObjectStore.js +0 -157
- package/build/lib/RecordStore.js +0 -152
- package/build/lib/binarySearch.js +0 -75
- package/build/lib/canInjectKey.js +0 -24
- package/build/lib/cmp.js +0 -78
- package/build/lib/enforceRange.js +0 -12
- package/build/lib/errors.js +0 -83
- package/build/lib/extractKey.js +0 -42
- package/build/lib/structuredClone.js +0 -18
- package/build/lib/types.js +0 -1
- package/build/lib/validateKeyPath.js +0 -51
- package/build/lib/valueToKey.js +0 -53
- package/build/lib/valueToKeyRange.js +0 -18
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ yarn add --dev fake-indexeddb
|
|
|
18
18
|
|
|
19
19
|
Functionally, it works exactly like IndexedDB except data is not persisted to disk.
|
|
20
20
|
|
|
21
|
-
The easiest way to use it is to import `fake-indexeddb/auto`, which will put all the IndexedDB variables in the global scope
|
|
21
|
+
The easiest way to use it is to import `fake-indexeddb/auto`, which will put all the IndexedDB variables in the global scope. (Both `import` and `require` are supported, use whichever you like, but the examples here are all `import`.)
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
24
|
import "fake-indexeddb/auto";
|
|
@@ -83,10 +83,6 @@ import {
|
|
|
83
83
|
} from "fake-indexeddb";
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
### ECMAScript modules (`import`) vs CommonJS (`require`)
|
|
87
|
-
|
|
88
|
-
Starting with version 4, fake-indexeddb uses ES modules rather than CommonJS. That means you need to `import` it, not `require` it. If that's a problem for you, stick to version 3 of fake-indexeddb, which supports `require("fake-indexeddb")`. Version 3 has basically all the same functionality as version 4, and I'll try to make any important bug fixes in both versions.
|
|
89
|
-
|
|
90
86
|
### TypeScript
|
|
91
87
|
|
|
92
88
|
As of version 4, fake-indexeddb includes TypeScript types. As you can see in types.d.ts, it's just using TypeScript's built-in IndexedDB types, rather than generating types from the fake-indexeddb code base. The reason I did this is for compatibility with your application code that may already be using TypeScript's IndexedDB types, so if I used something different for fake-indexeddb, it could lead to spurious type errors. In theory this could lead to other errors if there are differences between Typescript's IndexedDB types and fake-indexeddb's API, but currently I'm not aware of any difference. See [issue #23](https://github.com/dumbmatter/fakeIndexedDB/issues/23) for more discussion.
|
|
@@ -115,22 +111,22 @@ const db = new Dexie("MyDatabase", { indexedDB: indexedDB, IDBKeyRange: IDBKeyRa
|
|
|
115
111
|
|
|
116
112
|
### Jest
|
|
117
113
|
|
|
118
|
-
Out of the box, Jest v27 only supports CommonJS, not ES modules, so you'll have to do a little extra work to opt in to ES modules, either [for all your test files](https://jestjs.io/docs/ecmascript-modules) or by configuring Jest to [transpile fake-indexeddb](https://stackoverflow.com/a/43197503/786644). If you can't do that, you should use fake-indexeddb v3, see the above "ECMAScript modules" section for more info.
|
|
119
|
-
|
|
120
114
|
To use fake-indexeddb in a single Jest test suite, require `fake-indexeddb/auto` at the beginning of the test
|
|
121
115
|
file, as described above.
|
|
122
116
|
|
|
123
|
-
To use it on all Jest tests without having to
|
|
117
|
+
To use it on all Jest tests without having to include it in each file, add the auto setup script to the `setupFiles` in your Jest config:
|
|
124
118
|
|
|
125
119
|
```json
|
|
126
|
-
|
|
120
|
+
{
|
|
127
121
|
...
|
|
128
122
|
"setupFiles": [
|
|
129
|
-
"fake-indexeddb/auto"
|
|
123
|
+
"fake-indexeddb/auto.cjs"
|
|
130
124
|
]
|
|
131
125
|
}
|
|
132
126
|
```
|
|
133
127
|
|
|
128
|
+
That's "auto.cjs" rather than just "auto" to make sure it picks up the CommonJS version. Otherwise it would use the ESM version, which Jest does not support without [some extra configuration](https://jestjs.io/docs/ecmascript-modules).
|
|
129
|
+
|
|
134
130
|
### Wiping/resetting the indexedDB for a fresh state
|
|
135
131
|
|
|
136
132
|
If you are keeping your tests completely isolated you might want to "reset" the state of the mocked indexedDB. You can do this by creating a new instance of `IDBFactory`, which lets you have a totally fresh start.
|
package/auto/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const fakeIndexedDB = require("../build/cjs/fakeIndexedDB.js");
|
|
2
|
+
const FDBCursor = require("../build/cjs/FDBCursor.js");
|
|
3
|
+
const FDBCursorWithValue = require("../build/cjs/FDBCursorWithValue.js");
|
|
4
|
+
const FDBDatabase = require("../build/cjs/FDBDatabase.js");
|
|
5
|
+
const FDBFactory = require("../build/cjs/FDBFactory.js");
|
|
6
|
+
const FDBIndex = require("../build/cjs/FDBIndex.js");
|
|
7
|
+
const FDBKeyRange = require("../build/cjs/FDBKeyRange.js");
|
|
8
|
+
const FDBObjectStore = require("../build/cjs/FDBObjectStore.js");
|
|
9
|
+
const FDBOpenDBRequest = require("../build/cjs/FDBOpenDBRequest.js");
|
|
10
|
+
const FDBRequest = require("../build/cjs/FDBRequest.js");
|
|
11
|
+
const FDBTransaction = require("../build/cjs/FDBTransaction.js");
|
|
12
|
+
const FDBVersionChangeEvent = require("../build/cjs/FDBVersionChangeEvent.js");
|
|
13
|
+
|
|
14
|
+
// http://stackoverflow.com/a/33268326/786644 - works in browser, worker, and Node.js
|
|
15
|
+
var globalVar =
|
|
16
|
+
typeof window !== "undefined"
|
|
17
|
+
? window
|
|
18
|
+
: typeof WorkerGlobalScope !== "undefined"
|
|
19
|
+
? self
|
|
20
|
+
: typeof global !== "undefined"
|
|
21
|
+
? global
|
|
22
|
+
: Function("return this;")();
|
|
23
|
+
|
|
24
|
+
globalVar.indexedDB = fakeIndexedDB;
|
|
25
|
+
globalVar.IDBCursor = FDBCursor;
|
|
26
|
+
globalVar.IDBCursorWithValue = FDBCursorWithValue;
|
|
27
|
+
globalVar.IDBDatabase = FDBDatabase;
|
|
28
|
+
globalVar.IDBFactory = FDBFactory;
|
|
29
|
+
globalVar.IDBIndex = FDBIndex;
|
|
30
|
+
globalVar.IDBKeyRange = FDBKeyRange;
|
|
31
|
+
globalVar.IDBObjectStore = FDBObjectStore;
|
|
32
|
+
globalVar.IDBOpenDBRequest = FDBOpenDBRequest;
|
|
33
|
+
globalVar.IDBRequest = FDBRequest;
|
|
34
|
+
globalVar.IDBTransaction = FDBTransaction;
|
|
35
|
+
globalVar.IDBVersionChangeEvent = FDBVersionChangeEvent;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import fakeIndexedDB from "
|
|
2
|
-
import FDBCursor from "
|
|
3
|
-
import FDBCursorWithValue from "
|
|
4
|
-
import FDBDatabase from "
|
|
5
|
-
import FDBFactory from "
|
|
6
|
-
import FDBIndex from "
|
|
7
|
-
import FDBKeyRange from "
|
|
8
|
-
import FDBObjectStore from "
|
|
9
|
-
import FDBOpenDBRequest from "
|
|
10
|
-
import FDBRequest from "
|
|
11
|
-
import FDBTransaction from "
|
|
12
|
-
import FDBVersionChangeEvent from "
|
|
1
|
+
import fakeIndexedDB from "../build/esm/fakeIndexedDB.js";
|
|
2
|
+
import FDBCursor from "../build/esm/FDBCursor.js";
|
|
3
|
+
import FDBCursorWithValue from "../build/esm/FDBCursorWithValue.js";
|
|
4
|
+
import FDBDatabase from "../build/esm/FDBDatabase.js";
|
|
5
|
+
import FDBFactory from "../build/esm/FDBFactory.js";
|
|
6
|
+
import FDBIndex from "../build/esm/FDBIndex.js";
|
|
7
|
+
import FDBKeyRange from "../build/esm/FDBKeyRange.js";
|
|
8
|
+
import FDBObjectStore from "../build/esm/FDBObjectStore.js";
|
|
9
|
+
import FDBOpenDBRequest from "../build/esm/FDBOpenDBRequest.js";
|
|
10
|
+
import FDBRequest from "../build/esm/FDBRequest.js";
|
|
11
|
+
import FDBTransaction from "../build/esm/FDBTransaction.js";
|
|
12
|
+
import FDBVersionChangeEvent from "../build/esm/FDBVersionChangeEvent.js";
|
|
13
13
|
|
|
14
14
|
// http://stackoverflow.com/a/33268326/786644 - works in browser, worker, and Node.js
|
|
15
15
|
var globalVar =
|