Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dbcore middleware support (dexie#754)
This commit is a replacement of IndexedDB with something called DBCore. It's still a moving target how the DBCore API will be. Goal: Enable middlewares in Dexie that can be a better alternative to hooks. Actually the current hooks API is now implemented via a middleware that would possibly be an optional addon (dexie-hooks) to slim down dexie.js. Example uses of middlewares: ```js const db = new Dexie('dbname'); db.version(x).stores(y); db.use(someMiddleware); ``` ## Example middleware posibilities: * foreign key constraints * computed indexes * collated indexes * hierarchies * access control * encryption ## Commit summaries * A new middleware-friendly interface DBCore. To replace calls to indexedDB. The benefit of this will be an alternative to hooks: * Enable fully asynchronic create/add/delete hooks. Will eventually enable asynchronic read hooks in future as well. * Lower-level than Dexie but using Promises and bulk API. First plan for this will be to make it possible to create middlewares supporting feaures like foreign key constraints, etc. In the long term, the new middleware API will be simpler and a more robust alternative to hooks. An example will be: db.use(myMiddleware) A middleware can optionally implement partial parts of the DBCore API and act as a proxy between Dexie and DBCore. * dbcore layers seem to be complete. Still in the middle of rewriting Dexie to use dbcore instead of going directly to indexedDB. In this rewrite, all hook handling will be removed as it is now handled by a middleware instead, extept hook('reading') which need to be handled on the Dexie layer still. * Almost there. Collection.delete() still needed. Never run. Believe it will probably blow up when I do. * Should be complete. No tests run yet. Compiles. * Some fixes after trying running unit tests. Still race issue about creating the dbcoretables. * Bugfix dbcore-indexeddb * Must set table.core both on _allTables and db. * Issues with Cursor. Not solved. * Now lots of unit tests succeed. But many still fails. * More and more unit tests starts working... * Empty toString message of ModifyError * Non-bugfixes. Just cleanup code etc. * Bugfix of tracking failures in Collection.modify * Corrected failures array of BulkError * Failing unit test in tests-open. Failed when there were no objectStores in an existing database. * Regression bug found by "misc: Adding object with falsy keys" * Now all but one unit test succeeds. One test needed to be changed as it invalidly expected certain order of events. The test that now fails only fails on number of expected assertions. Will need to diff the log from it with a working one to find out why we get 57 assertions instead of the expected 53 assertions. * Added test that verifies the posibility to modify a primary key. Don't actually know if this was possible in earlier versions of Dexie, as it used IDBCursor.update() instead of the current modification strategy. * Include the flow of modifying primary key in test "Dexie.currentTransaction in CRUD hooks". * Finally all tests run on IE11, Safari 10 and Safari 11 and Chrome. Let's see what travis thinks about this... * Fixed failing unit test of Dexie.Observable. In previous versions, updatingHook was called also when no actual changes were made. New version will neither call updating hooks nor do any put() operation if the changes wouldn't have any effect. * Repaired integration tests of Dexie.Observable by locking transaction using trans._promise instead of LockableTableMiddleware. The difference I see is that trans._promise uses a recursive locking strategy, which may be needed for hooks because they act in a high level that once again might call down the dbcore stack and otherwise get stuck in a deadlock. This would not be the case for pure middlewares where the middlewares should NOT call on Dexie methods again because it would possibly cause stack overflow. * All tests seems to pass now. The last changes had to do with the hooks middleware that needs to: 1. Run in upgraders and on populate as well due to how prior unit tests are done (syncable specifically). 2. Attach to transaction's table's hooks instead of db.table.hook because in certain upgrade scenarios, db.table may be deleted in later version but exist in transaction of intermediate version. * Improve code coverage * Fail instead of returning undefined when table is not found. Otherwise an obscure error will be thrown in some unrelated middleware. * Include messages of nested exceptions on more than just one level. Specifically, a unit test of Dexie.Syncable failed with inner exception Database.OpenError, with another inner exception telling the real reason. This was not shown in the unit test log, but is now. * Minor corrections
- Loading branch information