fake-indexeddb 4.0.0-beta.1 → 4.0.0-beta.5

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 (116) hide show
  1. package/README.md +7 -11
  2. package/auto/index.js +35 -0
  3. package/{auto.js → auto/index.mjs} +12 -12
  4. package/auto/package.json +3 -0
  5. package/build/cjs/FDBCursor.js +591 -0
  6. package/build/cjs/FDBCursorWithValue.js +27 -0
  7. package/build/cjs/FDBDatabase.js +226 -0
  8. package/build/cjs/FDBFactory.js +310 -0
  9. package/build/cjs/FDBIndex.js +252 -0
  10. package/build/cjs/FDBKeyRange.js +103 -0
  11. package/build/cjs/FDBObjectStore.js +508 -0
  12. package/build/cjs/FDBOpenDBRequest.js +24 -0
  13. package/build/cjs/FDBRequest.js +55 -0
  14. package/build/cjs/FDBTransaction.js +260 -0
  15. package/build/cjs/FDBVersionChangeEvent.js +27 -0
  16. package/build/cjs/fakeIndexedDB.js +15 -0
  17. package/build/cjs/index.js +107 -0
  18. package/build/cjs/lib/Database.js +48 -0
  19. package/build/cjs/lib/FakeDOMStringList.js +53 -0
  20. package/build/cjs/lib/FakeEvent.js +52 -0
  21. package/build/cjs/lib/FakeEventTarget.js +128 -0
  22. package/build/cjs/lib/Index.js +187 -0
  23. package/build/cjs/lib/KeyGenerator.js +38 -0
  24. package/build/cjs/lib/ObjectStore.js +210 -0
  25. package/build/cjs/lib/RecordStore.js +180 -0
  26. package/build/cjs/lib/binarySearch.js +104 -0
  27. package/build/cjs/lib/canInjectKey.js +42 -0
  28. package/build/cjs/lib/cmp.js +111 -0
  29. package/build/cjs/lib/enforceRange.js +24 -0
  30. package/build/cjs/lib/errors.js +130 -0
  31. package/build/cjs/lib/extractKey.js +61 -0
  32. package/build/cjs/lib/scheduling.js +35 -0
  33. package/build/cjs/lib/structuredClone.js +30 -0
  34. package/build/cjs/lib/types.js +1 -0
  35. package/build/cjs/lib/validateKeyPath.js +65 -0
  36. package/build/cjs/lib/valueToKey.js +64 -0
  37. package/build/cjs/lib/valueToKeyRange.js +36 -0
  38. package/build/cjs/package.json +1 -0
  39. package/build/esm/FDBCursor.js +574 -0
  40. package/build/esm/FDBCursorWithValue.js +16 -0
  41. package/build/esm/FDBDatabase.js +209 -0
  42. package/build/esm/FDBFactory.js +291 -0
  43. package/build/esm/FDBIndex.js +233 -0
  44. package/build/esm/FDBKeyRange.js +89 -0
  45. package/build/esm/FDBObjectStore.js +483 -0
  46. package/build/esm/FDBOpenDBRequest.js +13 -0
  47. package/build/esm/FDBRequest.js +43 -0
  48. package/build/esm/FDBTransaction.js +243 -0
  49. package/build/esm/FDBVersionChangeEvent.js +16 -0
  50. package/build/esm/fakeIndexedDB.js +3 -0
  51. package/build/{index.js → esm/index.js} +1 -1
  52. package/build/esm/lib/Database.js +38 -0
  53. package/build/esm/lib/FakeDOMStringList.js +44 -0
  54. package/build/esm/lib/FakeEvent.js +43 -0
  55. package/build/esm/lib/FakeEventTarget.js +119 -0
  56. package/build/esm/lib/Index.js +171 -0
  57. package/build/esm/lib/KeyGenerator.js +28 -0
  58. package/build/esm/lib/ObjectStore.js +195 -0
  59. package/build/esm/lib/RecordStore.js +167 -0
  60. package/build/esm/lib/binarySearch.js +87 -0
  61. package/build/esm/lib/canInjectKey.js +33 -0
  62. package/build/esm/lib/cmp.js +99 -0
  63. package/build/esm/lib/enforceRange.js +15 -0
  64. package/build/esm/lib/errors.js +93 -0
  65. package/build/esm/lib/extractKey.js +49 -0
  66. package/build/esm/lib/scheduling.js +26 -0
  67. package/build/esm/lib/structuredClone.js +18 -0
  68. package/build/esm/lib/types.js +1 -0
  69. package/build/esm/lib/validateKeyPath.js +56 -0
  70. package/build/esm/lib/valueToKey.js +55 -0
  71. package/build/esm/lib/valueToKeyRange.js +22 -0
  72. package/lib/FDBCursor.js +1 -0
  73. package/lib/FDBCursorWithValue.js +1 -0
  74. package/lib/FDBDatabase.js +1 -0
  75. package/lib/FDBFactory.js +1 -0
  76. package/lib/FDBIndex.js +1 -0
  77. package/lib/FDBKeyRange.js +1 -0
  78. package/lib/FDBObjectStore.js +1 -0
  79. package/lib/FDBOpenDBRequest.js +1 -0
  80. package/lib/FDBRequest.js +1 -0
  81. package/lib/FDBTransaction.js +1 -0
  82. package/lib/FDBVersionChangeEvent.js +1 -0
  83. package/lib/README.md +5 -0
  84. package/lib/package.json +3 -0
  85. package/package.json +89 -41
  86. package/build/FDBCursor.js +0 -579
  87. package/build/FDBCursorWithValue.js +0 -29
  88. package/build/FDBDatabase.js +0 -203
  89. package/build/FDBFactory.js +0 -322
  90. package/build/FDBIndex.js +0 -190
  91. package/build/FDBKeyRange.js +0 -74
  92. package/build/FDBObjectStore.js +0 -388
  93. package/build/FDBOpenDBRequest.js +0 -30
  94. package/build/FDBRequest.js +0 -62
  95. package/build/FDBTransaction.js +0 -254
  96. package/build/FDBVersionChangeEvent.js +0 -33
  97. package/build/fakeIndexedDB.js +0 -3
  98. package/build/lib/Database.js +0 -33
  99. package/build/lib/FakeEvent.js +0 -43
  100. package/build/lib/FakeEventTarget.js +0 -149
  101. package/build/lib/Index.js +0 -229
  102. package/build/lib/KeyGenerator.js +0 -24
  103. package/build/lib/ObjectStore.js +0 -253
  104. package/build/lib/RecordStore.js +0 -156
  105. package/build/lib/binarySearch.js +0 -75
  106. package/build/lib/canInjectKey.js +0 -46
  107. package/build/lib/cmp.js +0 -78
  108. package/build/lib/enforceRange.js +0 -12
  109. package/build/lib/errors.js +0 -148
  110. package/build/lib/extractKey.js +0 -64
  111. package/build/lib/fakeDOMStringList.js +0 -14
  112. package/build/lib/structuredClone.js +0 -12
  113. package/build/lib/types.js +0 -1
  114. package/build/lib/validateKeyPath.js +0 -83
  115. package/build/lib/valueToKey.js +0 -53
  116. package/build/lib/valueToKeyRange.js +0 -19
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,25 +111,25 @@ 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](https://jestjs.io/docs/ecmascript-modules). If you can't do that, you should switch to 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 require it in each file, add the auto setup script to the `setupFiles` in your Jest config:
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
- "jest": {
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
- 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 `fakeIndexedDB` instance, which lets you have a totally fresh start.
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.
137
133
 
138
134
  ```
139
135
  import "fake-indexeddb/auto";
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 "./build/fakeIndexedDB.js";
2
- import FDBCursor from "./build/FDBCursor.js";
3
- import FDBCursorWithValue from "./build/FDBCursorWithValue.js";
4
- import FDBDatabase from "./build/FDBDatabase.js";
5
- import FDBFactory from "./build/FDBFactory.js";
6
- import FDBIndex from "./build/FDBIndex.js";
7
- import FDBKeyRange from "./build/FDBKeyRange.js";
8
- import FDBObjectStore from "./build/FDBObjectStore.js";
9
- import FDBOpenDBRequest from "./build/FDBOpenDBRequest.js";
10
- import FDBRequest from "./build/FDBRequest.js";
11
- import FDBTransaction from "./build/FDBTransaction.js";
12
- import FDBVersionChangeEvent from "./build/FDBVersionChangeEvent.js";
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 =
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }