{"_id":"@clintharris/fake-indexeddb","_rev":"3-83a6da8ae8aaa624f018bcad71dda063","time":{"3.1.3":"2020-12-06T13:06:17.325Z","created":"2020-12-06T13:07:48.843Z","3.1.4":"2020-12-06T13:07:49.005Z","modified":"2022-04-04T23:23:53.278Z"},"name":"@clintharris/fake-indexeddb","dist-tags":{"latest":"3.1.4"},"versions":{"3.1.4":{"name":"@clintharris/fake-indexeddb","version":"3.1.4","description":"Fake IndexedDB: a pure JS in-memory implementation of the IndexedDB API","homepage":"https://github.com/dumbmatter/fakeIndexedDB","repository":{"type":"git","url":"git://github.com/dumbmatter/fakeIndexedDB.git"},"bugs":{"url":"https://github.com/dumbmatter/fakeIndexedDB/issues"},"keywords":["indexeddb","datastore","database","embedded","nosql","in-memory","polyfill","shim"],"main":"build/index.js","scripts":{"build":"rm -rf build lib/**/*.d.ts && tsc && npm run build-typedefs","build-typedefs":"tsc --outDir ./lib --declaration --emitDeclarationOnly --target es5 --downlevelIteration ./src/FDB*.ts","prepublishOnly":"npm run build && rm -rf build/test","lint":"tslint  'src/**/*.ts'","prettier":"prettier --write *.json  'src/**/*.{js,ts}'","test-mocha":"mocha --timeout 10000 build/test/fakeIndexedDB","build-qunit":"browserify build/test/indexedDBmock/exports-qunit-bundle.js -o build/test/indexedDBmock/exports-qunit-bundle.js && cp src/test/indexedDBmock/index.html build/test/indexedDBmock/index.html","test-qunit":"npm run build-qunit && node-qunit-phantomjs build/test/indexedDBmock/index.html","test-w3c":"node src/test/web-platform-tests/run-all.js","test":"npm run lint && npm run build && node test/test.js && npm run test-w3c && npm run test-mocha && npm run test-qunit"},"author":{"name":"Jeremy Scheff","email":"jdscheff@gmail.com","url":"http://dumbmatter.com/"},"license":"Apache-2.0","dependencies":{"realistic-structured-clone":"^2.0.1","setimmediate":"^1.0.5"},"devDependencies":{"@types/mocha":"^5.2.7","@types/node":"^12.12.7","browserify":"^16.5.0","core-js":"^3.4.1","glob":"^7.1.6","husky":"^3.0.9","lint-staged":"^9.4.3","mocha":"^6.2.2","node-qunit-phantomjs":"^1.6.3","prettier":"^1.19.1","qunitjs":"^1.23.1","semver":"^6.3.0","tslint":"^5.20.1","tslint-config-prettier":"^1.15.0","typescript":"3.7.2"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.{js,json,ts}":["prettier --write","git add"]},"gitHead":"4333821ec0b292ccf4a09fc4318817dfaa8ca697","_id":"@clintharris/fake-indexeddb@3.1.4","_nodeVersion":"12.14.1","_npmVersion":"6.13.6","dist":{"integrity":"sha512-UquN04aMnswOrUl5vMmPQ8yiAH0E2a7S4e605NPZQ0Gh2QYqqDlThusGasngeeO4YJ/OVa2SptaTs1rktj7VwA==","shasum":"f1a84e4a177fb6ac91e14ea09c38b27132c365db","tarball":"https://registry.npmjs.org/@clintharris/fake-indexeddb/-/fake-indexeddb-3.1.4.tgz","fileCount":79,"unpackedSize":209234,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfzNelCRA9TVsSAnZWagAAQRUP/1Hj/Z25jafMgMs4IwXt\ncTUR7zukOdiaUV0I/7dEkEgX/4ByWZ+vMeZTvxt8Cg4nHrMAhJA/f+kaM8tw\nLKLEFLiqMh2XYCGtpsYDGVpooCofyTxHucC7PJRZRAYV6zp+nyuwT9VpTz91\npZgbAGg5GixV+Agq4T27G7IZBK2xMqiwNOFUweE7a+t8RW7kJAAQ4K4ET3f7\n6FmOiPOe09eQCreW7Debb/tnIhV0YH/Wn0C79wS3vmoABghMNPN4/61ZmHXI\nX4O7aPBNlK/lyVr1j12VNjfOEkStYacb5lvx1HMTyxGm79d5WF8PERtCtX1X\nxgR8fvxG8nVydf2iBt+6UZmUAYKxUPjAcg3nt1TdViQZWQ1NSWsyKM+wX2ZI\nef0hm7S/y3FbF6Dvx06s+x4kFPHsFGAOiny4yEzhVpgh4ugkRCrQ6hutHkZY\nI9+Dv/9TqfwRBbVpXypnC3QDJiiCKJ0CLHvncMmbYuj8XYKHdkkyaNS5Pa+E\nO6ISk9ZvclihyWT+pz2KKm5TYhWoomqAPYiCclOD3IPpIphowkSMSekkCcqY\nTncW+HgL1bpzJ/w7oVAp3gQJiI69iGSiXHejk2kwAwZpKH4BFkAB+PP8t74o\nsAy5Uj8RhaOCfI6WCJVw971KAgShWsV7la6KDkggSVBMbiaSgRp1B/e7nQ7+\nlDwo\r\n=9QVV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCyMq5ZcMRYdU/4DSLtg/dBXuKheWg+3UteqL6fPGkc9gIgdfnf0L8pMxIongKs3+S8M6pSMVPKZLAjFJpiuZD7/Vw="}]},"_npmUser":{"name":"clintharris","email":"npmjs.com@airpost.net"},"directories":{},"maintainers":[{"name":"clintharris","email":"npmjs.com@airpost.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fake-indexeddb_3.1.4_1607260068844_0.7679216042907351"},"_hasShrinkwrap":false}},"maintainers":[{"name":"clintharris","email":"npmjs.com@airpost.net"}],"description":"Fake IndexedDB: a pure JS in-memory implementation of the IndexedDB API","homepage":"https://github.com/dumbmatter/fakeIndexedDB","keywords":["indexeddb","datastore","database","embedded","nosql","in-memory","polyfill","shim"],"repository":{"type":"git","url":"git://github.com/dumbmatter/fakeIndexedDB.git"},"author":{"name":"Jeremy Scheff","email":"jdscheff@gmail.com","url":"http://dumbmatter.com/"},"bugs":{"url":"https://github.com/dumbmatter/fakeIndexedDB/issues"},"license":"Apache-2.0","readme":"# fake-indexeddb [![Build Status](https://travis-ci.org/dumbmatter/fakeIndexedDB.svg?branch=master)](https://travis-ci.org/dumbmatter/fakeIndexedDB)\n\nThis is a pure JS in-memory implementation of [the IndexedDB API](https://w3c.github.io/IndexedDB/). Its main utility is for testing IndexedDB-dependent code in Node.js.\n\n## Installation\n\n```sh\nnpm install --save-dev fake-indexeddb\n```\n\nor\n\n```sh\nyarn add --dev fake-indexeddb\n```\n\n## Use\n\nFunctionally, it works exactly like IndexedDB except data is not persisted to disk.\n\nThe easiest way to use it is to import `fake-indexeddb/auto`, which will put all the IndexedDB objects in the global scope:\n\n```js\nrequire(\"fake-indexeddb/auto\");\n\nvar request = indexedDB.open(\"test\", 3);\nrequest.onupgradeneeded = function () {\n    var db = request.result;\n    var store = db.createObjectStore(\"books\", {keyPath: \"isbn\"});\n    store.createIndex(\"by_title\", \"title\", {unique: true});\n\n    store.put({title: \"Quarry Memories\", author: \"Fred\", isbn: 123456});\n    store.put({title: \"Water Buffaloes\", author: \"Fred\", isbn: 234567});\n    store.put({title: \"Bedrock Nights\", author: \"Barney\", isbn: 345678});\n}\nrequest.onsuccess = function (event) {\n    var db = event.target.result;\n\n    var tx = db.transaction(\"books\");\n\n    tx.objectStore(\"books\").index(\"by_title\").get(\"Quarry Memories\").addEventListener(\"success\", function (event) {\n        console.log(\"From index:\", event.target.result);\n    });\n    tx.objectStore(\"books\").openCursor(IDBKeyRange.lowerBound(200000)).onsuccess = function (event) {\n        var cursor = event.target.result;\n        if (cursor) {\n            console.log(\"From cursor:\", cursor.value);\n            cursor.continue();\n        }\n    };\n    tx.oncomplete = function () {\n        console.log(\"All done!\");\n    };\n};\n```\n\nAlternatively, you can import individual objects:\n\n```js\nvar indexedDB = require(\"fake-indexeddb\");\nvar IDBKeyRange = require(\"fake-indexeddb/lib/FDBKeyRange\");\n\n// The rest is the same as above.\n```\n\nWhen importing individual classes directly (like `var IDBKeyRange =\nrequire(\"fake-indexeddb/lib/FDBKeyRange\");` above), file names of all the objects are like the\nnormal IndexedDB ones except with F replacing I, e.g. `FDBIndex` instead of `IDBIndex`.\n\n### With Dexie and other IndexedDB API wrappers\n\nIf you import `fake-indexeddb/auto` before calling `new Dexie()`, it should work:\n\n```js\nconst Dexie = require(\"dexie\");\nrequire(\"fake-indexeddb/auto\");\n\nconst db = new Dexie(\"MyDatabase\");\n```\n\nThe same likely holds true for other IndexedDB API wrappers like idb.\n\nAlternatively, if you don't want to modify the global scope, then you need to explicitly pass the objects to Dexie:\n\n```js\nconst Dexie = require(\"dexie\");\nconst indexedDB = require(\"fake-indexeddb\");\nconst IDBKeyRange = require(\"fake-indexeddb/lib/FDBKeyRange\");\n\nconst db = new Dexie(\"MyDatabase\", { indexedDB: indexedDB, IDBKeyRange: IDBKeyRange });\n```\n\n### With Jest\n\nTo use this on a single Jest test suite, require `fake-indexeddb/auto` at the beginning of the test\nfile, as described above.\n\nTo 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:\n\n```json\n\"jest\": {\n    ...\n    \"setupFiles\": [\n        \"fake-indexeddb/auto\"\n    ]\n}\n```\n\n### Wiping/resetting the indexedDB for a fresh state\n\nIf 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.\n\n```\nrequire(\"fake-indexeddb/auto\");\nconst FDBFactory = require(\"fake-indexeddb/lib/FDBFactory\");\n\n// Whenever you want a fresh indexedDB\nindexedDB = new FDBFactory();\n```\n\n### With PhantomJS and other really old environments\n\nPhantomJS (and other really old environments) are missing tons of modern JavaScript features. In fact, that may be why you use fake-indexeddb in such an environment! Prior to v3.0.0, fake-indexeddb imported core-js and automatically applied its polyfills. However, since most fake-indexeddb users are not using really old environments, I got rid of that runtime dependency in v3.0.0. To work around that, you can import core-js yourself before you import fake-indexeddb, like:\n\n```js\nrequire(\"core-js/stable\");\nvar indexedDB = require(\"fake-indexeddb\");\n```\n\n## Quality\n\nHere's a comparison of fake-indexeddb and real browser IndexedDB implementations on [the W3C IndexedDB test suite](https://github.com/w3c/web-platform-tests/tree/master/IndexedDB) as of March 18, 2019:\n\n| Implementation       | Percentage of files that pass completely |\n| -------------------- | ---------------------------------------- |\n| Chrome 73            | 99%                                      |\n| Firefox 65           | 97%                                      |\n| Safari 12            | 92%                                      |\n| fake-indexeddb 3.0.0 | 87%                                      |\n| Edge 18              | 61%                                      |\n\nFor browsers, I ran http://w3c-test.org/tools/runner/index.html and counted the passes. For fake-indexeddb, I ran `npm run test-w3c`.\n\n87% is pretty good, right? Especially considering that fake-indexeddb runs in Node.js where failure is guaranteed for tests involving browser APIs like Web Workers. There are definitley still some weak points of fake-indexeddb, most of which are described in `src/test/web-platform-tests/run-all.js`. Your app will probably run fine, though.\n\n## Potential applications:\n\n1. Use as a mock database in unit tests.\n\n2. Use the same API in Node.js and in the browser.\n\n3. Support IndexedDB in old or crappy browsers.\n\n4. Somehow use it within a caching layer on top of IndexedDB in the browser, since IndexedDB can be kind of slow.\n\n5. Abstract the core database functions out, so what is left is a shell that allows the IndexedDB API to easily sit on top of many different backends.\n\n6. Serve as a playground for experimenting with IndexedDB.\n\n## License\n\nApache 2.0\n","readmeFilename":"README.md"}