From fde255c06b17b544a69182b952da317327ad0b54 Mon Sep 17 00:00:00 2001 From: David Fahlander Date: Mon, 4 Apr 2016 15:24:10 +0200 Subject: [PATCH] Build output --- addons/Dexie.Observable/dist/README.md | 37 - .../Dexie.Observable/dist/dexie-observable.js | 817 ++++ .../dist/dexie-observable.js.map | 1 + .../dist/dexie-observable.min.js | 2 + .../dist/dexie-observable.min.js.map | 1 + addons/Dexie.Syncable/dist/README.md | 37 - addons/Dexie.Syncable/dist/dexie-syncable.js | 1005 ++++ .../Dexie.Syncable/dist/dexie-syncable.js.map | 1 + .../Dexie.Syncable/dist/dexie-syncable.min.js | 2 + .../dist/dexie-syncable.min.js.map | 1 + bower.json | 3 +- dist/README.md | 51 - dist/dexie.d.ts | 440 ++ dist/dexie.js | 4157 +++++++++++++++++ dist/dexie.js.map | 1 + dist/dexie.min.js | 3 + dist/dexie.min.js.map | 1 + 17 files changed, 6434 insertions(+), 126 deletions(-) delete mode 100644 addons/Dexie.Observable/dist/README.md create mode 100644 addons/Dexie.Observable/dist/dexie-observable.js create mode 100644 addons/Dexie.Observable/dist/dexie-observable.js.map create mode 100644 addons/Dexie.Observable/dist/dexie-observable.min.js create mode 100644 addons/Dexie.Observable/dist/dexie-observable.min.js.map delete mode 100644 addons/Dexie.Syncable/dist/README.md create mode 100644 addons/Dexie.Syncable/dist/dexie-syncable.js create mode 100644 addons/Dexie.Syncable/dist/dexie-syncable.js.map create mode 100644 addons/Dexie.Syncable/dist/dexie-syncable.min.js create mode 100644 addons/Dexie.Syncable/dist/dexie-syncable.min.js.map delete mode 100644 dist/README.md create mode 100644 dist/dexie.d.ts create mode 100644 dist/dexie.js create mode 100644 dist/dexie.js.map create mode 100644 dist/dexie.min.js create mode 100644 dist/dexie.min.js.map diff --git a/addons/Dexie.Observable/dist/README.md b/addons/Dexie.Observable/dist/README.md deleted file mode 100644 index 7574f1379..000000000 --- a/addons/Dexie.Observable/dist/README.md +++ /dev/null @@ -1,37 +0,0 @@ -## Can't find dexie-observable.js? -Transpiled code (dist version) IS ONLY checked in to -the [releases](https://github.com/dfahlander/Dexie.js/tree/releases/addons/Dexie.Observable/dist) -branch. - -## Download -[npmcdn.com/dexie-observable/dist/dexie-observable.js](https://npmcdn.com/dexie-observable/dist/dexie-observable.js) - -[npmcdn.com/dexie-observable/dist/dexie-observable.min.js](https://npmcdn.com/dexie-observable/dist/dexie-observable.min.js) - -[npmcdn.com/dexie-observable/dist/dexie-observable.js.map](https://npmcdn.com/dexie-observable/dist/dexie-observable.js.map) - -[npmcdn.com/dexie-observable/dist/dexie-observable.min.js.map](https://npmcdn.com/dexie-observable/dist/dexie-observable.min.js.map) - -## npm -``` -npm install dexie-observable --save -``` -## bower -Since Dexie v1.3.4, addons are included in the dexie bower package. -``` -$ bower install dexie --save -$ ls bower_components/dexie/addons/Dexie.Observable/dist -dexie-observable.js dexie-observable.js.map dexie-observable.min.js dexie-observable.min.js.map - -``` -## Or build them yourself... -Fork Dexie.js, then: -``` -git clone https://github.com/YOUR-USERNAME/Dexie.js.git -cd Dexie.js -npm install -cd addons/Dexie.Observable -npm run build # or npm run watch - -``` -If you're on windows, you need to use an elevated command prompt of some reason to get `npm install` to work. diff --git a/addons/Dexie.Observable/dist/dexie-observable.js b/addons/Dexie.Observable/dist/dexie-observable.js new file mode 100644 index 000000000..f123b5968 --- /dev/null +++ b/addons/Dexie.Observable/dist/dexie-observable.js @@ -0,0 +1,817 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('dexie')) : + typeof define === 'function' && define.amd ? define(['dexie'], factory) : + global.Dexie.Observable = factory(global.Dexie); +}(this, function (Dexie) { 'use strict'; + + Dexie = 'default' in Dexie ? Dexie['default'] : Dexie; + + var global = self; + + /** class DatabaseChange + * + * Object contained by the _changes table. + */ + var DatabaseChange = Dexie.defineClass({ + rev: Number, // Auto-incremented primary key + source: String, // Optional source creating the change. Set if transaction.source was set when doing the operation. + table: String, // Table name + key: Object, // Primary key. Any type. + type: Number, // 1 = CREATE, 2 = UPDATE, 3 = DELETE + obj: Object, // CREATE: obj contains the object created. + mods: Object, // UPDATE: mods contains the modifications made to the object. + oldObj: Object // DELETE: oldObj contains the object deleted. UPDATE: oldObj contains the old object before updates applied. + }); + + // Import some usable helper functions + var override = Dexie.override; + var Promise = Dexie.Promise; + var browserIsShuttingDown = false; + + function Observable(db) { + /// + /// Extension to Dexie providing Syncronization capabilities to Dexie. + /// + /// + + var NODE_TIMEOUT = 20000, + // 20 seconds before local db instances are timed out. This is so that old changes can be deleted when not needed and to garbage collect old _syncNodes objects. + HIBERNATE_GRACE_PERIOD = 20000, + // 20 seconds + // LOCAL_POLL: The time to wait before polling local db for changes and cleaning up old nodes. + // Polling for changes is a fallback only needed in certain circomstances (when the onstorage event doesnt reach all listeners - when different browser windows doesnt share the same process) + LOCAL_POLL = 2000, + // 1 second. In real-world there will be this value + the time it takes to poll(). + CREATE = 1, + UPDATE = 2, + DELETE = 3; + + var localStorage = Observable.localStorageImpl; + + /** class SyncNode + * + * Object contained in the _syncNodes table. + */ + var SyncNode = Dexie.defineClass({ + //id: Number, + myRevision: Number, + type: String, // "local" or "remote" + lastHeartBeat: Number, + deleteTimeStamp: Number, // In case lastHeartBeat is too old, a value of now + HIBERNATE_GRACE_PERIOD will be set here. If reached before node wakes up, node will be deleted. + url: String, // Only applicable for "remote" nodes. Only used in Dexie.Syncable. + isMaster: Number, // 1 if true. Not using Boolean because it's not possible to index Booleans in IE implementation of IDB. + + // Below properties should be extended in Dexie.Syncable. Not here. They apply to remote nodes only (type == "remote"): + syncProtocol: String, // Tells which implementation of ISyncProtocol to use for remote syncing. + syncContext: null, + syncOptions: Object, + connected: false, // FIXTHIS: Remove! Replace with status. + status: Number, + appliedRemoteRevision: null, + remoteBaseRevisions: [{ local: Number, remote: null }], + dbUploadState: { + tablesToUpload: [String], + currentTable: String, + currentKey: null, + localBaseRevision: Number + } + }); + + var mySyncNode = null; + + // Allow other addons to access the local sync node. May be needed by Dexie.Syncable. + Object.defineProperty(db, "_localSyncNode", { + get: function () { + return mySyncNode; + } + }); + + var pollHandle = null; + + if (Dexie.fake) { + // This code will never run. + // It's here just to enable auto-complete in visual studio - helps a lot when writing code. + db.version(1).stores({ + _syncNodes: "++id,myRevision,lastHeartBeat", + _changes: "++rev", + _intercomm: "++id,destinationNode", + _uncommittedChanges: "++id,node" + }); + db._syncNodes.mapToClass(SyncNode); + db._changes.mapToClass(DatabaseChange); + mySyncNode = new SyncNode({ + myRevision: 0, + type: "local", + lastHeartBeat: Date.now(), + deleteTimeStamp: null + }); + } + + // + // Override parsing the stores to add "_changes" and "_syncNodes" tables. + // + db.Version.prototype._parseStoresSpec = override(db.Version.prototype._parseStoresSpec, function (origFunc) { + return function (stores, dbSchema) { + // Create the _changes and _syncNodes tables + stores["_changes"] = "++rev"; + stores["_syncNodes"] = "++id,myRevision,lastHeartBeat,url,isMaster,type,status"; + stores["_intercomm"] = "++id,destinationNode"; + stores["_uncommittedChanges"] = "++id,node"; // For remote syncing when server returns a partial result. + // Call default implementation. Will populate the dbSchema structures. + origFunc.call(this, stores, dbSchema); + // Allow UUID primary keys using $$ prefix on primary key or indexes + Object.keys(dbSchema).forEach(function (tableName) { + var schema = dbSchema[tableName]; + if (schema.primKey.name.indexOf('$$') === 0) { + schema.primKey.uuid = true; + schema.primKey.name = schema.primKey.name.substr(2); + schema.primKey.keyPath = schema.primKey.keyPath.substr(2); + } + }); + // Now mark all observable tables + Object.keys(dbSchema).forEach(function (tableName) { + // Marked observable tables with "observable" in their TableSchema. + if (tableName.indexOf('_') !== 0 && tableName.indexOf('$') !== 0) { + dbSchema[tableName].observable = true; + } + }); + }; + }); + + // + // Make sure to subscribe to "creating", "updating" and "deleting" hooks for all observable tables that were created in the stores() method. + // + db._tableFactory = override(db._tableFactory, function (origCreateTable) { + return function createTable(mode, tableSchema, transactionPromiseFactory) { + var table = origCreateTable.apply(this, arguments); + if (table.schema.observable && transactionPromiseFactory === db._transPromiseFactory) { + // Only crudMonitor when creating + crudMonitor(table); + } + if (table.name === "_syncNodes" && transactionPromiseFactory === db._transPromiseFactory) { + table.mapToClass(SyncNode); + } + return table; + }; + }); + + // changes event on db: + db.on.addEventType({ + changes: 'asap', + cleanup: [promisableChain, nop], // fire (nodesTable, changesTable, trans). Hook called when cleaning up nodes. Subscribers may return a Promise to to more stuff. May do additional stuff if local sync node is master. + message: 'asap' + }); + + // + // Overide transaction creation to always include the "_changes" store when any observable store is involved. + // + db._createTransaction = override(db._createTransaction, function (origFunc) { + return function (mode, storenames, dbschema, parent) { + if (db.dynamicallyOpened()) return origFunc.apply(this, arguments); // Don't observe dynamically opened databases. + var addChanges = false; + if (mode === 'readwrite' && storenames.some(function (storeName) { + return dbschema[storeName] && dbschema[storeName].observable; + })) { + // At least one included store is a observable store. Make sure to also include the _changes store. + addChanges = true; + storenames = storenames.slice(0); // Clone + if (storenames.indexOf("_changes") === -1) storenames.push("_changes"); // Otherwise, firefox will hang... (I've reported the bug to Mozilla@Bugzilla) + } + // Call original db._createTransaction() + var trans = origFunc.call(this, mode, storenames, dbschema, parent); + // If this transaction is bound to any observable table, make sure to add changes when transaction completes. + if (addChanges) { + trans._lastWrittenRevision = 0; + trans.on('complete', function () { + if (trans._lastWrittenRevision) { + // Changes were written in this transaction. + if (!parent) { + // This is root-level transaction, i.e. a physical commit has happened. + // Delay-trigger a wakeup call: + if (wakeupObservers.timeoutHandle) clearTimeout(wakeupObservers.timeoutHandle); + wakeupObservers.timeoutHandle = setTimeout(function () { + delete wakeupObservers.timeoutHandle; + wakeupObservers(trans._lastWrittenRevision); + }, 25); + } else { + // This is just a virtual commit of a sub transaction. + // Wait with waking up observers until root transaction has committed. + // Make sure to mark root transaction so that it will wakeup observers upon commit. + var rootTransaction = function findRootTransaction(trans) { + return trans.parent ? findRootTransaction(trans.parent) : trans; + }(parent); + rootTransaction._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rootTransaction.lastWrittenRevision || 0); + } + } + }); + // Derive "source" property from parent transaction by default + if (trans.parent && trans.parent.source) trans.source = trans.parent.source; + } + return trans; + }; + }); + + // If Observable.latestRevsion[db.name] is undefined, set it to 0 so that comparing against it always works. + // You might think that it will always be undefined before this call, but in case another Dexie instance in the same + // window with the same database name has been created already, this static property will already be set correctly. + Observable.latestRevision[db.name] = Observable.latestRevision[db.name] || 0; + + function wakeupObservers(lastWrittenRevision) { + // Make sure Observable.latestRevision[db.name] is still below our value, now when some time has elapsed and other db instances in same window possibly could have made changes too. + if (Observable.latestRevision[db.name] < lastWrittenRevision) { + // Set the static property lastRevision[db.name] to the revision of the last written change. + Observable.latestRevision[db.name] = lastWrittenRevision; + // Wakeup ourselves, and any other db instances on this window: + Dexie.ignoreTransaction(function () { + Observable.on('latestRevisionIncremented').fire(db.name, lastWrittenRevision); + }); + // Observable.on.latestRevisionIncremented will only wakeup db's in current window. + // We need a storage event to wakeup other windwos. + // Since indexedDB lacks storage events, let's use the storage event from WebStorage just for + // the purpose to wakeup db instances in other windows. + localStorage.setItem('Dexie.Observable/latestRevision/' + db.name, lastWrittenRevision); // In IE, this will also wakeup our own window. However, onLatestRevisionIncremented will work around this by only running once per revision id. + } + } + + db.close = override(db.close, function (origClose) { + return function () { + if (db.dynamicallyOpened()) return origClose.apply(this, arguments); // Don't observe dynamically opened databases. + // Teardown our framework. + if (wakeupObservers.timeoutHandle) { + clearTimeout(wakeupObservers.timeoutHandle); + delete wakeupObservers.timeoutHandle; + } + Observable.on('latestRevisionIncremented').unsubscribe(onLatestRevisionIncremented); + Observable.on('suicideNurseCall').unsubscribe(onSuicide); + Observable.on('intercomm').unsubscribe(onIntercomm); + Observable.on('beforeunload').unsubscribe(onBeforeUnload); + // Inform other db instances in same window that we are dying: + if (mySyncNode && mySyncNode.id) { + Observable.on.suicideNurseCall.fire(db.name, mySyncNode.id); + // Inform other windows as well: + localStorage.setItem('Dexie.Observable/deadnode:' + mySyncNode.id.toString() + '/' + db.name, "dead"); // In IE, this will also wakeup our own window. cleanup() may trigger twice per other db instance. But that doesnt to anything. + mySyncNode.deleteTimeStamp = 1; // One millisecond after 1970. Makes it occur in the past but still keeps it truthy. + mySyncNode.lastHeartBeat = 0; + db._syncNodes.put(mySyncNode); // This async operation may be cancelled since the browser is closing down now. + mySyncNode = null; + } + + if (pollHandle) clearTimeout(pollHandle); + pollHandle = null; + return origClose.apply(this, arguments); + }; + }); + + // Override Dexie.delete() in order to delete Observable.latestRevision[db.name]. + db.delete = override(db.delete, function (origDelete) { + return function () { + return origDelete.apply(this, arguments).then(function (result) { + // Reset Observable.latestRevision[db.name] + Observable.latestRevision[db.name] = 0; + return result; + }); + }; + }); + + // + // The Creating/Updating/Deleting hook will make sure any change is stored to the changes table + // + function crudMonitor(table) { + /// + var tableName = table.name; + + table.hook('creating').subscribe(function (primKey, obj, trans) { + /// + var rv = undefined; + if (primKey === undefined && table.schema.primKey.uuid) { + primKey = rv = Observable.createUUID(); + if (table.schema.primKey.keyPath) { + Dexie.setByKeyPath(obj, table.schema.primKey.keyPath, primKey); + } + } + + var change = { + source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes. + table: tableName, + key: primKey === undefined ? null : primKey, + type: CREATE, + obj: obj + }; + + var promise = trans.tables._changes.add(change).then(function (rev) { + trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev); + return rev; + }); + + // Wait for onsuccess so that we have the primKey if it is auto-incremented and update the change item if so. + this.onsuccess = function (resultKey) { + if (primKey != resultKey) promise._then(function () { + change.key = resultKey; + trans.tables._changes.put(change); + }); + }; + this.onerror = function (err) { + // If the main operation fails, make sure to regret the change + promise._then(function (rev) { + // Will only happen if app code catches the main operation error to prohibit transaction from aborting. + trans.tables._changes.delete(rev); + }); + }; + + return rv; + }); + + table.hook('updating').subscribe(function (mods, primKey, oldObj, trans) { + /// + // mods may contain property paths with undefined as value if the property + // is being deleted. Since we cannot persist undefined we need to act + // like those changes is setting the value to null instead. + var modsWithoutUndefined = {}; + // As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change. + // Therefore we may do that kind of optimization here - to not add change entries if + // there's nothing to change. + var anythingChanged = false; + var newObj = Dexie.deepClone(oldObj); + for (var propPath in mods) { + var mod = mods[propPath]; + if (typeof mod === 'undefined') { + Dexie.delByKeyPath(newObj, propPath); + modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined. + anythingChanged = true; + } else { + var currentValue = Dexie.getByKeyPath(oldObj, propPath); + if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) { + Dexie.setByKeyPath(newObj, propPath, mod); + modsWithoutUndefined[propPath] = mod; + anythingChanged = true; + } + } + } + if (anythingChanged) { + var change = { + source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes. + table: tableName, + key: primKey, + type: UPDATE, + mods: modsWithoutUndefined, + oldObj: oldObj, + obj: newObj + }; + var promise = trans.tables._changes.add(change); // Just so we get the correct revision order of the update... + this.onsuccess = function () { + promise._then(function (rev) { + trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev); + }); + }; + this.onerror = function (err) { + // If the main operation fails, make sure to regret the change. + promise._then(function (rev) { + // Will only happen if app code catches the main operation error to prohibit transaction from aborting. + trans.tables._changes.delete(rev); + }); + }; + } + }); + + table.hook('deleting').subscribe(function (primKey, obj, trans) { + /// + var promise = trans.tables._changes.add({ + source: trans.source || null, // If a "source" is marked on the transaction, store it. Useful for observers that want to ignore their own changes. + table: tableName, + key: primKey, + type: DELETE, + oldObj: obj + }).then(function (rev) { + trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev); + return rev; + }); + this.onerror = function () { + // If the main operation fails, make sure to regret the change. + // Using _then because if promise is already fullfilled, the standard then() would + // do setTimeout() and we would loose the transaction. + promise._then(function (rev) { + // Will only happen if app code catches the main operation error to prohibit transaction from aborting. + trans.tables._changes.delete(rev); + }); + }; + }); + } + + // When db opens, make sure to start monitor any changes before other db operations will start. + db.on("ready", function startObserving() { + if (db.dynamicallyOpened()) return db; // Don't observe dynamically opened databases. + return db.table("_changes").orderBy("rev").last(function (lastChange) { + // Since startObserving() is called before database open() method, this will be the first database operation enqueued to db. + // Therefore we know that the retrieved value will be This query will + var latestRevision = lastChange ? lastChange.rev : 0; + mySyncNode = new SyncNode({ + myRevision: latestRevision, + type: "local", + lastHeartBeat: Date.now(), + deleteTimeStamp: null, + isMaster: 0 + }); + if (Observable.latestRevision[db.name] < latestRevision) { + // Side track . For correctness whenever setting Observable.latestRevision[db.name] we must make sure the event is fired if increased: + // There are other db instances in same window that hasnt yet been informed about a new revision + Observable.latestRevision[db.name] = latestRevision; + Dexie.ignoreTransaction(function () { + Observable.on.latestRevisionIncremented.fire(latestRevision); + }); + } + // Add new sync node or if this is a reopening of the database after a close() call, update it. + return db.transaction('rw', '_syncNodes', function () { + db._syncNodes.where('isMaster').equals(1).count(function (anyMasterNode) { + if (!anyMasterNode) { + // There's no master node. Let's take that role then. + mySyncNode.isMaster = 1; + } + // Add our node to DB and start subscribing to events + db._syncNodes.add(mySyncNode).then(function () { + Observable.on('latestRevisionIncremented', onLatestRevisionIncremented); // Wakeup when a new revision is available. + Observable.on('beforeunload', onBeforeUnload); + Observable.on('suicideNurseCall', onSuicide); + Observable.on('intercomm', onIntercomm); + // Start polling for changes and do cleanups: + pollHandle = setTimeout(poll, LOCAL_POLL); + }); + }); + }).then(function () { + cleanup(); + }); + //cleanup(); + //}); + }); + }, true); // True means the on(ready) event will survive a db reopening (db.close() / db.open()). + + var handledRevision = 0; + + function onLatestRevisionIncremented(dbname, latestRevision) { + if (dbname === db.name) { + if (handledRevision >= latestRevision) return; // Make sure to only run once per revision. (Workaround for IE triggering storage event on same window) + handledRevision = latestRevision; + Dexie.vip(function () { + readChanges(latestRevision); + }); + } + } + + function readChanges(latestRevision, recursion, wasPartial) { + // Whenever changes are read, fire db.on("changes") with the array of changes. Eventually, limit the array to 1000 entries or so (an entire database is + // downloaded from server AFTER we are initiated. For example, if first sync call fails, then after a while we get reconnected. However, that scenario + // should be handled in case database is totally empty we should fail if sync is not available) + if (!recursion && readChanges.ongoingOperation) { + // We are already reading changes. Prohibit a parallell execution of this which would lead to duplicate trigging of 'changes' event. + // Instead, the callback in toArray() will always check Observable.latestRevision[db.name] to see if it has changed and if so, re-launch readChanges(). + // The caller should get the Promise instance from the ongoing operation so that the then() method will resolve when operation is finished. + return readChanges.ongoingOperation; + } + + var partial = false; + var ourSyncNode = mySyncNode; // Because mySyncNode can suddenly be set to null on database close, and worse, can be set to a new value if database is reopened. + if (!ourSyncNode) { + return Promise.reject("Database closed"); + } + var LIMIT = 1000; + var promise = db._changes.where("rev").above(ourSyncNode.myRevision).limit(LIMIT).toArray(function (changes) { + if (changes.length > 0) { + var lastChange = changes[changes.length - 1]; + partial = changes.length === LIMIT; + db.on('changes').fire(changes, partial); + ourSyncNode.myRevision = lastChange.rev; + } else if (wasPartial) { + // No more changes, BUT since we have triggered on('changes') with partial = true, + // we HAVE TO trigger changes again with empty list and partial = false + db.on('changes').fire([], false); + } + + return db.table("_syncNodes").update(ourSyncNode, { + lastHeartBeat: Date.now(), + deleteTimeStamp: null, // Reset "deleteTimeStamp" flag if it was there. + myRevision: ourSyncNode.myRevision + }); + }).then(function (nodeWasUpdated) { + if (!nodeWasUpdated) { + // My node has been deleted. We must have been lazy and got removed by another node. + if (browserIsShuttingDown) { + throw new Error("Browser is shutting down"); + } else { + db.close(); + console.error("Out of sync"); // TODO: What to do? Reload the page? + if (global.location) global.location.reload(true); + throw new Error("Out of sync"); // Will make current promise reject + } + } + + // Check if more changes have come since we started reading changes in the first place. If so, relaunch readChanges and let the ongoing promise not + // resolve until all changes have been read. + if (partial || Observable.latestRevision[db.name] > ourSyncNode.myRevision) { + // Either there were more than 1000 changes or additional changes where added while we were reading these changes, + // In either case, call readChanges() again until we're done. + return readChanges(Observable.latestRevision[db.name], (recursion || 0) + 1, partial); + } + }).finally(function () { + delete readChanges.ongoingOperation; + }); + + if (!recursion) { + readChanges.ongoingOperation = promise; + } + return promise; + } + + function poll() { + pollHandle = null; + var currentInstance = mySyncNode.id; + Dexie.vip(function () { + // VIP ourselves. Otherwise we might not be able to consume intercomm messages from master node before database has finished opening. This would make DB stall forever. Cannot rely on storage-event since it may not always work in some browsers of different processes. + readChanges(Observable.latestRevision[db.name]).then(cleanup).then(consumeIntercommMessages).finally(function () { + // Poll again in given interval: + if (mySyncNode && mySyncNode.id === currentInstance) { + pollHandle = setTimeout(poll, LOCAL_POLL); + } + }); + }); + } + + function cleanup() { + var ourSyncNode = mySyncNode; + if (!ourSyncNode) return Promise.reject("Database closed"); + return db.transaction('rw', '_syncNodes', '_changes', '_intercomm', function () { + // Cleanup dead local nodes that has no heartbeat for over a minute + // Dont do the following: + //nodes.where("lastHeartBeat").below(Date.now() - NODE_TIMEOUT).and(function (node) { return node.type == "local"; }).delete(); + // Because client may have been in hybernate mode and recently woken up. That would lead to deletion of all nodes. + // Instead, we should mark any old nodes for deletion in a minute or so. If they still dont wakeup after that minute we could consider them dead. + var weBecameMaster = false; + db._syncNodes.where("lastHeartBeat").below(Date.now() - NODE_TIMEOUT).and(function (node) { + return node.type === 'local'; + }).modify(function (node) { + if (node.deleteTimeStamp && node.deleteTimeStamp < Date.now()) { + // Delete the node. + delete this.value; + // Cleanup localStorage "deadnode:" entry for this node (localStorage API was used to wakeup other windows (onstorage event) - an event type missing in indexedDB.) + localStorage.removeItem('Dexie.Observable/deadnode:' + node.id + '/' + db.name); + // Check if we are deleting a master node + if (node.isMaster) { + // The node we are deleting is master. We must take over that role. + // OK to call nodes.update(). No need to call Dexie.vip() because nodes is opened in existing transaction! + db._syncNodes.update(ourSyncNode, { isMaster: 1 }); + weBecameMaster = true; + } + // Cleanup intercomm messages destinated to the node being deleted: + db._intercomm.where("destinationNode").equals(node.id).modify(function (msg) { + // OK to call intercomm. No need to call Dexie.vip() because intercomm is opened in existing transaction! + // Delete the message from DB and if someone is waiting for reply, let ourselved answer the request. + delete this.value; + if (msg.wantReply) { + // Message wants a reply, meaning someone must take over its messages when it dies. Let us be that one! + Dexie.ignoreTransaction(function () { + consumeMessage(msg); + }); + } + }); + } else if (!node.deleteTimeStamp) { + // Mark the node for deletion + node.deleteTimeStamp = Date.now() + HIBERNATE_GRACE_PERIOD; + } + }).then(function () { + // Cleanup old revisions that no node is interested of. + Observable.deleteOldChanges(db); + return db.on("cleanup").fire(weBecameMaster); + }); + }); + } + + function onBeforeUnload(event) { + // Mark our own sync node for deletion. + if (!mySyncNode) return; + browserIsShuttingDown = true; + mySyncNode.deleteTimeStamp = 1; // One millisecond after 1970. Makes it occur in the past but still keeps it truthy. + mySyncNode.lastHeartBeat = 0; + db._syncNodes.put(mySyncNode); // This async operation may be cancelled since the browser is closing down now. + Observable.wereTheOneDying = true; // If other nodes in same window wakes up by this call, make sure they dont start taking over mastership and stuff... + // Inform other windows that we're gone, so that they may take over our role if needed. Setting localStorage item below will trigger Observable.onStorage, which will trigger onSuicie() below: + localStorage.setItem('Dexie.Observable/deadnode:' + mySyncNode.id.toString() + '/' + db.name, "dead"); // In IE, this will also wakeup our own window. However, that is doublechecked in nursecall subscriber below. + } + + function onSuicide(dbname, nodeID) { + if (dbname === db.name && !Observable.wereTheOneDying) { + // Make sure it's dead indeed. Second bullet. Why? Because it has marked itself for deletion in the onbeforeunload event, which is fired just before window dies. + // It's own call to put() may have been cancelled. + // Note also that in IE, this event may be called twice, but that doesnt harm! + Dexie.vip(function () { + db._syncNodes.update(nodeID, { deleteTimeStamp: 1, lastHeartBeat: 0 }).then(cleanup); + }); + } + } + + // + // Intercommunication between nodes + // + // Enable inter-process communication between browser windows + + var requestsWaitingForReply = {}; + + db.sendMessage = function (type, message, destinationNode, options) { + /// Type of message + /// Message to send + /// ID of destination node + /// {wantReply: Boolean, isFailure: Boolean, requestId: Number}. If wantReply, the returned promise will complete with the reply from remote. Otherwise it will complete when message has been successfully sent. + if (!mySyncNode) return Promise.reject("Database closed"); + options = options || {}; + var msg = { message: message, destinationNode: destinationNode, sender: mySyncNode.id, type: type }; + Dexie.extend(msg, options); // wantReply: wantReply, success: !isFailure, requestId: ... + var tables = ["_intercomm"]; + if (options.wantReply) tables.push("_syncNodes"); // If caller wants a reply, include "_syncNodes" in transaction to check that there's a reciever there. Otherwise, new master will get it. + return db.transaction('rw?', tables, function () { + if (options.wantReply) { + // Check that there is a reciever there to take the request. + return db._syncNodes.where('id').equals(destinationNode).count(function (recieverAlive) { + if (recieverAlive) return addMessage(msg);else return db._syncNodes.where('isMaster').above(0).first(function (masterNode) { + msg.destinationNode = masterNode.id; + return addMessage(msg); + }); + }); + } else { + addMessage(msg); // No need to return Promise. Caller dont need a reply. + } + + function addMessage(msg) { + return db._intercomm.add(msg).then(function (messageId) { + localStorage.setItem("Dexie.Observable/intercomm/" + db.name, messageId.toString()); + Dexie.ignoreTransaction(function () { + Observable.on.intercomm.fire(db.name); + }); + if (options.wantReply) { + return new Promise(function (resolve, reject) { + requestsWaitingForReply[messageId.toString()] = { resolve: resolve, reject: reject }; + }); + } + }); + } + }); + }; + + db.broadcastMessage = function (type, message, bIncludeSelf) { + if (!mySyncNode) return Promise.reject("Database closed"); + var mySyncNodeId = mySyncNode.id; + db._syncNodes.each(function (node) { + if (node.type === 'local' && (bIncludeSelf || node.id !== mySyncNodeId)) { + db.sendMessage(type, message, node.id); + } + }); + }; + + db.observable = {}; + db.observable.SyncNode = SyncNode; + + function consumeIntercommMessages() { + // Check if we got messages: + if (!mySyncNode) return Promise.reject("Database closed"); + return db.table('_intercomm').where("destinationNode").equals(mySyncNode.id).modify(function (msg) { + // For each message, fire the event and remove message. + delete this.value; + Dexie.ignoreTransaction(function () { + consumeMessage(msg); + }); + }); + } + + function consumeMessage(msg) { + if (msg.type === 'response') { + // This is a response. Lookup pending request and fulfill it's promise. + var request = requestsWaitingForReply[msg.requestId.toString()]; + if (request) { + if (msg.isFailure) { + request.reject(msg.message.error); + } else { + request.resolve(msg.message.result); + } + delete requestsWaitingForReply[msg.requestId.toString()]; + } + } else { + // This is a message or request. Fire the event and add an API for the subscriber to use if reply is requested + msg.resolve = function (result) { + db.sendMessage('response', { result: result }, msg.sender, { requestId: msg.id }); + }; + msg.reject = function (error) { + db.sendMessage('response', { error: error.toString() }, msg.sender, { isFailure: true, requestId: msg.id }); + }; + var message = msg.message; + delete msg.message; + Dexie.extend(msg, message); + db.on.message.fire(msg); + } + } + + function onIntercomm(dbname) { + // When storage event trigger us to check + if (dbname === db.name) { + consumeIntercommMessages(); + } + } + } + + // + // Help functions + // + + function nop() {}; + + function promisableChain(f1, f2) { + if (f1 === nop) return f2; + return function () { + var res = f1.apply(this, arguments); + if (res && typeof res.then === 'function') { + var thiz = this, + args = arguments; + return res.then(function () { + return f2.apply(thiz, args); + }); + } + return f2.apply(this, arguments); + }; + } + + // + // Static properties and methods + // + + Observable.latestRevision = {}; // Latest revision PER DATABASE. Example: Observable.latestRevision.FriendsDB = 37; + Observable.on = Dexie.events(null, "latestRevisionIncremented", "suicideNurseCall", "intercomm", "beforeunload"); // fire(dbname, value); + Observable.createUUID = function () { + // Decent solution from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript + var d = Date.now(); + var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = (d + Math.random() * 16) % 16 | 0; + d = Math.floor(d / 16); + return (c === 'x' ? r : r & 0x7 | 0x8).toString(16); + }); + return uuid; + }; + + Observable.deleteOldChanges = function (db) { + db._syncNodes.orderBy("myRevision").first(function (oldestNode) { + var timeout = Date.now() + 300, + timedout = false; + db._changes.where("rev").below(oldestNode.myRevision).until(function () { + return timedout = Date.now() > timeout; + }).delete().then(function () { + // If not done garbage collecting, reschedule a continuation of it until done. + if (timedout) setTimeout(function () { + Observable.deleteOldChanges(db); + }, 10); + }); + }); + }; + + Observable._onStorage = function onStorage(event) { + // We use the onstorage event to trigger onLatestRevisionIncremented since we will wake up when other windows modify the DB as well! + if (event.key.indexOf("Dexie.Observable/") === 0) { + // For example "Dexie.Observable/latestRevision/FriendsDB" + var parts = event.key.split('/'); + var prop = parts[1]; + var dbname = parts[2]; + if (prop === 'latestRevision') { + var rev = parseInt(event.newValue, 10); + if (!isNaN(rev) && rev > Observable.latestRevision[dbname]) { + Observable.latestRevision[dbname] = rev; + Dexie.ignoreTransaction(function () { + Observable.on('latestRevisionIncremented').fire(dbname, rev); + }); + } + } else if (prop.indexOf("deadnode:") === 0) { + var nodeID = parseInt(prop.split(':')[1], 10); + if (event.newValue) { + Observable.on.suicideNurseCall.fire(dbname, nodeID); + } + } else if (prop === 'intercomm') { + if (event.newValue) { + Observable.on.intercomm.fire(dbname); + } + } + } + }; + + Observable._onBeforeUnload = function () { + Observable.on.beforeunload.fire(); + }; + + Observable.localStorageImpl = global.localStorage; + + // + // Map window events to static events in Dexie.Observable: + // + if (global.addEventListener) { + global.addEventListener("storage", Observable._onStorage); + global.addEventListener("beforeunload", Observable._onBeforeUnload); + } + // Register addon: + Dexie.Observable = Observable; + Dexie.addons.push(Observable); + + return Observable; + +})); +//# sourceMappingURL=dexie-observable.js.map \ No newline at end of file diff --git a/addons/Dexie.Observable/dist/dexie-observable.js.map b/addons/Dexie.Observable/dist/dexie-observable.js.map new file mode 100644 index 000000000..d2f7bbf62 --- /dev/null +++ b/addons/Dexie.Observable/dist/dexie-observable.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dexie-observable.js","sources":["../C:/repos/dexie-release/addons/Dexie.Observable/tools/tmp/src/Dexie.Observable.js"],"sourcesContent":["/// \n\n/**\r\n * Dexie.Observable.js\r\n * ===================\r\n * Dexie addon for observing database changes not just on local db instance but also on other instances and windows.\r\n *\r\n * version: {version} Alpha, {date}\r\n *\r\n * Disclaimber: This addon is in alpha status meaning that\r\n * its API and behavior may change.\r\n *\r\n */\nimport Dexie from 'dexie';\n\nvar global = self;\n\n/** class DatabaseChange\r\n *\r\n * Object contained by the _changes table.\r\n */\nvar DatabaseChange = Dexie.defineClass({\n rev: Number, // Auto-incremented primary key\n source: String, // Optional source creating the change. Set if transaction.source was set when doing the operation.\n table: String, // Table name\n key: Object, // Primary key. Any type.\n type: Number, // 1 = CREATE, 2 = UPDATE, 3 = DELETE\n obj: Object, // CREATE: obj contains the object created.\n mods: Object, // UPDATE: mods contains the modifications made to the object.\n oldObj: Object // DELETE: oldObj contains the object deleted. UPDATE: oldObj contains the old object before updates applied.\n});\n\n// Import some usable helper functions\nvar override = Dexie.override;\nvar Promise = Dexie.Promise;\nvar browserIsShuttingDown = false;\n\nexport default function Observable(db) {\n /// \n /// Extension to Dexie providing Syncronization capabilities to Dexie.\n /// \n /// \n\n var NODE_TIMEOUT = 20000,\n // 20 seconds before local db instances are timed out. This is so that old changes can be deleted when not needed and to garbage collect old _syncNodes objects.\n HIBERNATE_GRACE_PERIOD = 20000,\n // 20 seconds\n // LOCAL_POLL: The time to wait before polling local db for changes and cleaning up old nodes.\n // Polling for changes is a fallback only needed in certain circomstances (when the onstorage event doesnt reach all listeners - when different browser windows doesnt share the same process)\n LOCAL_POLL = 2000,\n // 1 second. In real-world there will be this value + the time it takes to poll().\n CREATE = 1,\n UPDATE = 2,\n DELETE = 3;\n\n var localStorage = Observable.localStorageImpl;\n\n /** class SyncNode\r\n *\r\n * Object contained in the _syncNodes table.\r\n */\n var SyncNode = Dexie.defineClass({\n //id: Number,\n myRevision: Number,\n type: String, // \"local\" or \"remote\"\n lastHeartBeat: Number,\n deleteTimeStamp: Number, // In case lastHeartBeat is too old, a value of now + HIBERNATE_GRACE_PERIOD will be set here. If reached before node wakes up, node will be deleted.\n url: String, // Only applicable for \"remote\" nodes. Only used in Dexie.Syncable.\n isMaster: Number, // 1 if true. Not using Boolean because it's not possible to index Booleans in IE implementation of IDB.\n\n // Below properties should be extended in Dexie.Syncable. Not here. They apply to remote nodes only (type == \"remote\"):\n syncProtocol: String, // Tells which implementation of ISyncProtocol to use for remote syncing.\n syncContext: null,\n syncOptions: Object,\n connected: false, // FIXTHIS: Remove! Replace with status.\n status: Number,\n appliedRemoteRevision: null,\n remoteBaseRevisions: [{ local: Number, remote: null }],\n dbUploadState: {\n tablesToUpload: [String],\n currentTable: String,\n currentKey: null,\n localBaseRevision: Number\n }\n });\n\n var mySyncNode = null;\n\n // Allow other addons to access the local sync node. May be needed by Dexie.Syncable.\n Object.defineProperty(db, \"_localSyncNode\", {\n get: function () {\n return mySyncNode;\n }\n });\n\n var pollHandle = null;\n\n if (Dexie.fake) {\n // This code will never run.\n // It's here just to enable auto-complete in visual studio - helps a lot when writing code.\n db.version(1).stores({\n _syncNodes: \"++id,myRevision,lastHeartBeat\",\n _changes: \"++rev\",\n _intercomm: \"++id,destinationNode\",\n _uncommittedChanges: \"++id,node\"\n });\n db._syncNodes.mapToClass(SyncNode);\n db._changes.mapToClass(DatabaseChange);\n mySyncNode = new SyncNode({\n myRevision: 0,\n type: \"local\",\n lastHeartBeat: Date.now(),\n deleteTimeStamp: null\n });\n }\n\n //\n // Override parsing the stores to add \"_changes\" and \"_syncNodes\" tables.\n //\n db.Version.prototype._parseStoresSpec = override(db.Version.prototype._parseStoresSpec, function (origFunc) {\n return function (stores, dbSchema) {\n // Create the _changes and _syncNodes tables\n stores[\"_changes\"] = \"++rev\";\n stores[\"_syncNodes\"] = \"++id,myRevision,lastHeartBeat,url,isMaster,type,status\";\n stores[\"_intercomm\"] = \"++id,destinationNode\";\n stores[\"_uncommittedChanges\"] = \"++id,node\"; // For remote syncing when server returns a partial result.\n // Call default implementation. Will populate the dbSchema structures.\n origFunc.call(this, stores, dbSchema);\n // Allow UUID primary keys using $$ prefix on primary key or indexes\n Object.keys(dbSchema).forEach(function (tableName) {\n var schema = dbSchema[tableName];\n if (schema.primKey.name.indexOf('$$') === 0) {\n schema.primKey.uuid = true;\n schema.primKey.name = schema.primKey.name.substr(2);\n schema.primKey.keyPath = schema.primKey.keyPath.substr(2);\n }\n });\n // Now mark all observable tables\n Object.keys(dbSchema).forEach(function (tableName) {\n // Marked observable tables with \"observable\" in their TableSchema.\n if (tableName.indexOf('_') !== 0 && tableName.indexOf('$') !== 0) {\n dbSchema[tableName].observable = true;\n }\n });\n };\n });\n\n //\n // Make sure to subscribe to \"creating\", \"updating\" and \"deleting\" hooks for all observable tables that were created in the stores() method.\n //\n db._tableFactory = override(db._tableFactory, function (origCreateTable) {\n return function createTable(mode, tableSchema, transactionPromiseFactory) {\n var table = origCreateTable.apply(this, arguments);\n if (table.schema.observable && transactionPromiseFactory === db._transPromiseFactory) {\n // Only crudMonitor when creating\n crudMonitor(table);\n }\n if (table.name === \"_syncNodes\" && transactionPromiseFactory === db._transPromiseFactory) {\n table.mapToClass(SyncNode);\n }\n return table;\n };\n });\n\n // changes event on db:\n db.on.addEventType({\n changes: 'asap',\n cleanup: [promisableChain, nop], // fire (nodesTable, changesTable, trans). Hook called when cleaning up nodes. Subscribers may return a Promise to to more stuff. May do additional stuff if local sync node is master.\n message: 'asap'\n });\n\n //\n // Overide transaction creation to always include the \"_changes\" store when any observable store is involved.\n //\n db._createTransaction = override(db._createTransaction, function (origFunc) {\n return function (mode, storenames, dbschema, parent) {\n if (db.dynamicallyOpened()) return origFunc.apply(this, arguments); // Don't observe dynamically opened databases.\n var addChanges = false;\n if (mode === 'readwrite' && storenames.some(function (storeName) {\n return dbschema[storeName] && dbschema[storeName].observable;\n })) {\n // At least one included store is a observable store. Make sure to also include the _changes store.\n addChanges = true;\n storenames = storenames.slice(0); // Clone\n if (storenames.indexOf(\"_changes\") === -1) storenames.push(\"_changes\"); // Otherwise, firefox will hang... (I've reported the bug to Mozilla@Bugzilla)\n }\n // Call original db._createTransaction()\n var trans = origFunc.call(this, mode, storenames, dbschema, parent);\n // If this transaction is bound to any observable table, make sure to add changes when transaction completes.\n if (addChanges) {\n trans._lastWrittenRevision = 0;\n trans.on('complete', function () {\n if (trans._lastWrittenRevision) {\n // Changes were written in this transaction.\n if (!parent) {\n // This is root-level transaction, i.e. a physical commit has happened.\n // Delay-trigger a wakeup call:\n if (wakeupObservers.timeoutHandle) clearTimeout(wakeupObservers.timeoutHandle);\n wakeupObservers.timeoutHandle = setTimeout(function () {\n delete wakeupObservers.timeoutHandle;\n wakeupObservers(trans._lastWrittenRevision);\n }, 25);\n } else {\n // This is just a virtual commit of a sub transaction.\n // Wait with waking up observers until root transaction has committed.\n // Make sure to mark root transaction so that it will wakeup observers upon commit.\n var rootTransaction = function findRootTransaction(trans) {\n return trans.parent ? findRootTransaction(trans.parent) : trans;\n }(parent);\n rootTransaction._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rootTransaction.lastWrittenRevision || 0);\n }\n }\n });\n // Derive \"source\" property from parent transaction by default\n if (trans.parent && trans.parent.source) trans.source = trans.parent.source;\n }\n return trans;\n };\n });\n\n // If Observable.latestRevsion[db.name] is undefined, set it to 0 so that comparing against it always works.\n // You might think that it will always be undefined before this call, but in case another Dexie instance in the same\n // window with the same database name has been created already, this static property will already be set correctly.\n Observable.latestRevision[db.name] = Observable.latestRevision[db.name] || 0;\n\n function wakeupObservers(lastWrittenRevision) {\n // Make sure Observable.latestRevision[db.name] is still below our value, now when some time has elapsed and other db instances in same window possibly could have made changes too.\n if (Observable.latestRevision[db.name] < lastWrittenRevision) {\n // Set the static property lastRevision[db.name] to the revision of the last written change.\n Observable.latestRevision[db.name] = lastWrittenRevision;\n // Wakeup ourselves, and any other db instances on this window:\n Dexie.ignoreTransaction(function () {\n Observable.on('latestRevisionIncremented').fire(db.name, lastWrittenRevision);\n });\n // Observable.on.latestRevisionIncremented will only wakeup db's in current window.\n // We need a storage event to wakeup other windwos.\n // Since indexedDB lacks storage events, let's use the storage event from WebStorage just for\n // the purpose to wakeup db instances in other windows.\n localStorage.setItem('Dexie.Observable/latestRevision/' + db.name, lastWrittenRevision); // In IE, this will also wakeup our own window. However, onLatestRevisionIncremented will work around this by only running once per revision id.\n }\n }\n\n db.close = override(db.close, function (origClose) {\n return function () {\n if (db.dynamicallyOpened()) return origClose.apply(this, arguments); // Don't observe dynamically opened databases.\n // Teardown our framework.\n if (wakeupObservers.timeoutHandle) {\n clearTimeout(wakeupObservers.timeoutHandle);\n delete wakeupObservers.timeoutHandle;\n }\n Observable.on('latestRevisionIncremented').unsubscribe(onLatestRevisionIncremented);\n Observable.on('suicideNurseCall').unsubscribe(onSuicide);\n Observable.on('intercomm').unsubscribe(onIntercomm);\n Observable.on('beforeunload').unsubscribe(onBeforeUnload);\n // Inform other db instances in same window that we are dying:\n if (mySyncNode && mySyncNode.id) {\n Observable.on.suicideNurseCall.fire(db.name, mySyncNode.id);\n // Inform other windows as well:\n localStorage.setItem('Dexie.Observable/deadnode:' + mySyncNode.id.toString() + '/' + db.name, \"dead\"); // In IE, this will also wakeup our own window. cleanup() may trigger twice per other db instance. But that doesnt to anything.\n mySyncNode.deleteTimeStamp = 1; // One millisecond after 1970. Makes it occur in the past but still keeps it truthy.\n mySyncNode.lastHeartBeat = 0;\n db._syncNodes.put(mySyncNode); // This async operation may be cancelled since the browser is closing down now.\n mySyncNode = null;\n }\n\n if (pollHandle) clearTimeout(pollHandle);\n pollHandle = null;\n return origClose.apply(this, arguments);\n };\n });\n\n // Override Dexie.delete() in order to delete Observable.latestRevision[db.name].\n db.delete = override(db.delete, function (origDelete) {\n return function () {\n return origDelete.apply(this, arguments).then(function (result) {\n // Reset Observable.latestRevision[db.name]\n Observable.latestRevision[db.name] = 0;\n return result;\n });\n };\n });\n\n //\n // The Creating/Updating/Deleting hook will make sure any change is stored to the changes table\n //\n function crudMonitor(table) {\n /// \n var tableName = table.name;\n\n table.hook('creating').subscribe(function (primKey, obj, trans) {\n /// \n var rv = undefined;\n if (primKey === undefined && table.schema.primKey.uuid) {\n primKey = rv = Observable.createUUID();\n if (table.schema.primKey.keyPath) {\n Dexie.setByKeyPath(obj, table.schema.primKey.keyPath, primKey);\n }\n }\n\n var change = {\n source: trans.source || null, // If a \"source\" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.\n table: tableName,\n key: primKey === undefined ? null : primKey,\n type: CREATE,\n obj: obj\n };\n\n var promise = trans.tables._changes.add(change).then(function (rev) {\n trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev);\n return rev;\n });\n\n // Wait for onsuccess so that we have the primKey if it is auto-incremented and update the change item if so.\n this.onsuccess = function (resultKey) {\n if (primKey != resultKey) promise._then(function () {\n change.key = resultKey;\n trans.tables._changes.put(change);\n });\n };\n this.onerror = function (err) {\n // If the main operation fails, make sure to regret the change\n promise._then(function (rev) {\n // Will only happen if app code catches the main operation error to prohibit transaction from aborting.\n trans.tables._changes.delete(rev);\n });\n };\n\n return rv;\n });\n\n table.hook('updating').subscribe(function (mods, primKey, oldObj, trans) {\n /// \n // mods may contain property paths with undefined as value if the property\n // is being deleted. Since we cannot persist undefined we need to act\n // like those changes is setting the value to null instead.\n var modsWithoutUndefined = {};\n // As of current Dexie version (1.0.3) hook may be called even if it wouldnt really change.\n // Therefore we may do that kind of optimization here - to not add change entries if\n // there's nothing to change.\n var anythingChanged = false;\n var newObj = Dexie.deepClone(oldObj);\n for (var propPath in mods) {\n var mod = mods[propPath];\n if (typeof mod === 'undefined') {\n Dexie.delByKeyPath(newObj, propPath);\n modsWithoutUndefined[propPath] = null; // Null is as close we could come to deleting a property when not allowing undefined.\n anythingChanged = true;\n } else {\n var currentValue = Dexie.getByKeyPath(oldObj, propPath);\n if (mod !== currentValue && JSON.stringify(mod) !== JSON.stringify(currentValue)) {\n Dexie.setByKeyPath(newObj, propPath, mod);\n modsWithoutUndefined[propPath] = mod;\n anythingChanged = true;\n }\n }\n }\n if (anythingChanged) {\n var change = {\n source: trans.source || null, // If a \"source\" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.\n table: tableName,\n key: primKey,\n type: UPDATE,\n mods: modsWithoutUndefined,\n oldObj: oldObj,\n obj: newObj\n };\n var promise = trans.tables._changes.add(change); // Just so we get the correct revision order of the update...\n this.onsuccess = function () {\n promise._then(function (rev) {\n trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev);\n });\n };\n this.onerror = function (err) {\n // If the main operation fails, make sure to regret the change.\n promise._then(function (rev) {\n // Will only happen if app code catches the main operation error to prohibit transaction from aborting.\n trans.tables._changes.delete(rev);\n });\n };\n }\n });\n\n table.hook('deleting').subscribe(function (primKey, obj, trans) {\n /// \n var promise = trans.tables._changes.add({\n source: trans.source || null, // If a \"source\" is marked on the transaction, store it. Useful for observers that want to ignore their own changes.\n table: tableName,\n key: primKey,\n type: DELETE,\n oldObj: obj\n }).then(function (rev) {\n trans._lastWrittenRevision = Math.max(trans._lastWrittenRevision, rev);\n return rev;\n });\n this.onerror = function () {\n // If the main operation fails, make sure to regret the change.\n // Using _then because if promise is already fullfilled, the standard then() would\n // do setTimeout() and we would loose the transaction.\n promise._then(function (rev) {\n // Will only happen if app code catches the main operation error to prohibit transaction from aborting.\n trans.tables._changes.delete(rev);\n });\n };\n });\n }\n\n // When db opens, make sure to start monitor any changes before other db operations will start.\n db.on(\"ready\", function startObserving() {\n if (db.dynamicallyOpened()) return db; // Don't observe dynamically opened databases.\n return db.table(\"_changes\").orderBy(\"rev\").last(function (lastChange) {\n // Since startObserving() is called before database open() method, this will be the first database operation enqueued to db.\n // Therefore we know that the retrieved value will be This query will\n var latestRevision = lastChange ? lastChange.rev : 0;\n mySyncNode = new SyncNode({\n myRevision: latestRevision,\n type: \"local\",\n lastHeartBeat: Date.now(),\n deleteTimeStamp: null,\n isMaster: 0\n });\n if (Observable.latestRevision[db.name] < latestRevision) {\n // Side track . For correctness whenever setting Observable.latestRevision[db.name] we must make sure the event is fired if increased:\n // There are other db instances in same window that hasnt yet been informed about a new revision\n Observable.latestRevision[db.name] = latestRevision;\n Dexie.ignoreTransaction(function () {\n Observable.on.latestRevisionIncremented.fire(latestRevision);\n });\n }\n // Add new sync node or if this is a reopening of the database after a close() call, update it.\n return db.transaction('rw', '_syncNodes', function () {\n db._syncNodes.where('isMaster').equals(1).count(function (anyMasterNode) {\n if (!anyMasterNode) {\n // There's no master node. Let's take that role then.\n mySyncNode.isMaster = 1;\n }\n // Add our node to DB and start subscribing to events\n db._syncNodes.add(mySyncNode).then(function () {\n Observable.on('latestRevisionIncremented', onLatestRevisionIncremented); // Wakeup when a new revision is available.\n Observable.on('beforeunload', onBeforeUnload);\n Observable.on('suicideNurseCall', onSuicide);\n Observable.on('intercomm', onIntercomm);\n // Start polling for changes and do cleanups:\n pollHandle = setTimeout(poll, LOCAL_POLL);\n });\n });\n }).then(function () {\n cleanup();\n });\n //cleanup();\n //});\n });\n }, true); // True means the on(ready) event will survive a db reopening (db.close() / db.open()).\n\n var handledRevision = 0;\n\n function onLatestRevisionIncremented(dbname, latestRevision) {\n if (dbname === db.name) {\n if (handledRevision >= latestRevision) return; // Make sure to only run once per revision. (Workaround for IE triggering storage event on same window)\n handledRevision = latestRevision;\n Dexie.vip(function () {\n readChanges(latestRevision);\n });\n }\n }\n\n function readChanges(latestRevision, recursion, wasPartial) {\n // Whenever changes are read, fire db.on(\"changes\") with the array of changes. Eventually, limit the array to 1000 entries or so (an entire database is\n // downloaded from server AFTER we are initiated. For example, if first sync call fails, then after a while we get reconnected. However, that scenario\n // should be handled in case database is totally empty we should fail if sync is not available)\n if (!recursion && readChanges.ongoingOperation) {\n // We are already reading changes. Prohibit a parallell execution of this which would lead to duplicate trigging of 'changes' event.\n // Instead, the callback in toArray() will always check Observable.latestRevision[db.name] to see if it has changed and if so, re-launch readChanges().\n // The caller should get the Promise instance from the ongoing operation so that the then() method will resolve when operation is finished.\n return readChanges.ongoingOperation;\n }\n\n var partial = false;\n var ourSyncNode = mySyncNode; // Because mySyncNode can suddenly be set to null on database close, and worse, can be set to a new value if database is reopened.\n if (!ourSyncNode) {\n return Promise.reject(\"Database closed\");\n }\n var LIMIT = 1000;\n var promise = db._changes.where(\"rev\").above(ourSyncNode.myRevision).limit(LIMIT).toArray(function (changes) {\n if (changes.length > 0) {\n var lastChange = changes[changes.length - 1];\n partial = changes.length === LIMIT;\n db.on('changes').fire(changes, partial);\n ourSyncNode.myRevision = lastChange.rev;\n } else if (wasPartial) {\n // No more changes, BUT since we have triggered on('changes') with partial = true,\n // we HAVE TO trigger changes again with empty list and partial = false\n db.on('changes').fire([], false);\n }\n\n return db.table(\"_syncNodes\").update(ourSyncNode, {\n lastHeartBeat: Date.now(),\n deleteTimeStamp: null, // Reset \"deleteTimeStamp\" flag if it was there.\n myRevision: ourSyncNode.myRevision\n });\n }).then(function (nodeWasUpdated) {\n if (!nodeWasUpdated) {\n // My node has been deleted. We must have been lazy and got removed by another node.\n if (browserIsShuttingDown) {\n throw new Error(\"Browser is shutting down\");\n } else {\n db.close();\n console.error(\"Out of sync\"); // TODO: What to do? Reload the page?\n if (global.location) global.location.reload(true);\n throw new Error(\"Out of sync\"); // Will make current promise reject\n }\n }\n\n // Check if more changes have come since we started reading changes in the first place. If so, relaunch readChanges and let the ongoing promise not\n // resolve until all changes have been read.\n if (partial || Observable.latestRevision[db.name] > ourSyncNode.myRevision) {\n // Either there were more than 1000 changes or additional changes where added while we were reading these changes,\n // In either case, call readChanges() again until we're done.\n return readChanges(Observable.latestRevision[db.name], (recursion || 0) + 1, partial);\n }\n }).finally(function () {\n delete readChanges.ongoingOperation;\n });\n\n if (!recursion) {\n readChanges.ongoingOperation = promise;\n }\n return promise;\n }\n\n function poll() {\n pollHandle = null;\n var currentInstance = mySyncNode.id;\n Dexie.vip(function () {\n // VIP ourselves. Otherwise we might not be able to consume intercomm messages from master node before database has finished opening. This would make DB stall forever. Cannot rely on storage-event since it may not always work in some browsers of different processes.\n readChanges(Observable.latestRevision[db.name]).then(cleanup).then(consumeIntercommMessages).finally(function () {\n // Poll again in given interval:\n if (mySyncNode && mySyncNode.id === currentInstance) {\n pollHandle = setTimeout(poll, LOCAL_POLL);\n }\n });\n });\n }\n\n function cleanup() {\n var ourSyncNode = mySyncNode;\n if (!ourSyncNode) return Promise.reject(\"Database closed\");\n return db.transaction('rw', '_syncNodes', '_changes', '_intercomm', function () {\n // Cleanup dead local nodes that has no heartbeat for over a minute\n // Dont do the following:\n //nodes.where(\"lastHeartBeat\").below(Date.now() - NODE_TIMEOUT).and(function (node) { return node.type == \"local\"; }).delete();\n // Because client may have been in hybernate mode and recently woken up. That would lead to deletion of all nodes.\n // Instead, we should mark any old nodes for deletion in a minute or so. If they still dont wakeup after that minute we could consider them dead.\n var weBecameMaster = false;\n db._syncNodes.where(\"lastHeartBeat\").below(Date.now() - NODE_TIMEOUT).and(function (node) {\n return node.type === 'local';\n }).modify(function (node) {\n if (node.deleteTimeStamp && node.deleteTimeStamp < Date.now()) {\n // Delete the node.\n delete this.value;\n // Cleanup localStorage \"deadnode:\" entry for this node (localStorage API was used to wakeup other windows (onstorage event) - an event type missing in indexedDB.)\n localStorage.removeItem('Dexie.Observable/deadnode:' + node.id + '/' + db.name);\n // Check if we are deleting a master node\n if (node.isMaster) {\n // The node we are deleting is master. We must take over that role.\n // OK to call nodes.update(). No need to call Dexie.vip() because nodes is opened in existing transaction!\n db._syncNodes.update(ourSyncNode, { isMaster: 1 });\n weBecameMaster = true;\n }\n // Cleanup intercomm messages destinated to the node being deleted:\n db._intercomm.where(\"destinationNode\").equals(node.id).modify(function (msg) {\n // OK to call intercomm. No need to call Dexie.vip() because intercomm is opened in existing transaction!\n // Delete the message from DB and if someone is waiting for reply, let ourselved answer the request.\n delete this.value;\n if (msg.wantReply) {\n // Message wants a reply, meaning someone must take over its messages when it dies. Let us be that one!\n Dexie.ignoreTransaction(function () {\n consumeMessage(msg);\n });\n }\n });\n } else if (!node.deleteTimeStamp) {\n // Mark the node for deletion\n node.deleteTimeStamp = Date.now() + HIBERNATE_GRACE_PERIOD;\n }\n }).then(function () {\n // Cleanup old revisions that no node is interested of.\n Observable.deleteOldChanges(db);\n return db.on(\"cleanup\").fire(weBecameMaster);\n });\n });\n }\n\n function onBeforeUnload(event) {\n // Mark our own sync node for deletion.\n if (!mySyncNode) return;\n browserIsShuttingDown = true;\n mySyncNode.deleteTimeStamp = 1; // One millisecond after 1970. Makes it occur in the past but still keeps it truthy.\n mySyncNode.lastHeartBeat = 0;\n db._syncNodes.put(mySyncNode); // This async operation may be cancelled since the browser is closing down now.\n Observable.wereTheOneDying = true; // If other nodes in same window wakes up by this call, make sure they dont start taking over mastership and stuff...\n // Inform other windows that we're gone, so that they may take over our role if needed. Setting localStorage item below will trigger Observable.onStorage, which will trigger onSuicie() below:\n localStorage.setItem('Dexie.Observable/deadnode:' + mySyncNode.id.toString() + '/' + db.name, \"dead\"); // In IE, this will also wakeup our own window. However, that is doublechecked in nursecall subscriber below.\n }\n\n function onSuicide(dbname, nodeID) {\n if (dbname === db.name && !Observable.wereTheOneDying) {\n // Make sure it's dead indeed. Second bullet. Why? Because it has marked itself for deletion in the onbeforeunload event, which is fired just before window dies.\n // It's own call to put() may have been cancelled.\n // Note also that in IE, this event may be called twice, but that doesnt harm!\n Dexie.vip(function () {\n db._syncNodes.update(nodeID, { deleteTimeStamp: 1, lastHeartBeat: 0 }).then(cleanup);\n });\n }\n }\n\n //\n // Intercommunication between nodes\n //\n // Enable inter-process communication between browser windows\n\n var requestsWaitingForReply = {};\n\n db.sendMessage = function (type, message, destinationNode, options) {\n /// Type of message\n /// Message to send\n /// ID of destination node\n /// {wantReply: Boolean, isFailure: Boolean, requestId: Number}. If wantReply, the returned promise will complete with the reply from remote. Otherwise it will complete when message has been successfully sent.\n if (!mySyncNode) return Promise.reject(\"Database closed\");\n options = options || {};\n var msg = { message: message, destinationNode: destinationNode, sender: mySyncNode.id, type: type };\n Dexie.extend(msg, options); // wantReply: wantReply, success: !isFailure, requestId: ...\n var tables = [\"_intercomm\"];\n if (options.wantReply) tables.push(\"_syncNodes\"); // If caller wants a reply, include \"_syncNodes\" in transaction to check that there's a reciever there. Otherwise, new master will get it.\n return db.transaction('rw?', tables, function () {\n if (options.wantReply) {\n // Check that there is a reciever there to take the request.\n return db._syncNodes.where('id').equals(destinationNode).count(function (recieverAlive) {\n if (recieverAlive) return addMessage(msg);else return db._syncNodes.where('isMaster').above(0).first(function (masterNode) {\n msg.destinationNode = masterNode.id;\n return addMessage(msg);\n });\n });\n } else {\n addMessage(msg); // No need to return Promise. Caller dont need a reply.\n }\n\n function addMessage(msg) {\n return db._intercomm.add(msg).then(function (messageId) {\n localStorage.setItem(\"Dexie.Observable/intercomm/\" + db.name, messageId.toString());\n Dexie.ignoreTransaction(function () {\n Observable.on.intercomm.fire(db.name);\n });\n if (options.wantReply) {\n return new Promise(function (resolve, reject) {\n requestsWaitingForReply[messageId.toString()] = { resolve: resolve, reject: reject };\n });\n }\n });\n }\n });\n };\n\n db.broadcastMessage = function (type, message, bIncludeSelf) {\n if (!mySyncNode) return Promise.reject(\"Database closed\");\n var mySyncNodeId = mySyncNode.id;\n db._syncNodes.each(function (node) {\n if (node.type === 'local' && (bIncludeSelf || node.id !== mySyncNodeId)) {\n db.sendMessage(type, message, node.id);\n }\n });\n };\n\n db.observable = {};\n db.observable.SyncNode = SyncNode;\n\n function consumeIntercommMessages() {\n // Check if we got messages:\n if (!mySyncNode) return Promise.reject(\"Database closed\");\n return db.table('_intercomm').where(\"destinationNode\").equals(mySyncNode.id).modify(function (msg) {\n // For each message, fire the event and remove message.\n delete this.value;\n Dexie.ignoreTransaction(function () {\n consumeMessage(msg);\n });\n });\n }\n\n function consumeMessage(msg) {\n if (msg.type === 'response') {\n // This is a response. Lookup pending request and fulfill it's promise.\n var request = requestsWaitingForReply[msg.requestId.toString()];\n if (request) {\n if (msg.isFailure) {\n request.reject(msg.message.error);\n } else {\n request.resolve(msg.message.result);\n }\n delete requestsWaitingForReply[msg.requestId.toString()];\n }\n } else {\n // This is a message or request. Fire the event and add an API for the subscriber to use if reply is requested\n msg.resolve = function (result) {\n db.sendMessage('response', { result: result }, msg.sender, { requestId: msg.id });\n };\n msg.reject = function (error) {\n db.sendMessage('response', { error: error.toString() }, msg.sender, { isFailure: true, requestId: msg.id });\n };\n var message = msg.message;\n delete msg.message;\n Dexie.extend(msg, message);\n db.on.message.fire(msg);\n }\n }\n\n function onIntercomm(dbname) {\n // When storage event trigger us to check\n if (dbname === db.name) {\n consumeIntercommMessages();\n }\n }\n}\n\n//\n// Help functions\n//\n\nfunction nop() {};\n\nfunction promisableChain(f1, f2) {\n if (f1 === nop) return f2;\n return function () {\n var res = f1.apply(this, arguments);\n if (res && typeof res.then === 'function') {\n var thiz = this,\n args = arguments;\n return res.then(function () {\n return f2.apply(thiz, args);\n });\n }\n return f2.apply(this, arguments);\n };\n}\n\n//\n// Static properties and methods\n//\n\nObservable.latestRevision = {}; // Latest revision PER DATABASE. Example: Observable.latestRevision.FriendsDB = 37;\nObservable.on = Dexie.events(null, \"latestRevisionIncremented\", \"suicideNurseCall\", \"intercomm\", \"beforeunload\"); // fire(dbname, value);\nObservable.createUUID = function () {\n // Decent solution from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript\n var d = Date.now();\n var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n var r = (d + Math.random() * 16) % 16 | 0;\n d = Math.floor(d / 16);\n return (c === 'x' ? r : r & 0x7 | 0x8).toString(16);\n });\n return uuid;\n};\n\nObservable.deleteOldChanges = function (db) {\n db._syncNodes.orderBy(\"myRevision\").first(function (oldestNode) {\n var timeout = Date.now() + 300,\n timedout = false;\n db._changes.where(\"rev\").below(oldestNode.myRevision).until(function () {\n return timedout = Date.now() > timeout;\n }).delete().then(function () {\n // If not done garbage collecting, reschedule a continuation of it until done.\n if (timedout) setTimeout(function () {\n Observable.deleteOldChanges(db);\n }, 10);\n });\n });\n};\n\nObservable._onStorage = function onStorage(event) {\n // We use the onstorage event to trigger onLatestRevisionIncremented since we will wake up when other windows modify the DB as well!\n if (event.key.indexOf(\"Dexie.Observable/\") === 0) {\n // For example \"Dexie.Observable/latestRevision/FriendsDB\"\n var parts = event.key.split('/');\n var prop = parts[1];\n var dbname = parts[2];\n if (prop === 'latestRevision') {\n var rev = parseInt(event.newValue, 10);\n if (!isNaN(rev) && rev > Observable.latestRevision[dbname]) {\n Observable.latestRevision[dbname] = rev;\n Dexie.ignoreTransaction(function () {\n Observable.on('latestRevisionIncremented').fire(dbname, rev);\n });\n }\n } else if (prop.indexOf(\"deadnode:\") === 0) {\n var nodeID = parseInt(prop.split(':')[1], 10);\n if (event.newValue) {\n Observable.on.suicideNurseCall.fire(dbname, nodeID);\n }\n } else if (prop === 'intercomm') {\n if (event.newValue) {\n Observable.on.intercomm.fire(dbname);\n }\n }\n }\n};\n\nObservable._onBeforeUnload = function () {\n Observable.on.beforeunload.fire();\n};\n\nObservable.localStorageImpl = global.localStorage;\n\n//\n// Map window events to static events in Dexie.Observable:\n//\nif (global.addEventListener) {\n global.addEventListener(\"storage\", Observable._onStorage);\n global.addEventListener(\"beforeunload\", Observable._onBeforeUnload);\n}\n// Register addon:\nDexie.Observable = Observable;\nDexie.addons.push(Observable);"],"names":[],"mappings":";;;;;;;;IAeA,IAAI,MAAM,GAAG,IAAI;;;;;;IAMjB,IAAI,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC;QACnC,GAAG,EAAE,MAAM;QACX,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,MAAM;QACb,GAAG,EAAE,MAAM;QACX,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,MAAM;QACX,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,MAAM;KACjB,CAAC;;;IAGF,IAAI,QAAQ,GAAG,KAAK,CAAC,QAAQ;IAC7B,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO;IAC3B,IAAI,qBAAqB,GAAG,KAAK;;IAElB,SAAS,UAAU,CAAC,EAAE,EAAE;;;;;;QAMnC,IAAI,YAAY,GAAG,KAAK;;QAExB,sBAAsB,GAAG,KAAK;;;;QAI9B,UAAU,GAAG,IAAI;;QAEjB,MAAM,GAAG,CAAC;YACN,MAAM,GAAG,CAAC;YACV,MAAM,GAAG,CAAC;;QAEd,IAAI,YAAY,GAAG,UAAU,CAAC,gBAAgB;;;;;;QAM9C,IAAI,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC;;YAE7B,UAAU,EAAE,MAAM;YA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K,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,;;,;;"} \ No newline at end of file diff --git a/addons/Dexie.Observable/dist/dexie-observable.min.js b/addons/Dexie.Observable/dist/dexie-observable.min.js new file mode 100644 index 000000000..73d99658c --- /dev/null +++ b/addons/Dexie.Observable/dist/dexie-observable.min.js @@ -0,0 +1,2 @@ +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("dexie")):"function"==typeof define&&define.amd?define(["dexie"],n):e.Dexie.Observable=n(e.Dexie)}(this,function(e){"use strict";function n(c){function u(t){n.latestRevision[c.name]=t)return;I=t,e.vip(function(){f(t)})}}function f(e,t,i){if(!t&&f.ongoingOperation)return f.ongoingOperation;var a=!1,r=j;if(!r)return s.reject("Database closed");var u=1e3,d=c._changes.where("rev").above(r.myRevision).limit(u).toArray(function(e){if(e.length>0){var n=e[e.length-1];a=e.length===u,c.on("changes").fire(e,a),r.myRevision=n.rev}else i&&c.on("changes").fire([],!1);return c.table("_syncNodes").update(r,{lastHeartBeat:Date.now(),deleteTimeStamp:null,myRevision:r.myRevision})}).then(function(e){if(!e)throw l?new Error("Browser is shutting down"):(c.close(),console.error("Out of sync"),o.location&&o.location.reload(!0),new Error("Out of sync"));return a||n.latestRevision[c.name]>r.myRevision?f(n.latestRevision[c.name],(t||0)+1,a):void 0})["finally"](function(){delete f.ongoingOperation});return t||(f.ongoingOperation=d),d}function v(){B=null;var t=j.id;e.vip(function(){f(n.latestRevision[c.name]).then(y).then(b)["finally"](function(){j&&j.id===t&&(B=setTimeout(v,N))})})}function y(){var t=j;return t?c.transaction("rw","_syncNodes","_changes","_intercomm",function(){var i=!1;c._syncNodes.where("lastHeartBeat").below(Date.now()-x).and(function(e){return"local"===e.type}).modify(function(n){n.deleteTimeStamp&&n.deleteTimeStampi})["delete"]().then(function(){o&&setTimeout(function(){n.deleteOldChanges(e)},10)})})},n._onStorage=function(t){if(0===t.key.indexOf("Dexie.Observable/")){var i=t.key.split("/"),o=i[1],a=i[2];if("latestRevision"===o){var r=parseInt(t.newValue,10);!isNaN(r)&&r>n.latestRevision[a]&&(n.latestRevision[a]=r,e.ignoreTransaction(function(){n.on("latestRevisionIncremented").fire(a,r)}))}else if(0===o.indexOf("deadnode:")){var s=parseInt(o.split(":")[1],10);t.newValue&&n.on.suicideNurseCall.fire(a,s)}else"intercomm"===o&&t.newValue&&n.on.intercomm.fire(a)}},n._onBeforeUnload=function(){n.on.beforeunload.fire()},n.localStorageImpl=o.localStorage,o.addEventListener&&(o.addEventListener("storage",n._onStorage),o.addEventListener("beforeunload",n._onBeforeUnload)),e.Observable=n,e.addons.push(n),n}); +//# sourceMappingURL=dist/dexie-observable.min.js.map \ No newline at end of file diff --git a/addons/Dexie.Observable/dist/dexie-observable.min.js.map b/addons/Dexie.Observable/dist/dexie-observable.min.js.map new file mode 100644 index 000000000..23c44764f --- /dev/null +++ b/addons/Dexie.Observable/dist/dexie-observable.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../C:/repos/dexie-release/addons/Dexie.Observable/tools/tmp/src/Dexie.Observable.js"],"names":["Observable","db","wakeupObservers","lastWrittenRevision","latestRevision","name","Dexie","ignoreTransaction","on","fire","localStorage","setItem","crudMonitor","table","tableName","hook","subscribe","primKey","obj","trans","rv","undefined","schema","uuid","createUUID","keyPath","setByKeyPath","change","source","key","type","CREATE","promise","tables","_changes","add","then","rev","_lastWrittenRevision","Math","max","this","onsuccess","resultKey","_then","put","onerror","err","mods","oldObj","modsWithoutUndefined","anythingChanged","newObj","deepClone","propPath","mod","delByKeyPath","currentValue","getByKeyPath","JSON","stringify","UPDATE","DELETE","onLatestRevisionIncremented","dbname","handledRevision","vip","readChanges","recursion","wasPartial","ongoingOperation","partial","ourSyncNode","mySyncNode","Promise","reject","LIMIT","where","above","myRevision","limit","toArray","changes","length","lastChange","update","lastHeartBeat","Date","now","deleteTimeStamp","nodeWasUpdated","browserIsShuttingDown","Error","close","console","error","global","location","reload","poll","pollHandle","currentInstance","id","cleanup","consumeIntercommMessages","setTimeout","LOCAL_POLL","transaction","weBecameMaster","_syncNodes","below","NODE_TIMEOUT","and","node","modify","value","removeItem","isMaster","_intercomm","equals","msg","wantReply","consumeMessage","HIBERNATE_GRACE_PERIOD","deleteOldChanges","onBeforeUnload","event","wereTheOneDying","toString","onSuicide","nodeID","request","requestsWaitingForReply","requestId","isFailure","message","resolve","result","sendMessage","sender","extend","onIntercomm","localStorageImpl","SyncNode","defineClass","Number","String","url","syncProtocol","syncContext","syncOptions","Object","connected","status","appliedRemoteRevision","remoteBaseRevisions","local","remote","dbUploadState","tablesToUpload","currentTable","currentKey","localBaseRevision","defineProperty","get","fake","version","stores","_uncommittedChanges","mapToClass","DatabaseChange","Version","prototype","_parseStoresSpec","override","origFunc","dbSchema","call","keys","forEach","indexOf","substr","observable","_tableFactory","origCreateTable","mode","tableSchema","transactionPromiseFactory","apply","arguments","_transPromiseFactory","addEventType","promisableChain","nop","_createTransaction","storenames","dbschema","parent","dynamicallyOpened","addChanges","some","storeName","slice","push","rootTransaction","findRootTransaction","timeoutHandle","clearTimeout","origClose","unsubscribe","suicideNurseCall","origDelete","orderBy","last","latestRevisionIncremented","count","anyMasterNode","destinationNode","options","addMessage","messageId","intercomm","recieverAlive","first","masterNode","broadcastMessage","bIncludeSelf","mySyncNodeId","each","f1","f2","res","thiz","args","self","events","d","replace","c","r","random","floor","oldestNode","timeout","timedout","until","_onStorage","parts","split","prop","parseInt","newValue","isNaN","_onBeforeUnload","beforeunload","addEventListener","addons"],"mappings":"6NAqCe,SAASA,GAAWC,GA4L/B,QAASC,GAAgBC,GAEjBH,EAAWI,eAAeH,EAAGI,MAAQF,IAErCH,EAAWI,eAAeH,EAAGI,MAAQF,EAErCG,EAAMC,kBAAkB,WACpBP,EAAWQ,GAAG,6BAA6BC,KAAKR,EAAGI,KAAMF,KAM7DO,EAAaC,QAAQ,mCAAqCV,EAAGI,KAAMF,IA+C3E,QAASS,GAAYC,GAEjB,GAAIC,GAAYD,EAAM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KAAKC,MAAQ2J,IADnClP,YAEYmC,KAAK,WAETgN,GAAU3I,WAAW,WACrBzG,EAAW4H,iBAAiB3H,IAC7B,SAKfD,EAAWsP,WAAa,SAAmBxH,GAEvC,GAA+C,IAA3CA,EAAMjG,IAAIuJ,QAAQ,qBAA4B,CAE9C,GAAImE,GAAQzH,EAAMjG,IAAI2N,MAAM,KACxBC,EAAOF,EAAM,GACbvL,EAASuL,EAAM,EACnB,IAAa,mBAATE,EAA2B,CAC3B,GAAIpN,GAAMqN,SAAS5H,EAAM6H,SAAU,KAC9BC,MAAMvN,IAAQA,EAAMrC,EAAWI,eAAe4D,KAC/ChE,EAAWI,eAAe4D,GAAU3B,EACpC/B,EAAMC,kBAAkB,WACpBP,EAAWQ,GAAG,6BAA6BC,KAAKuD,EAAQ3B,UAG7D,IAAkC,IAA9BoN,EAAKrE,QAAQ,aAAoB,CACxC,GAAIlD,GAASwH,SAASD,EAAKD,MAAM,KAAK,GAAI,GACtC1H,GAAM6H,UACN3P,EAAWQ,GAAG0M,iBAAiBzM,KAAKuD,EAAQkE,OAEhC,cAATuH,GACH3H,EAAM6H,UACN3P,EAAWQ,GAAGqN,UAAUpN,KAAKuD,KAM7ChE,EAAW6P,gBAAkB,WACzB7P,EAAWQ,GAAGsP,aAAarP,QAG/BT,EAAW8I,iBAAmB9C,EAAOtF,aAKjCsF,EAAO+J,mBACP/J,EAAO+J,iBAAiB,UAAW/P,EAAWsP,YAC9CtJ,EAAO+J,iBAAiB,eAAgB/P,EAAW6P,kBAGvDvP,EAAMN,WAAaA,EACnBM,EAAM0P,OAAOrD,KAAK3M","file":"dist/dexie-observable.min.js.map"} \ No newline at end of file diff --git a/addons/Dexie.Syncable/dist/README.md b/addons/Dexie.Syncable/dist/README.md deleted file mode 100644 index e2bb5cf5e..000000000 --- a/addons/Dexie.Syncable/dist/README.md +++ /dev/null @@ -1,37 +0,0 @@ -## Can't find dexie-syncable.js? -Transpiled code (dist version) IS ONLY checked in to -the [releases](https://github.com/dfahlander/Dexie.js/tree/releases/addons/Dexie.Syncable/dist). -branch. - -## Download -[npmcdn.com/dexie-syncable/dist/dexie-syncable.js](https://npmcdn.com/dexie-syncable/dist/dexie-syncable.js) - -[npmcdn.com/dexie-syncable/dist/dexie-syncable.min.js](https://npmcdn.com/dexie-syncable/dist/dexie-syncable.min.js) - -[npmcdn.com/dexie-syncable/dist/dexie-syncable.js.map](https://npmcdn.com/dexie-syncable/dist/dexie-syncable.js.map) - -[npmcdn.com/dexie-syncable/dist/dexie-syncable.min.js.map](https://npmcdn.com/dexie-syncable/dist/dexie-syncable.min.js.map) - -## npm -``` -npm install dexie-syncable --save -``` -## bower -Since Dexie v1.3.4, addons are included in the dexie bower package. -``` -$ bower install dexie --save -$ ls bower_components/dexie/addons/Dexie.Syncable/dist -dexie-syncable.js dexie-syncable.js.map dexie-syncable.min.js dexie-syncable.min.js.map - -``` -## Or build them yourself... -Fork Dexie.js, then: -``` -git clone https://github.com/YOUR-USERNAME/Dexie.js.git -cd Dexie.js -npm install -cd addons/Dexie.Syncable -npm run build # or npm run watch - -``` -If you're on windows, you need to use an elevated command prompt of some reason to get `npm install` to work. diff --git a/addons/Dexie.Syncable/dist/dexie-syncable.js b/addons/Dexie.Syncable/dist/dexie-syncable.js new file mode 100644 index 000000000..39232f2f1 --- /dev/null +++ b/addons/Dexie.Syncable/dist/dexie-syncable.js @@ -0,0 +1,1005 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('dexie'), require('dexie-observable')) : + typeof define === 'function' && define.amd ? define(['dexie', 'dexie-observable'], factory) : + global.Dexie.Syncable = factory(global.Dexie,global.dexieObservable); +}(this, function (Dexie,dexieObservable) { 'use strict'; + + Dexie = 'default' in Dexie ? Dexie['default'] : Dexie; + + var override = Dexie.override; + var Promise = Dexie.Promise; + var setByKeyPath = Dexie.setByKeyPath; + var Observable = Dexie.Observable; + function Syncable(db) { + /// + + var activePeers = []; + + // Change Types + var CREATE = 1, + UPDATE = 2, + DELETE = 3; + + // Statuses + var Statuses = Syncable.Statuses; + + var MAX_CHANGES_PER_CHUNK = 1000; + + db.on('message', function (msg) { + // Message from other local node arrives... + Dexie.vip(function () { + if (msg.type === 'connect') { + // We are master node and another non-master node wants us to do the connect. + db.syncable.connect(msg.protocolName, msg.url, msg.options).then(msg.resolve, msg.reject); + } else if (msg.type === 'disconnect') { + db.syncable.disconnect(msg.url).then(msg.resolve, msg.reject); + } else if (msg.type === 'syncStatusChanged') { + // We are client and a master node informs us about syncStatus change. + // Lookup the connectedProvider and call its event + db.syncable.on.statusChanged.fire(msg.newStatus, msg.url); + } + }); + }); + + db.on('cleanup', function (weBecameMaster) { + // A cleanup (done in Dexie.Observable) may result in that a master node is removed and we become master. + if (weBecameMaster) { + // We took over the master role in Observable's cleanup method + db._syncNodes.where('type').equals('remote').and(function (node) { + return node.status !== Statuses.OFFLINE && node.status !== Statuses.ERROR; + }).each(function (connectedRemoteNode) { + // There are connected remote nodes that we must take over + // Since we may be in the on(ready) event, we must get VIPed to continue + Dexie.ignoreTransaction(function () { + Dexie.vip(function () { + db.syncable.connect(connectedRemoteNode.syncProtocol, connectedRemoteNode.url, connectedRemoteNode.syncOptions); + }); + }); + }); + } + }); + + db.on('ready', function onReady() { + // Again, in onReady: If we ARE master, make sure to connect to remote servers that is in a connected state. + if (db._localSyncNode && db._localSyncNode.isMaster) { + // Make sure to connect to remote servers that is in a connected state (NOT OFFLINE or ERROR!) + return db._syncNodes.where('type').equals('remote').and(function (node) { + return node.status !== Statuses.OFFLINE && node.status !== Statuses.ERROR; + }).toArray(function (connectedRemoteNodes) { + // There are connected remote nodes that we must take over + if (connectedRemoteNodes.length > 0) { + return Promise.all(connectedRemoteNodes.map(function (node) { + return db.syncable.connect(node.syncProtocol, node.url, node.syncOptions).catch(function (err) { + return undefined; // If a node fails to connect, don't make db.open() reject. Accept it! + }); + })); + } + }); + } + }, true); // True means the ready event will survive a db reopen - db.close()/db.open() + + db.syncable = {}; + + db.syncable.getStatus = function (url, cb) { + if (db.isOpen()) { + return Dexie.vip(function () { + return db._syncNodes.where('url').equals(url).first(function (node) { + return node ? node.status : Statuses.OFFLINE; + }); + }).then(cb); + } else { + return Promise.resolve(Syncable.Statuses.OFFLINE).then(cb); + } + }; + + db.syncable.list = function () { + return db._syncNodes.where('type').equals('remote').toArray(function (a) { + return a.map(function (node) { + return node.url; + }); + }); + }; + + db.syncable.on = Dexie.events(db, { statusChanged: "asap" }); + + db.syncable.disconnect = function (url) { + if (db._localSyncNode && db._localSyncNode.isMaster) { + activePeers.filter(function (peer) { + return peer.url === url; + }).forEach(function (peer) { + peer.disconnect(Statuses.OFFLINE); + }); + } else { + db._syncNodes.where('isMaster').above(0).first(function (masterNode) { + db.sendMessage('disconnect', { url: url }, masterNode.id, { wantReply: true }); + }); + } + + return db._syncNodes.where("url").equals(url).modify(function (node) { + node.status = Statuses.OFFLINE; + }); + }; + + db.syncable.connect = function (protocolName, url, options) { + options = options || {}; // Make sure options is always an object because 1) Provider expects it to be. 2) We'll be persisting it and you cannot persist undefined. + var protocolInstance = Syncable.registeredProtocols[protocolName]; + + if (protocolInstance) { + if (db.isOpen() && db._localSyncNode) { + // Database is open + if (db._localSyncNode.isMaster) { + // We are master node + return connect(protocolInstance, protocolName, url, options, db._localSyncNode.id); + } else { + // We are not master node + // Request master node to do the connect: + db.table('_syncNodes').where('isMaster').above(0).first(function (masterNode) { + // There will always be a master node. In theory we may self have become master node when we come here. But that's ok. We'll request ourselves. + return db.sendMessage('connect', { protocolName: protocolName, url: url, options: options }, masterNode.id, { wantReply: true }); + }); + return Promise.resolve(); + } + } else { + // Database not yet open + // Wait for it to open + return new Promise(function (resolve, reject) { + db.on("ready", function syncWhenReady() { + return Dexie.vip(function () { + return db.syncable.connect(protocolName, url, options).then(resolve).catch(function (err) { + // Reject the promise returned to the caller of db.syncable.connect(): + reject(err); + // but resolve the promise that db.on("ready") waits for, because database should succeed to open even if the connect operation fails! + }); + }); + }); + }); + } + } else { + throw new Error("ISyncProtocol '" + protocolName + "' is not registered in Dexie.Syncable.registerSyncProtocol()"); + return new Promise(); // For code completion + } + }; + + db.syncable.delete = function (url) { + // Notice: Caller should call db.syncable.disconnect(url) and wait for it to finish before calling db.syncable.delete(url) + // Surround with a readwrite-transaction + return db.transaction('rw', db._syncNodes, db._changes, db._uncommittedChanges, function () { + // Find the node + db._syncNodes.where("url").equals(url).toArray(function (nodes) { + // If it's found (or even several found, as detected by @martindiphoorn), + // let's delete it (or them) and cleanup _changes and _uncommittedChanges + // accordingly. + if (nodes.length > 0) { + var nodeIDs = nodes.map(function (node) { + return node.id; + }); + // The following 'return' statement is not needed right now, but I leave it + // there because if we would like to add a 'then()' statement to the main , + // operation above ( db._syncNodes.where("url").equals(url).toArray(...) ) , + // this return statement will asure that the whole chain is waited for + // before entering the then() callback. + return db._syncNodes.where('id').anyOf(nodeIDs).delete().then(function () { + // When theese nodes are gone, let's clear the _changes table + // from all revisions older than the oldest node. + // Delete all changes older than revision of oldest node: + Observable.deleteOldChanges(); + // Also don't forget to delete all uncommittedChanges for the deleted node: + return db._uncommittedChanges.where('node').anyOf(nodeIDs).delete(); + }); + } + }); + }); + }; + + db.syncable.unsyncedChanges = function (url) { + return db._syncNodes.where("url").equals(url).first(function (node) { + return db._changes.where('rev').above(node.myRevision).toArray(); + }); + }; + + function connect(protocolInstance, protocolName, url, options, dbAliveID) { + /// + var existingPeer = activePeers.filter(function (peer) { + return peer.url === url; + }); + if (existingPeer.length > 0) { + // Never create multiple syncNodes with same protocolName and url. Instead, let the next call to connect() return the same promise that + // have already been started and eventually also resolved. If promise has already resolved (node connected), calling existing promise.then() will give a callback directly. + return existingPeer[0].connectPromise; + } + + var connectPromise = getOrCreateSyncNode(options).then(function (node) { + return connectProtocol(node); + }); + + var rejectConnectPromise = null; + var disconnected = false; + var hasMoreToGive = true; + var activePeer = { + url: url, + status: Statuses.OFFLINE, + connectPromise: connectPromise, + on: Dexie.events(null, "disconnect"), + disconnect: function (newStatus, error) { + if (!disconnected) { + activePeer.on.disconnect.fire(newStatus, error); + var pos = activePeers.indexOf(activePeer); + if (pos >= 0) activePeers.splice(pos, 1); + if (error && rejectConnectPromise) rejectConnectPromise(error); + } + disconnected = true; + } + }; + activePeers.push(activePeer); + + return connectPromise; + + function stillAlive() { + // A better method than doing db.isOpen() because the same db instance may have been reopened, but then this sync call should be dead + // because the new instance should be considered a fresh instance and will have another local node. + return db._localSyncNode && db._localSyncNode.id === dbAliveID; + } + + function getOrCreateSyncNode(options) { + return db.transaction('rw', db._syncNodes, function () { + if (!url) throw new Error("Url cannot be empty"); + // Returning a promise from transaction scope will make the transaction promise resolve with the value of that promise. + + return db._syncNodes.where("url").equalsIgnoreCase(url).first(function (node) { + // + // PersistedContext : IPersistedContext + // + function PersistedContext(nodeID, otherProps) { + this.nodeID = nodeID; + if (otherProps) Dexie.extend(this, otherProps); + } + + PersistedContext.prototype.save = function () { + // Store this instance in the syncContext property of the node it belongs to. + return Dexie.vip(function () { + return node.save(); + }); + }; + + if (node) { + // Node already there. Make syncContext become an instance of PersistedContext: + node.syncContext = new PersistedContext(node.id, node.syncContext); + node.syncProtocol = protocolName; // In case it was changed (would be very strange but...) could happen... + db._syncNodes.put(node); + } else { + // Create new node and sync everything + node = new db.observable.SyncNode(); + node.myRevision = -1; + node.appliedRemoteRevision = null; + node.remoteBaseRevisions = []; + node.type = "remote"; + node.syncProtocol = protocolName; + node.url = url; + node.syncOptions = options; + node.lastHeartBeat = Date.now(); + node.dbUploadState = null; + Promise.resolve(function () { + // If options.initialUpload is explicitely false, set myRevision to currentRevision. + if (options.initialUpload === false) return db._changes.lastKey(function (currentRevision) { + node.myRevision = currentRevision; + }); + }).then(function () { + db._syncNodes.add(node).then(function (nodeId) { + node.syncContext = new PersistedContext(nodeId); // Update syncContext in db with correct nodeId. + db._syncNodes.put(node); + }); + }); + } + + return node; // returning node will make the db.transaction()-promise resolve with this value. + }); + }); + } + + function connectProtocol(node) { + /// + + function changeStatusTo(newStatus) { + if (node.status !== newStatus) { + node.status = newStatus; + node.save(); + db.syncable.on.statusChanged.fire(newStatus, url); + // Also broadcast message to other nodes about the status + db.broadcastMessage("syncStatusChanged", { newStatus: newStatus, url: url }, false); + } + } + + activePeer.on('disconnect', function (newStatus) { + if (!isNaN(newStatus)) changeStatusTo(newStatus); + }); + + var connectedContinuation; + changeStatusTo(Statuses.CONNECTING); + return doSync(); + + function doSync() { + // Use enque() to ensure only a single promise execution at a time. + return enque(doSync, function () { + // By returning the Promise returned by getLocalChangesForNode() a final catch() on the sync() method will also catch error occurring in entire sequence. + return getLocalChangesForNode_autoAckIfEmpty(node, function sendChangesToProvider(changes, remoteBaseRevision, partial, nodeModificationsOnAck) { + // Create a final Promise for the entire sync() operation that will resolve when provider calls onSuccess(). + // By creating finalPromise before calling protocolInstance.sync() it is possible for provider to call onError() immediately if it wants. + var finalSyncPromise = new Promise(function (resolve, reject) { + rejectConnectPromise = function (err) { + reject(err); + }; + Dexie.asap(function () { + try { + protocolInstance.sync(node.syncContext, url, options, remoteBaseRevision, node.appliedRemoteRevision, changes, partial, applyRemoteChanges, onChangesAccepted, function (continuation) { + resolve(continuation); + }, onError); + } catch (ex) { + onError(ex, Infinity); + } + + function onError(error, again) { + reject(error); + if (stillAlive()) { + if (!isNaN(again) && again < Infinity) { + setTimeout(function () { + if (stillAlive()) { + changeStatusTo(Statuses.SYNCING); + doSync(); + } + }, again); + changeStatusTo(Statuses.ERROR_WILL_RETRY, error); + if (connectedContinuation && connectedContinuation.disconnect) connectedContinuation.disconnect(); + connectedContinuation = null; + } else { + abortTheProvider(error); // Will fire ERROR on statusChanged event. + } + } + } + }); + }); + + return finalSyncPromise.then(function () { + // Resolve caller of db.syncable.connect() with undefined. Not with continuation! + }); + + function onChangesAccepted() { + Object.keys(nodeModificationsOnAck).forEach(function (keyPath) { + Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]); + }); + node.save(); + // We dont know if onSuccess() was called by provider yet. If it's already called, finalPromise.then() will execute immediately, + // otherwise it will execute when finalSyncPromise resolves. + finalSyncPromise.then(continueSendingChanges); + } + }); + }, dbAliveID); + } + + function abortTheProvider(error) { + activePeer.disconnect(Statuses.ERROR, error); + } + + function getBaseRevisionAndMaxClientRevision(node) { + /// + if (node.remoteBaseRevisions.length === 0) return { + // No remoteBaseRevisions have arrived yet. No limit on clientRevision and provide null as remoteBaseRevision: + maxClientRevision: Infinity, + remoteBaseRevision: null + }; + for (var i = node.remoteBaseRevisions.length - 1; i >= 0; --i) { + if (node.myRevision >= node.remoteBaseRevisions[i].local) { + // Found a remoteBaseRevision that fits node.myRevision. Return remoteBaseRevision and eventually a roof maxClientRevision pointing out where next remoteBaseRevision bases its changes on. + return { + maxClientRevision: i === node.remoteBaseRevisions.length - 1 ? Infinity : node.remoteBaseRevisions[i + 1].local, + remoteBaseRevision: node.remoteBaseRevisions[i].remote + }; + } + } + // There are at least one item in the list but the server hasnt yet become up-to-date with the 0 revision from client. + return { + maxClientRevision: node.remoteBaseRevisions[0].local, + remoteBaseRevision: null + }; + } + + function getLocalChangesForNode_autoAckIfEmpty(node, cb) { + return getLocalChangesForNode(node, function autoAck(changes, remoteBaseRevision, partial, nodeModificationsOnAck) { + if (changes.length === 0 && 'myRevision' in nodeModificationsOnAck && nodeModificationsOnAck.myRevision !== node.myRevision) { + Object.keys(nodeModificationsOnAck).forEach(function (keyPath) { + Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]); + }); + node.save(); + return getLocalChangesForNode(node, autoAck); + } else { + return cb(changes, remoteBaseRevision, partial, nodeModificationsOnAck); + } + }); + } + + function getLocalChangesForNode(node, cb) { + /// + /// Based on given node's current revision and state, this function makes sure to retrieve next chunk of changes + /// for that node. + /// + /// + /// Callback that will retrieve next chunk of changes and a boolean telling if it's a partial result or not. If truthy, result is partial and there are more changes to come. If falsy, these changes are the final result. + + if (node.myRevision >= 0) { + // Node is based on a revision in our local database and will just need to get the changes that has occurred since that revision. + var brmcr = getBaseRevisionAndMaxClientRevision(node); + return getChangesSinceRevision(node.myRevision, MAX_CHANGES_PER_CHUNK, brmcr.maxClientRevision, function (changes, partial, nodeModificationsOnAck) { + return cb(changes, brmcr.remoteBaseRevision, partial, nodeModificationsOnAck); + }); + } else { + // Node hasn't got anything from our local database yet. We will need to upload entire DB to the node in the form of CREATE changes. + // Check if we're in the middle of already doing that: + if (node.dbUploadState === null) { + // Initiatalize dbUploadState + var tablesToUpload = db.tables.filter(function (table) { + return table.schema.observable; + }).map(function (table) { + return table.name; + }); + if (tablesToUpload.length === 0) return Promise.resolve(cb([], null, false, {})); // There are no synched tables at all. + var dbUploadState = { + tablesToUpload: tablesToUpload, + currentTable: tablesToUpload.shift(), + currentKey: null + }; + return db._changes.orderBy('rev').last(function (lastChange) { + dbUploadState.localBaseRevision = lastChange && lastChange.rev || 0; + var collection = db.table(dbUploadState.currentTable).orderBy(':id'); + return getTableObjectsAsChanges(dbUploadState, [], collection); + }); + } else if (node.dbUploadState.currentKey) { + var collection = db.table(node.dbUploadState.currentTable).where(':id').above(node.dbUploadState.currentKey); + return getTableObjectsAsChanges(Dexie.deepClone(node.dbUploadState), [], collection); + } else { + var collection = db.table(dbUploadState.currentTable).orderBy(':id'); + return getTableObjectsAsChanges(Dexie.deepClone(node.dbUploadState), [], collection); + } + } + + function getTableObjectsAsChanges(state, changes, collection) { + /// + /// + /// + var limitReached = false; + return collection.until(function () { + if (changes.length === MAX_CHANGES_PER_CHUNK) { + limitReached = true; + return true; + } + }).each(function (item, cursor) { + changes.push({ + type: CREATE, + table: state.currentTable, + key: cursor.key, + obj: cursor.value + }); + state.currentKey = cursor.key; + }).then(function () { + if (limitReached) { + // Limit reached. Send partial result. + hasMoreToGive = true; + return cb(changes, null, true, { dbUploadState: state }); + } else { + // Done iterating this table. Check if there are more tables to go through: + if (state.tablesToUpload.length === 0) { + // Done iterating all tables + // Now append changes occurred during our dbUpload: + var brmcr = getBaseRevisionAndMaxClientRevision(node); + return getChangesSinceRevision(state.localBaseRevision, MAX_CHANGES_PER_CHUNK - changes.length, brmcr.maxClientRevision, function (additionalChanges, partial, nodeModificationsOnAck) { + changes = changes.concat(additionalChanges); + nodeModificationsOnAck.dbUploadState = null; + return cb(changes, brmcr.remoteBaseRevision, partial, nodeModificationsOnAck); + }); + } else { + // Not done iterating all tables. Continue on next table: + state.currentTable = state.tablesToUpload.shift(); + return getTableObjectsAsChanges(state, changes, db.table(state.currentTable).orderBy(':id')); + } + } + }); + } + + function getChangesSinceRevision(revision, maxChanges, maxRevision, cb) { + /// Callback that will retrieve next chunk of changes and a boolean telling if it's a partial result or not. If truthy, result is partial and there are more changes to come. If falsy, these changes are the final result. + var changeSet = {}; + var numChanges = 0; + var partial = false; + var ignoreSource = node.id; + var nextRevision = revision; + return db.transaction('r', db._changes, function () { + var query = maxRevision === Infinity ? db._changes.where('rev').above(revision) : db._changes.where('rev').between(revision, maxRevision, false, true); + query.until(function () { + if (numChanges === maxChanges) { + partial = true; + return true; + } + }).each(function (change) { + // Note the revision in nextRevision: + nextRevision = change.rev; + if (change.source === ignoreSource) return; + // Our _changes table contains more info than required (old objs, source etc). Just make sure to include the nescessary info: + var changeToSend = { + type: change.type, + table: change.table, + key: change.key + }; + if (change.type === CREATE) changeToSend.obj = change.obj;else if (change.type === UPDATE) changeToSend.mods = change.mods; + + var id = change.table + ":" + change.key; + var prevChange = changeSet[id]; + if (!prevChange) { + // This is the first change on this key. Add it unless it comes from the source that we are working against + changeSet[id] = changeToSend; + ++numChanges; + } else { + // Merge the oldchange with the new change + var nextChange = changeToSend; + var mergedChange = function () { + switch (prevChange.type) { + case CREATE: + switch (nextChange.type) { + case CREATE: + return nextChange; // Another CREATE replaces previous CREATE. + case UPDATE: + return combineCreateAndUpdate(prevChange, nextChange); // Apply nextChange.mods into prevChange.obj + case DELETE: + return nextChange; // Object created and then deleted. If it wasnt for that we MUST handle resent changes, we would skip entire change here. But what if the CREATE was sent earlier, and then CREATE/DELETE at later stage? It would become a ghost object in DB. Therefore, we MUST keep the delete change! If object doesnt exist, it wont harm! + } + break; + case UPDATE: + switch (nextChange.type) { + case CREATE: + return nextChange; // Another CREATE replaces previous update. + case UPDATE: + return combineUpdateAndUpdate(prevChange, nextChange); // Add the additional modifications to existing modification set. + case DELETE: + return nextChange; // Only send the delete change. What was updated earlier is no longer of interest. + } + break; + case DELETE: + switch (nextChange.type) { + case CREATE: + return nextChange; // A resurection occurred. Only create change is of interest. + case UPDATE: + return prevChange; // Nothing to do. We cannot update an object that doesnt exist. Leave the delete change there. + case DELETE: + return prevChange; // Still a delete change. Leave as is. + } + break; + } + }(); + changeSet[id] = mergedChange; + } + }); + }).then(function () { + var changes = Object.keys(changeSet).map(function (key) { + return changeSet[key]; + }); + hasMoreToGive = partial; + return cb(changes, partial, { myRevision: nextRevision }); + }); + } + } + + function applyRemoteChanges(remoteChanges, remoteRevision, partial, clear) { + return enque(applyRemoteChanges, function () { + if (!stillAlive()) return Promise.reject("Database not open"); + // FIXTHIS: Check what to do if clear() is true! + return (partial ? saveToUncommitedChanges(remoteChanges) : finallyCommitAllChanges(remoteChanges, remoteRevision)).catch(function (error) { + abortTheProvider(error); + return Promise.reject(error); + }); + }, dbAliveID); + + function saveToUncommitedChanges(changes) { + return db.transaction('rw', db._uncommittedChanges, function () { + changes.forEach(function (change) { + var changeToAdd = { + node: node.id, + type: change.type, + table: change.table, + key: change.key + }; + if (change.obj) changeToAdd.obj = change.obj; + if (change.mods) changeToAdd.mods = change.mods; + db._uncommittedChanges.add(changeToAdd); + }); + }).then(function () { + node.appliedRemoteRevision = remoteRevision; + node.save(); + }); + } + + function finallyCommitAllChanges(changes, remoteRevision) { + //alert("finallyCommitAllChanges() will now start its job."); + //var tick = Date.now(); + + // 1. Open a write transaction on all tables in DB + return db.transaction('rw', db.tables.filter(function (table) { + return table.name === '_changes' || table.name === '_uncommittedChanges' || table.schema.observable; + }), function () { + var trans = Dexie.currentTransaction; + var localRevisionBeforeChanges = 0; + db._changes.orderBy('rev').last(function (lastChange) { + // Store what revision we were at before committing the changes + localRevisionBeforeChanges = lastChange && lastChange.rev || 0; + }).then(function () { + // Specify the source. Important for the change consumer to ignore changes originated from self! + trans.source = node.id; + // 2. Apply uncommitted changes and delete each uncommitted change + return db._uncommittedChanges.where('node').equals(node.id).toArray(); + }).then(function (uncommittedChanges) { + return applyChanges(uncommittedChanges, 0); + }).then(function () { + return db._uncommittedChanges.where('node').equals(node.id).delete(); + }).then(function () { + // 3. Apply last chunk of changes + return applyChanges(changes, 0); + }).then(function () { + // Get what revision we are at now: + return db._changes.orderBy('rev').last(); + }).then(function (lastChange) { + var currentLocalRevision = lastChange && lastChange.rev || 0; + // 4. Update node states (appliedRemoteRevision, remoteBaseRevisions and eventually myRevision) + node.appliedRemoteRevision = remoteRevision; + node.remoteBaseRevisions.push({ remote: remoteRevision, local: currentLocalRevision }); + if (node.myRevision === localRevisionBeforeChanges) { + // If server was up-to-date before we added new changes from the server, update myRevision to last change + // because server is still up-to-date! This is also important in order to prohibit getLocalChangesForNode() from + // ever sending an empty change list to server, which would otherwise be done every second time it would send changes. + node.myRevision = currentLocalRevision; + } + // Garbage collect remoteBaseRevisions not in use anymore: + if (node.remoteBaseRevisions.length > 1) { + for (var i = node.remoteBaseRevisions.length - 1; i > 0; --i) { + if (node.myRevision >= node.remoteBaseRevisions[i].local) { + node.remoteBaseRevisions.splice(0, i); + break; + } + } + } + node.save(); // We are not including _syncNodes in transaction, so this save() call will execute in its own transaction. + //var tock = Date.now(); + //alert("finallyCommitAllChanges() has done its job. " + changes.length + " changes applied in " + ((tock - tick) / 1000) + "seconds"); + }); + + function applyChanges(changes, offset) { + /// + /// + var lastChangeType = 0; + var lastCreatePromise = null; + if (offset >= changes.length) return Promise.resolve(null); + var change = changes[offset]; + var table = trans.tables[change.table]; + while (change && change.type === CREATE) { + // Optimize CREATE changes because on initial sync with server, the entire DB will be downloaded in forms of CREATE changes. + // Instead of waiting for each change to resolve, do all CREATE changes in bulks until another type of change is stepped upon. + // This case is the only case that allows i to increment and the for-loop to continue since it does not return anything. + var specifyKey = !table.schema.primKey.keyPath; + lastCreatePromise = function (change, table, specifyKey) { + return (specifyKey ? table.add(change.obj, change.key) : table.add(change.obj)).catch("ConstraintError", function (e) { + return specifyKey ? table.put(change.obj, change.key) : table.put(change.obj); + }); + }(change, table, specifyKey); + change = changes[++offset]; + if (change) table = trans.tables[change.table]; + } + + if (lastCreatePromise) { + // We did some CREATE changes but now stumbled upon another type of change. + // Let's wait for the last CREATE change to resolve and then call applyChanges again at current position. Next time, lastCreatePromise will be null and a case below will happen. + return lastCreatePromise.then(function () { + return offset < changes.length ? applyChanges(changes, offset) : null; + }); + } + + if (change) { + if (change.type === UPDATE) { + return table.update(change.key, change.mods).then(function () { + // Wait for update to resolve before taking next change. Why? Because it will lock transaction anyway since we are listening to CRUD events here. + return applyChanges(changes, offset + 1); + }); + } + + if (change.type === DELETE) { + return table.delete(change.key).then(function () { + // Wait for delete to resolve before taking next change. Why? Because it will lock transaction anyway since we are listening to CRUD events here. + return applyChanges(changes, offset + 1); + }); + } + } + + return Promise.resolve(null); // Will return null or a Promise and make the entire applyChanges promise finally resolve. + } + }); + } + } + + // + // + // Continuation Patterns Follows + // + // + + function continueSendingChanges(continuation) { + if (!stillAlive()) { + // Database was closed. + if (continuation.disconnect) continuation.disconnect(); + return; + } + + connectedContinuation = continuation; + activePeer.on('disconnect', function () { + if (connectedContinuation) { + if (connectedContinuation.react) { + try { + // react pattern must provide a disconnect function. + connectedContinuation.disconnect(); + } catch (e) {} + } + connectedContinuation = null; // Stop poll() pattern from polling again and abortTheProvider() from being called twice. + } + }); + + if (continuation.react) { + continueUsingReactPattern(continuation); + } else { + continueUsingPollPattern(continuation); + } + } + + // React Pattern (eager) + function continueUsingReactPattern(continuation) { + var changesWaiting, // Boolean + isWaitingForServer; // Boolean + + function onChanges() { + if (connectedContinuation) { + changeStatusTo(Statuses.SYNCING); + if (isWaitingForServer) changesWaiting = true;else { + reactToChanges(); + } + } + } + + db.on('changes', onChanges); + + // Override disconnect() to also unsubscribe to onChanges. + activePeer.on('disconnect', function () { + db.on.changes.unsubscribe(onChanges); + }); + + function reactToChanges() { + if (!connectedContinuation) return; + changesWaiting = false; + isWaitingForServer = true; + getLocalChangesForNode_autoAckIfEmpty(node, function (changes, remoteBaseRevision, partial, nodeModificationsOnAck) { + if (!connectedContinuation) return; + if (changes.length > 0) { + continuation.react(changes, remoteBaseRevision, partial, function onChangesAccepted() { + Object.keys(nodeModificationsOnAck).forEach(function (keyPath) { + Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]); + }); + node.save(); + // More changes may be waiting: + reactToChanges(); + }); + } else { + isWaitingForServer = false; + if (changesWaiting) { + // A change jumped in between the time-spot of quering _changes and getting called back with zero changes. + // This is an expreemely rare scenario, and eventually impossible. But need to be here because it could happen in theory. + reactToChanges(); + } else { + changeStatusTo(Statuses.ONLINE); + } + } + }).catch(abortTheProvider); + } + + reactToChanges(); + } + + // Poll Pattern + function continueUsingPollPattern() { + + function syncAgain() { + getLocalChangesForNode_autoAckIfEmpty(node, function (changes, remoteBaseRevision, partial, nodeModificationsOnAck) { + + protocolInstance.sync(node.syncContext, url, options, remoteBaseRevision, node.appliedRemoteRevision, changes, partial, applyRemoteChanges, onChangesAccepted, onSuccess, onError); + + function onChangesAccepted() { + Object.keys(nodeModificationsOnAck).forEach(function (keyPath) { + Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]); + }); + node.save(); + } + + function onSuccess(continuation) { + if (!connectedContinuation) { + // Got disconnected before succeeding. Quit. + return; + } + connectedContinuation = continuation; + if (partial) { + // We only sent partial changes. Need to do another round asap. + syncAgain(); + } else { + // We've sent all changes now (in sync!) + if (!isNaN(continuation.again) && continuation.again < Infinity) { + // Provider wants to keep polling. Set Status to ONLINE. + changeStatusTo(Statuses.ONLINE); + setTimeout(function () { + if (connectedContinuation) { + changeStatusTo(Statuses.SYNCING); + syncAgain(); + } + }, continuation.again); + } else { + // Provider seems finished polling. Since we are never going to poll again, + // disconnect provider and set status to OFFLINE until another call to db.syncable.connect(). + activePeer.disconnect(Statuses.OFFLINE); + } + } + } + + function onError(error, again) { + if (!isNaN(again) && again < Infinity) { + if (connectedContinuation) { + setTimeout(function () { + if (connectedContinuation) { + changeStatusTo(Statuses.SYNCING); + syncAgain(); + } + }, again); + changeStatusTo(Statuses.ERROR_WILL_RETRY); + } // else status is already changed since we got disconnected. + } else { + abortTheProvider(error); // Will fire ERROR on onStatusChanged. + } + } + }).catch(abortTheProvider); + } + + if (hasMoreToGive) { + syncAgain(); + } else if (connectedContinuation && !isNaN(connectedContinuation.again) && connectedContinuation.again < Infinity) { + changeStatusTo(Statuses.ONLINE); + setTimeout(function () { + if (connectedContinuation) { + changeStatusTo(Statuses.SYNCING); + syncAgain(); + } + }, connectedContinuation.again); + } + } + } + } + + db.close = override(db.close, function (origClose) { + return function () { + activePeers.forEach(function (peer) { + peer.disconnect(); + }); + return origClose.apply(this, arguments); + }; + }); + + var syncNodeSaveQueContexts = {}; + db.observable.SyncNode.prototype.save = function () { + var self = this; + return db.transaction('rw?', db._syncNodes, function () { + db._syncNodes.put(self); + }); + }; + + function enque(context, fn, instanceID) { + function _enque() { + if (!context.ongoingOperation) { + context.ongoingOperation = Dexie.ignoreTransaction(function () { + return Dexie.vip(function () { + return fn(); + }); + }).then(function (res) { + delete context.ongoingOperation; + return res; + }); + } else { + context.ongoingOperation = context.ongoingOperation.then(function () { + return enque(context, fn, instanceID); + }); + } + return context.ongoingOperation; + } + + if (!instanceID) { + // Caller wants to enque it until database becomes open. + if (db.isOpen()) { + return _enque(); + } else { + return Promise.reject(new Error("Database was closed")); + } + } else if (db._localSyncNode && instanceID === db._localSyncNode.id) { + // DB is already open but queuer doesnt want it to be queued if database has been closed (request bound to current instance of DB) + return _enque(); + } else { + return Promise.reject(new Error("Database was closed")); + } + } + + function combineCreateAndUpdate(prevChange, nextChange) { + var clonedChange = Dexie.deepClone(prevChange); // Clone object before modifying since the earlier change in db.changes[] would otherwise be altered. + Object.keys(nextChange.mods).forEach(function (keyPath) { + setByKeyPath(clonedChange.obj, keyPath, nextChange.mods[keyPath]); + }); + return clonedChange; + } + + function combineUpdateAndUpdate(prevChange, nextChange) { + var clonedChange = Dexie.deepClone(prevChange); // Clone object before modifying since the earlier change in db.changes[] would otherwise be altered. + Object.keys(nextChange.mods).forEach(function (keyPath) { + // If prev-change was changing a parent path of this keyPath, we must update the parent path rather than adding this keyPath + var hadParentPath = false; + Object.keys(prevChange.mods).filter(function (parentPath) { + return keyPath.indexOf(parentPath + '.') === 0; + }).forEach(function (parentPath) { + setByKeyPath(clonedChange[parentPath], keyPath.substr(parentPath.length + 1), nextChange.mods[keyPath]); + hadParentPath = true; + }); + if (!hadParentPath) { + // Add or replace this keyPath and its new value + clonedChange.mods[keyPath] = nextChange.mods[keyPath]; + } + // In case prevChange contained sub-paths to the new keyPath, we must make sure that those sub-paths are removed since + // we must mimic what would happen if applying the two changes after each other: + Object.keys(prevChange.mods).filter(function (subPath) { + return subPath.indexOf(keyPath + '.') === 0; + }).forEach(function (subPath) { + delete clonedChange[subPath]; + }); + }); + return clonedChange; + } + }; + + Syncable.Statuses = { + ERROR: -1, // An irrepairable error occurred and the sync provider is dead. + OFFLINE: 0, // The sync provider hasnt yet become online, or it has been disconnected. + CONNECTING: 1, // Trying to connect to server + ONLINE: 2, // Connected to server and currently in sync with server + SYNCING: 3, // Syncing with server. For poll pattern, this is every poll call. For react pattern, this is when local changes are being sent to server. + ERROR_WILL_RETRY: 4 // An error occured such as net down but the sync provider will retry to connect. + }; + + Syncable.StatusTexts = { + "-1": "ERROR", + "0": "OFFLINE", + "1": "CONNECTING", + "2": "ONLINE", + "3": "SYNCING", + "4": "ERROR_WILL_RETRY" + }; + + Syncable.registeredProtocols = {}; // Map when key is the provider name. + + Syncable.registerSyncProtocol = function (name, protocolInstance) { + /// + /// Register a syncronization protocol that can syncronize databases with remote servers. + /// + /// Provider name + /// Implementation of ISyncProtocol + Syncable.registeredProtocols[name] = protocolInstance; + }; + + // Register addon in Dexie: + Dexie.Syncable = Syncable; + Dexie.addons.push(Syncable); + + return Syncable; + +})); +//# sourceMappingURL=dexie-syncable.js.map \ No newline at end of file diff --git a/addons/Dexie.Syncable/dist/dexie-syncable.js.map b/addons/Dexie.Syncable/dist/dexie-syncable.js.map new file mode 100644 index 000000000..a02f51238 --- /dev/null +++ b/addons/Dexie.Syncable/dist/dexie-syncable.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dexie-syncable.js","sources":["../C:/repos/dexie-release/addons/Dexie.Syncable/tools/tmp/src/Dexie.Syncable.js"],"sourcesContent":["/// \n/// \n/// \n/**\r\n * Dexie.Syncable.js\r\n * ===================\r\n * Dexie addon for syncing indexedDB with remote endpoints.\r\n *\r\n * version: {version} Alpha, {date}\r\n *\r\n * Disclaimber: This addon is in alpha status meaning that\r\n * its API and behavior may change.\r\n *\r\n */\n\nimport Dexie from \"dexie\";\n// Depend on 'dexie-observable'\n// To support both ES6,AMD,CJS and UMD (plain script), we just import it and then access it as \"Dexie.Observable\".\n// That way, our plugin works in all UMD cases.\n// If target platform would only be module based (ES6/AMD/CJS), we could have done 'import Observable from \"dexie-observable\"'.\nimport \"dexie-observable\";\n\nvar override = Dexie.override,\n Promise = Dexie.Promise,\n setByKeyPath = Dexie.setByKeyPath,\n Observable = Dexie.Observable;\n\nexport default function Syncable(db) {\n /// \n\n var activePeers = [];\n\n // Change Types\n var CREATE = 1,\n UPDATE = 2,\n DELETE = 3;\n\n // Statuses\n var Statuses = Syncable.Statuses;\n\n var MAX_CHANGES_PER_CHUNK = 1000;\n\n db.on('message', function (msg) {\n // Message from other local node arrives...\n Dexie.vip(function () {\n if (msg.type === 'connect') {\n // We are master node and another non-master node wants us to do the connect.\n db.syncable.connect(msg.protocolName, msg.url, msg.options).then(msg.resolve, msg.reject);\n } else if (msg.type === 'disconnect') {\n db.syncable.disconnect(msg.url).then(msg.resolve, msg.reject);\n } else if (msg.type === 'syncStatusChanged') {\n // We are client and a master node informs us about syncStatus change.\n // Lookup the connectedProvider and call its event\n db.syncable.on.statusChanged.fire(msg.newStatus, msg.url);\n }\n });\n });\n\n db.on('cleanup', function (weBecameMaster) {\n // A cleanup (done in Dexie.Observable) may result in that a master node is removed and we become master.\n if (weBecameMaster) {\n // We took over the master role in Observable's cleanup method\n db._syncNodes.where('type').equals('remote').and(function (node) {\n return node.status !== Statuses.OFFLINE && node.status !== Statuses.ERROR;\n }).each(function (connectedRemoteNode) {\n // There are connected remote nodes that we must take over\n // Since we may be in the on(ready) event, we must get VIPed to continue\n Dexie.ignoreTransaction(function () {\n Dexie.vip(function () {\n db.syncable.connect(connectedRemoteNode.syncProtocol, connectedRemoteNode.url, connectedRemoteNode.syncOptions);\n });\n });\n });\n }\n });\n\n db.on('ready', function onReady() {\n // Again, in onReady: If we ARE master, make sure to connect to remote servers that is in a connected state.\n if (db._localSyncNode && db._localSyncNode.isMaster) {\n // Make sure to connect to remote servers that is in a connected state (NOT OFFLINE or ERROR!)\n return db._syncNodes.where('type').equals('remote').and(function (node) {\n return node.status !== Statuses.OFFLINE && node.status !== Statuses.ERROR;\n }).toArray(function (connectedRemoteNodes) {\n // There are connected remote nodes that we must take over\n if (connectedRemoteNodes.length > 0) {\n return Promise.all(connectedRemoteNodes.map(function (node) {\n return db.syncable.connect(node.syncProtocol, node.url, node.syncOptions).catch(function (err) {\n return undefined; // If a node fails to connect, don't make db.open() reject. Accept it!\n });\n }));\n }\n });\n }\n }, true); // True means the ready event will survive a db reopen - db.close()/db.open()\n\n db.syncable = {};\n\n db.syncable.getStatus = function (url, cb) {\n if (db.isOpen()) {\n return Dexie.vip(function () {\n return db._syncNodes.where('url').equals(url).first(function (node) {\n return node ? node.status : Statuses.OFFLINE;\n });\n }).then(cb);\n } else {\n return Promise.resolve(Syncable.Statuses.OFFLINE).then(cb);\n }\n };\n\n db.syncable.list = function () {\n return db._syncNodes.where('type').equals('remote').toArray(function (a) {\n return a.map(function (node) {\n return node.url;\n });\n });\n };\n\n db.syncable.on = Dexie.events(db, { statusChanged: \"asap\" });\n\n db.syncable.disconnect = function (url) {\n if (db._localSyncNode && db._localSyncNode.isMaster) {\n activePeers.filter(function (peer) {\n return peer.url === url;\n }).forEach(function (peer) {\n peer.disconnect(Statuses.OFFLINE);\n });\n } else {\n db._syncNodes.where('isMaster').above(0).first(function (masterNode) {\n db.sendMessage('disconnect', { url: url }, masterNode.id, { wantReply: true });\n });\n }\n\n return db._syncNodes.where(\"url\").equals(url).modify(function (node) {\n node.status = Statuses.OFFLINE;\n });\n };\n\n db.syncable.connect = function (protocolName, url, options) {\n options = options || {}; // Make sure options is always an object because 1) Provider expects it to be. 2) We'll be persisting it and you cannot persist undefined.\n var protocolInstance = Syncable.registeredProtocols[protocolName];\n\n if (protocolInstance) {\n if (db.isOpen() && db._localSyncNode) {\n // Database is open\n if (db._localSyncNode.isMaster) {\n // We are master node\n return connect(protocolInstance, protocolName, url, options, db._localSyncNode.id);\n } else {\n // We are not master node\n // Request master node to do the connect:\n db.table('_syncNodes').where('isMaster').above(0).first(function (masterNode) {\n // There will always be a master node. In theory we may self have become master node when we come here. But that's ok. We'll request ourselves.\n return db.sendMessage('connect', { protocolName: protocolName, url: url, options: options }, masterNode.id, { wantReply: true });\n });\n return Promise.resolve();\n }\n } else {\n // Database not yet open\n // Wait for it to open\n return new Promise(function (resolve, reject) {\n db.on(\"ready\", function syncWhenReady() {\n return Dexie.vip(function () {\n return db.syncable.connect(protocolName, url, options).then(resolve).catch(function (err) {\n // Reject the promise returned to the caller of db.syncable.connect():\n reject(err);\n // but resolve the promise that db.on(\"ready\") waits for, because database should succeed to open even if the connect operation fails!\n });\n });\n });\n });\n }\n } else {\n throw new Error(\"ISyncProtocol '\" + protocolName + \"' is not registered in Dexie.Syncable.registerSyncProtocol()\");\n return new Promise(); // For code completion\n }\n };\n\n db.syncable.delete = function (url) {\n // Notice: Caller should call db.syncable.disconnect(url) and wait for it to finish before calling db.syncable.delete(url)\n // Surround with a readwrite-transaction\n return db.transaction('rw', db._syncNodes, db._changes, db._uncommittedChanges, function () {\n // Find the node\n db._syncNodes.where(\"url\").equals(url).toArray(function (nodes) {\n // If it's found (or even several found, as detected by @martindiphoorn),\n // let's delete it (or them) and cleanup _changes and _uncommittedChanges\n // accordingly.\n if (nodes.length > 0) {\n var nodeIDs = nodes.map(function (node) {\n return node.id;\n });\n // The following 'return' statement is not needed right now, but I leave it\n // there because if we would like to add a 'then()' statement to the main ,\n // operation above ( db._syncNodes.where(\"url\").equals(url).toArray(...) ) ,\n // this return statement will asure that the whole chain is waited for\n // before entering the then() callback.\n return db._syncNodes.where('id').anyOf(nodeIDs).delete().then(function () {\n // When theese nodes are gone, let's clear the _changes table\n // from all revisions older than the oldest node.\n // Delete all changes older than revision of oldest node:\n Observable.deleteOldChanges();\n // Also don't forget to delete all uncommittedChanges for the deleted node:\n return db._uncommittedChanges.where('node').anyOf(nodeIDs).delete();\n });\n }\n });\n });\n };\n\n db.syncable.unsyncedChanges = function (url) {\n return db._syncNodes.where(\"url\").equals(url).first(function (node) {\n return db._changes.where('rev').above(node.myRevision).toArray();\n });\n };\n\n function connect(protocolInstance, protocolName, url, options, dbAliveID) {\n /// \n var existingPeer = activePeers.filter(function (peer) {\n return peer.url === url;\n });\n if (existingPeer.length > 0) {\n // Never create multiple syncNodes with same protocolName and url. Instead, let the next call to connect() return the same promise that\n // have already been started and eventually also resolved. If promise has already resolved (node connected), calling existing promise.then() will give a callback directly.\n return existingPeer[0].connectPromise;\n }\n\n var connectPromise = getOrCreateSyncNode(options).then(function (node) {\n return connectProtocol(node);\n });\n\n var rejectConnectPromise = null;\n var disconnected = false;\n var hasMoreToGive = true;\n var activePeer = {\n url: url,\n status: Statuses.OFFLINE,\n connectPromise: connectPromise,\n on: Dexie.events(null, \"disconnect\"),\n disconnect: function (newStatus, error) {\n if (!disconnected) {\n activePeer.on.disconnect.fire(newStatus, error);\n var pos = activePeers.indexOf(activePeer);\n if (pos >= 0) activePeers.splice(pos, 1);\n if (error && rejectConnectPromise) rejectConnectPromise(error);\n }\n disconnected = true;\n }\n };\n activePeers.push(activePeer);\n\n return connectPromise;\n\n function stillAlive() {\n // A better method than doing db.isOpen() because the same db instance may have been reopened, but then this sync call should be dead\n // because the new instance should be considered a fresh instance and will have another local node.\n return db._localSyncNode && db._localSyncNode.id === dbAliveID;\n }\n\n function getOrCreateSyncNode(options) {\n return db.transaction('rw', db._syncNodes, function () {\n if (!url) throw new Error(\"Url cannot be empty\");\n // Returning a promise from transaction scope will make the transaction promise resolve with the value of that promise.\n\n return db._syncNodes.where(\"url\").equalsIgnoreCase(url).first(function (node) {\n //\n // PersistedContext : IPersistedContext\n //\n function PersistedContext(nodeID, otherProps) {\n this.nodeID = nodeID;\n if (otherProps) Dexie.extend(this, otherProps);\n }\n\n PersistedContext.prototype.save = function () {\n // Store this instance in the syncContext property of the node it belongs to.\n return Dexie.vip(function () {\n return node.save();\n });\n };\n\n if (node) {\n // Node already there. Make syncContext become an instance of PersistedContext:\n node.syncContext = new PersistedContext(node.id, node.syncContext);\n node.syncProtocol = protocolName; // In case it was changed (would be very strange but...) could happen...\n db._syncNodes.put(node);\n } else {\n // Create new node and sync everything\n node = new db.observable.SyncNode();\n node.myRevision = -1;\n node.appliedRemoteRevision = null;\n node.remoteBaseRevisions = [];\n node.type = \"remote\";\n node.syncProtocol = protocolName;\n node.url = url;\n node.syncOptions = options;\n node.lastHeartBeat = Date.now();\n node.dbUploadState = null;\n Promise.resolve(function () {\n // If options.initialUpload is explicitely false, set myRevision to currentRevision.\n if (options.initialUpload === false) return db._changes.lastKey(function (currentRevision) {\n node.myRevision = currentRevision;\n });\n }).then(function () {\n db._syncNodes.add(node).then(function (nodeId) {\n node.syncContext = new PersistedContext(nodeId); // Update syncContext in db with correct nodeId.\n db._syncNodes.put(node);\n });\n });\n }\n\n return node; // returning node will make the db.transaction()-promise resolve with this value.\n });\n });\n }\n\n function connectProtocol(node) {\n /// \n\n function changeStatusTo(newStatus) {\n if (node.status !== newStatus) {\n node.status = newStatus;\n node.save();\n db.syncable.on.statusChanged.fire(newStatus, url);\n // Also broadcast message to other nodes about the status\n db.broadcastMessage(\"syncStatusChanged\", { newStatus: newStatus, url: url }, false);\n }\n }\n\n activePeer.on('disconnect', function (newStatus) {\n if (!isNaN(newStatus)) changeStatusTo(newStatus);\n });\n\n var connectedContinuation;\n changeStatusTo(Statuses.CONNECTING);\n return doSync();\n\n function doSync() {\n // Use enque() to ensure only a single promise execution at a time.\n return enque(doSync, function () {\n // By returning the Promise returned by getLocalChangesForNode() a final catch() on the sync() method will also catch error occurring in entire sequence.\n return getLocalChangesForNode_autoAckIfEmpty(node, function sendChangesToProvider(changes, remoteBaseRevision, partial, nodeModificationsOnAck) {\n // Create a final Promise for the entire sync() operation that will resolve when provider calls onSuccess().\n // By creating finalPromise before calling protocolInstance.sync() it is possible for provider to call onError() immediately if it wants.\n var finalSyncPromise = new Promise(function (resolve, reject) {\n rejectConnectPromise = function (err) {\n reject(err);\n };\n Dexie.asap(function () {\n try {\n protocolInstance.sync(node.syncContext, url, options, remoteBaseRevision, node.appliedRemoteRevision, changes, partial, applyRemoteChanges, onChangesAccepted, function (continuation) {\n resolve(continuation);\n }, onError);\n } catch (ex) {\n onError(ex, Infinity);\n }\n\n function onError(error, again) {\n reject(error);\n if (stillAlive()) {\n if (!isNaN(again) && again < Infinity) {\n setTimeout(function () {\n if (stillAlive()) {\n changeStatusTo(Statuses.SYNCING);\n doSync();\n }\n }, again);\n changeStatusTo(Statuses.ERROR_WILL_RETRY, error);\n if (connectedContinuation && connectedContinuation.disconnect) connectedContinuation.disconnect();\n connectedContinuation = null;\n } else {\n abortTheProvider(error); // Will fire ERROR on statusChanged event.\n }\n }\n }\n });\n });\n\n return finalSyncPromise.then(function () {\n // Resolve caller of db.syncable.connect() with undefined. Not with continuation!\n });\n\n function onChangesAccepted() {\n Object.keys(nodeModificationsOnAck).forEach(function (keyPath) {\n Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]);\n });\n node.save();\n // We dont know if onSuccess() was called by provider yet. If it's already called, finalPromise.then() will execute immediately,\n // otherwise it will execute when finalSyncPromise resolves.\n finalSyncPromise.then(continueSendingChanges);\n }\n });\n }, dbAliveID);\n }\n\n function abortTheProvider(error) {\n activePeer.disconnect(Statuses.ERROR, error);\n }\n\n function getBaseRevisionAndMaxClientRevision(node) {\n /// \n if (node.remoteBaseRevisions.length === 0) return {\n // No remoteBaseRevisions have arrived yet. No limit on clientRevision and provide null as remoteBaseRevision:\n maxClientRevision: Infinity,\n remoteBaseRevision: null\n };\n for (var i = node.remoteBaseRevisions.length - 1; i >= 0; --i) {\n if (node.myRevision >= node.remoteBaseRevisions[i].local) {\n // Found a remoteBaseRevision that fits node.myRevision. Return remoteBaseRevision and eventually a roof maxClientRevision pointing out where next remoteBaseRevision bases its changes on.\n return {\n maxClientRevision: i === node.remoteBaseRevisions.length - 1 ? Infinity : node.remoteBaseRevisions[i + 1].local,\n remoteBaseRevision: node.remoteBaseRevisions[i].remote\n };\n }\n }\n // There are at least one item in the list but the server hasnt yet become up-to-date with the 0 revision from client.\n return {\n maxClientRevision: node.remoteBaseRevisions[0].local,\n remoteBaseRevision: null\n };\n }\n\n function getLocalChangesForNode_autoAckIfEmpty(node, cb) {\n return getLocalChangesForNode(node, function autoAck(changes, remoteBaseRevision, partial, nodeModificationsOnAck) {\n if (changes.length === 0 && 'myRevision' in nodeModificationsOnAck && nodeModificationsOnAck.myRevision !== node.myRevision) {\n Object.keys(nodeModificationsOnAck).forEach(function (keyPath) {\n Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]);\n });\n node.save();\n return getLocalChangesForNode(node, autoAck);\n } else {\n return cb(changes, remoteBaseRevision, partial, nodeModificationsOnAck);\n }\n });\n }\n\n function getLocalChangesForNode(node, cb) {\n /// \n /// Based on given node's current revision and state, this function makes sure to retrieve next chunk of changes\n /// for that node.\n /// \n /// \n /// Callback that will retrieve next chunk of changes and a boolean telling if it's a partial result or not. If truthy, result is partial and there are more changes to come. If falsy, these changes are the final result.\n\n if (node.myRevision >= 0) {\n // Node is based on a revision in our local database and will just need to get the changes that has occurred since that revision.\n var brmcr = getBaseRevisionAndMaxClientRevision(node);\n return getChangesSinceRevision(node.myRevision, MAX_CHANGES_PER_CHUNK, brmcr.maxClientRevision, function (changes, partial, nodeModificationsOnAck) {\n return cb(changes, brmcr.remoteBaseRevision, partial, nodeModificationsOnAck);\n });\n } else {\n // Node hasn't got anything from our local database yet. We will need to upload entire DB to the node in the form of CREATE changes.\n // Check if we're in the middle of already doing that:\n if (node.dbUploadState === null) {\n // Initiatalize dbUploadState\n var tablesToUpload = db.tables.filter(function (table) {\n return table.schema.observable;\n }).map(function (table) {\n return table.name;\n });\n if (tablesToUpload.length === 0) return Promise.resolve(cb([], null, false, {})); // There are no synched tables at all.\n var dbUploadState = {\n tablesToUpload: tablesToUpload,\n currentTable: tablesToUpload.shift(),\n currentKey: null\n };\n return db._changes.orderBy('rev').last(function (lastChange) {\n dbUploadState.localBaseRevision = lastChange && lastChange.rev || 0;\n var collection = db.table(dbUploadState.currentTable).orderBy(':id');\n return getTableObjectsAsChanges(dbUploadState, [], collection);\n });\n } else if (node.dbUploadState.currentKey) {\n var collection = db.table(node.dbUploadState.currentTable).where(':id').above(node.dbUploadState.currentKey);\n return getTableObjectsAsChanges(Dexie.deepClone(node.dbUploadState), [], collection);\n } else {\n var collection = db.table(dbUploadState.currentTable).orderBy(':id');\n return getTableObjectsAsChanges(Dexie.deepClone(node.dbUploadState), [], collection);\n }\n }\n\n function getTableObjectsAsChanges(state, changes, collection) {\n /// \n /// \n /// \n var limitReached = false;\n return collection.until(function () {\n if (changes.length === MAX_CHANGES_PER_CHUNK) {\n limitReached = true;\n return true;\n }\n }).each(function (item, cursor) {\n changes.push({\n type: CREATE,\n table: state.currentTable,\n key: cursor.key,\n obj: cursor.value\n });\n state.currentKey = cursor.key;\n }).then(function () {\n if (limitReached) {\n // Limit reached. Send partial result.\n hasMoreToGive = true;\n return cb(changes, null, true, { dbUploadState: state });\n } else {\n // Done iterating this table. Check if there are more tables to go through:\n if (state.tablesToUpload.length === 0) {\n // Done iterating all tables\n // Now append changes occurred during our dbUpload:\n var brmcr = getBaseRevisionAndMaxClientRevision(node);\n return getChangesSinceRevision(state.localBaseRevision, MAX_CHANGES_PER_CHUNK - changes.length, brmcr.maxClientRevision, function (additionalChanges, partial, nodeModificationsOnAck) {\n changes = changes.concat(additionalChanges);\n nodeModificationsOnAck.dbUploadState = null;\n return cb(changes, brmcr.remoteBaseRevision, partial, nodeModificationsOnAck);\n });\n } else {\n // Not done iterating all tables. Continue on next table:\n state.currentTable = state.tablesToUpload.shift();\n return getTableObjectsAsChanges(state, changes, db.table(state.currentTable).orderBy(':id'));\n }\n }\n });\n }\n\n function getChangesSinceRevision(revision, maxChanges, maxRevision, cb) {\n /// Callback that will retrieve next chunk of changes and a boolean telling if it's a partial result or not. If truthy, result is partial and there are more changes to come. If falsy, these changes are the final result.\n var changeSet = {};\n var numChanges = 0;\n var partial = false;\n var ignoreSource = node.id;\n var nextRevision = revision;\n return db.transaction('r', db._changes, function () {\n var query = maxRevision === Infinity ? db._changes.where('rev').above(revision) : db._changes.where('rev').between(revision, maxRevision, false, true);\n query.until(function () {\n if (numChanges === maxChanges) {\n partial = true;\n return true;\n }\n }).each(function (change) {\n // Note the revision in nextRevision:\n nextRevision = change.rev;\n if (change.source === ignoreSource) return;\n // Our _changes table contains more info than required (old objs, source etc). Just make sure to include the nescessary info:\n var changeToSend = {\n type: change.type,\n table: change.table,\n key: change.key\n };\n if (change.type === CREATE) changeToSend.obj = change.obj;else if (change.type === UPDATE) changeToSend.mods = change.mods;\n\n var id = change.table + \":\" + change.key;\n var prevChange = changeSet[id];\n if (!prevChange) {\n // This is the first change on this key. Add it unless it comes from the source that we are working against\n changeSet[id] = changeToSend;\n ++numChanges;\n } else {\n // Merge the oldchange with the new change\n var nextChange = changeToSend;\n var mergedChange = function () {\n switch (prevChange.type) {\n case CREATE:\n switch (nextChange.type) {\n case CREATE:\n return nextChange; // Another CREATE replaces previous CREATE.\n case UPDATE:\n return combineCreateAndUpdate(prevChange, nextChange); // Apply nextChange.mods into prevChange.obj\n case DELETE:\n return nextChange; // Object created and then deleted. If it wasnt for that we MUST handle resent changes, we would skip entire change here. But what if the CREATE was sent earlier, and then CREATE/DELETE at later stage? It would become a ghost object in DB. Therefore, we MUST keep the delete change! If object doesnt exist, it wont harm!\n }\n break;\n case UPDATE:\n switch (nextChange.type) {\n case CREATE:\n return nextChange; // Another CREATE replaces previous update.\n case UPDATE:\n return combineUpdateAndUpdate(prevChange, nextChange); // Add the additional modifications to existing modification set.\n case DELETE:\n return nextChange; // Only send the delete change. What was updated earlier is no longer of interest.\n }\n break;\n case DELETE:\n switch (nextChange.type) {\n case CREATE:\n return nextChange; // A resurection occurred. Only create change is of interest.\n case UPDATE:\n return prevChange; // Nothing to do. We cannot update an object that doesnt exist. Leave the delete change there.\n case DELETE:\n return prevChange; // Still a delete change. Leave as is.\n }\n break;\n }\n }();\n changeSet[id] = mergedChange;\n }\n });\n }).then(function () {\n var changes = Object.keys(changeSet).map(function (key) {\n return changeSet[key];\n });\n hasMoreToGive = partial;\n return cb(changes, partial, { myRevision: nextRevision });\n });\n }\n }\n\n function applyRemoteChanges(remoteChanges, remoteRevision, partial, clear) {\n return enque(applyRemoteChanges, function () {\n if (!stillAlive()) return Promise.reject(\"Database not open\");\n // FIXTHIS: Check what to do if clear() is true!\n return (partial ? saveToUncommitedChanges(remoteChanges) : finallyCommitAllChanges(remoteChanges, remoteRevision)).catch(function (error) {\n abortTheProvider(error);\n return Promise.reject(error);\n });\n }, dbAliveID);\n\n function saveToUncommitedChanges(changes) {\n return db.transaction('rw', db._uncommittedChanges, function () {\n changes.forEach(function (change) {\n var changeToAdd = {\n node: node.id,\n type: change.type,\n table: change.table,\n key: change.key\n };\n if (change.obj) changeToAdd.obj = change.obj;\n if (change.mods) changeToAdd.mods = change.mods;\n db._uncommittedChanges.add(changeToAdd);\n });\n }).then(function () {\n node.appliedRemoteRevision = remoteRevision;\n node.save();\n });\n }\n\n function finallyCommitAllChanges(changes, remoteRevision) {\n //alert(\"finallyCommitAllChanges() will now start its job.\");\n //var tick = Date.now();\n\n // 1. Open a write transaction on all tables in DB\n return db.transaction('rw', db.tables.filter(function (table) {\n return table.name === '_changes' || table.name === '_uncommittedChanges' || table.schema.observable;\n }), function () {\n var trans = Dexie.currentTransaction;\n var localRevisionBeforeChanges = 0;\n db._changes.orderBy('rev').last(function (lastChange) {\n // Store what revision we were at before committing the changes\n localRevisionBeforeChanges = lastChange && lastChange.rev || 0;\n }).then(function () {\n // Specify the source. Important for the change consumer to ignore changes originated from self!\n trans.source = node.id;\n // 2. Apply uncommitted changes and delete each uncommitted change\n return db._uncommittedChanges.where('node').equals(node.id).toArray();\n }).then(function (uncommittedChanges) {\n return applyChanges(uncommittedChanges, 0);\n }).then(function () {\n return db._uncommittedChanges.where('node').equals(node.id).delete();\n }).then(function () {\n // 3. Apply last chunk of changes\n return applyChanges(changes, 0);\n }).then(function () {\n // Get what revision we are at now:\n return db._changes.orderBy('rev').last();\n }).then(function (lastChange) {\n var currentLocalRevision = lastChange && lastChange.rev || 0;\n // 4. Update node states (appliedRemoteRevision, remoteBaseRevisions and eventually myRevision)\n node.appliedRemoteRevision = remoteRevision;\n node.remoteBaseRevisions.push({ remote: remoteRevision, local: currentLocalRevision });\n if (node.myRevision === localRevisionBeforeChanges) {\n // If server was up-to-date before we added new changes from the server, update myRevision to last change\n // because server is still up-to-date! This is also important in order to prohibit getLocalChangesForNode() from\n // ever sending an empty change list to server, which would otherwise be done every second time it would send changes.\n node.myRevision = currentLocalRevision;\n }\n // Garbage collect remoteBaseRevisions not in use anymore:\n if (node.remoteBaseRevisions.length > 1) {\n for (var i = node.remoteBaseRevisions.length - 1; i > 0; --i) {\n if (node.myRevision >= node.remoteBaseRevisions[i].local) {\n node.remoteBaseRevisions.splice(0, i);\n break;\n }\n }\n }\n node.save(); // We are not including _syncNodes in transaction, so this save() call will execute in its own transaction.\n //var tock = Date.now();\n //alert(\"finallyCommitAllChanges() has done its job. \" + changes.length + \" changes applied in \" + ((tock - tick) / 1000) + \"seconds\");\n });\n\n function applyChanges(changes, offset) {\n /// \n /// \n var lastChangeType = 0;\n var lastCreatePromise = null;\n if (offset >= changes.length) return Promise.resolve(null);\n var change = changes[offset];\n var table = trans.tables[change.table];\n while (change && change.type === CREATE) {\n // Optimize CREATE changes because on initial sync with server, the entire DB will be downloaded in forms of CREATE changes.\n // Instead of waiting for each change to resolve, do all CREATE changes in bulks until another type of change is stepped upon.\n // This case is the only case that allows i to increment and the for-loop to continue since it does not return anything.\n var specifyKey = !table.schema.primKey.keyPath;\n lastCreatePromise = function (change, table, specifyKey) {\n return (specifyKey ? table.add(change.obj, change.key) : table.add(change.obj)).catch(\"ConstraintError\", function (e) {\n return specifyKey ? table.put(change.obj, change.key) : table.put(change.obj);\n });\n }(change, table, specifyKey);\n change = changes[++offset];\n if (change) table = trans.tables[change.table];\n }\n\n if (lastCreatePromise) {\n // We did some CREATE changes but now stumbled upon another type of change.\n // Let's wait for the last CREATE change to resolve and then call applyChanges again at current position. Next time, lastCreatePromise will be null and a case below will happen.\n return lastCreatePromise.then(function () {\n return offset < changes.length ? applyChanges(changes, offset) : null;\n });\n }\n\n if (change) {\n if (change.type === UPDATE) {\n return table.update(change.key, change.mods).then(function () {\n // Wait for update to resolve before taking next change. Why? Because it will lock transaction anyway since we are listening to CRUD events here.\n return applyChanges(changes, offset + 1);\n });\n }\n\n if (change.type === DELETE) {\n return table.delete(change.key).then(function () {\n // Wait for delete to resolve before taking next change. Why? Because it will lock transaction anyway since we are listening to CRUD events here.\n return applyChanges(changes, offset + 1);\n });\n }\n }\n\n return Promise.resolve(null); // Will return null or a Promise and make the entire applyChanges promise finally resolve.\n }\n });\n }\n }\n\n //\n //\n // Continuation Patterns Follows\n //\n //\n\n function continueSendingChanges(continuation) {\n if (!stillAlive()) {\n // Database was closed.\n if (continuation.disconnect) continuation.disconnect();\n return;\n }\n\n connectedContinuation = continuation;\n activePeer.on('disconnect', function () {\n if (connectedContinuation) {\n if (connectedContinuation.react) {\n try {\n // react pattern must provide a disconnect function.\n connectedContinuation.disconnect();\n } catch (e) {}\n }\n connectedContinuation = null; // Stop poll() pattern from polling again and abortTheProvider() from being called twice.\n }\n });\n\n if (continuation.react) {\n continueUsingReactPattern(continuation);\n } else {\n continueUsingPollPattern(continuation);\n }\n }\n\n // React Pattern (eager)\n function continueUsingReactPattern(continuation) {\n var changesWaiting, // Boolean\n isWaitingForServer; // Boolean\n\n function onChanges() {\n if (connectedContinuation) {\n changeStatusTo(Statuses.SYNCING);\n if (isWaitingForServer) changesWaiting = true;else {\n reactToChanges();\n }\n }\n }\n\n db.on('changes', onChanges);\n\n // Override disconnect() to also unsubscribe to onChanges.\n activePeer.on('disconnect', function () {\n db.on.changes.unsubscribe(onChanges);\n });\n\n function reactToChanges() {\n if (!connectedContinuation) return;\n changesWaiting = false;\n isWaitingForServer = true;\n getLocalChangesForNode_autoAckIfEmpty(node, function (changes, remoteBaseRevision, partial, nodeModificationsOnAck) {\n if (!connectedContinuation) return;\n if (changes.length > 0) {\n continuation.react(changes, remoteBaseRevision, partial, function onChangesAccepted() {\n Object.keys(nodeModificationsOnAck).forEach(function (keyPath) {\n Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]);\n });\n node.save();\n // More changes may be waiting:\n reactToChanges();\n });\n } else {\n isWaitingForServer = false;\n if (changesWaiting) {\n // A change jumped in between the time-spot of quering _changes and getting called back with zero changes.\n // This is an expreemely rare scenario, and eventually impossible. But need to be here because it could happen in theory.\n reactToChanges();\n } else {\n changeStatusTo(Statuses.ONLINE);\n }\n }\n }).catch(abortTheProvider);\n }\n\n reactToChanges();\n }\n\n // Poll Pattern\n function continueUsingPollPattern() {\n\n function syncAgain() {\n getLocalChangesForNode_autoAckIfEmpty(node, function (changes, remoteBaseRevision, partial, nodeModificationsOnAck) {\n\n protocolInstance.sync(node.syncContext, url, options, remoteBaseRevision, node.appliedRemoteRevision, changes, partial, applyRemoteChanges, onChangesAccepted, onSuccess, onError);\n\n function onChangesAccepted() {\n Object.keys(nodeModificationsOnAck).forEach(function (keyPath) {\n Dexie.setByKeyPath(node, keyPath, nodeModificationsOnAck[keyPath]);\n });\n node.save();\n }\n\n function onSuccess(continuation) {\n if (!connectedContinuation) {\n // Got disconnected before succeeding. Quit.\n return;\n }\n connectedContinuation = continuation;\n if (partial) {\n // We only sent partial changes. Need to do another round asap.\n syncAgain();\n } else {\n // We've sent all changes now (in sync!)\n if (!isNaN(continuation.again) && continuation.again < Infinity) {\n // Provider wants to keep polling. Set Status to ONLINE.\n changeStatusTo(Statuses.ONLINE);\n setTimeout(function () {\n if (connectedContinuation) {\n changeStatusTo(Statuses.SYNCING);\n syncAgain();\n }\n }, continuation.again);\n } else {\n // Provider seems finished polling. Since we are never going to poll again,\n // disconnect provider and set status to OFFLINE until another call to db.syncable.connect().\n activePeer.disconnect(Statuses.OFFLINE);\n }\n }\n }\n\n function onError(error, again) {\n if (!isNaN(again) && again < Infinity) {\n if (connectedContinuation) {\n setTimeout(function () {\n if (connectedContinuation) {\n changeStatusTo(Statuses.SYNCING);\n syncAgain();\n }\n }, again);\n changeStatusTo(Statuses.ERROR_WILL_RETRY);\n } // else status is already changed since we got disconnected.\n } else {\n abortTheProvider(error); // Will fire ERROR on onStatusChanged.\n }\n }\n }).catch(abortTheProvider);\n }\n\n if (hasMoreToGive) {\n syncAgain();\n } else if (connectedContinuation && !isNaN(connectedContinuation.again) && connectedContinuation.again < Infinity) {\n changeStatusTo(Statuses.ONLINE);\n setTimeout(function () {\n if (connectedContinuation) {\n changeStatusTo(Statuses.SYNCING);\n syncAgain();\n }\n }, connectedContinuation.again);\n }\n }\n }\n }\n\n db.close = override(db.close, function (origClose) {\n return function () {\n activePeers.forEach(function (peer) {\n peer.disconnect();\n });\n return origClose.apply(this, arguments);\n };\n });\n\n var syncNodeSaveQueContexts = {};\n db.observable.SyncNode.prototype.save = function () {\n var self = this;\n return db.transaction('rw?', db._syncNodes, function () {\n db._syncNodes.put(self);\n });\n };\n\n function enque(context, fn, instanceID) {\n function _enque() {\n if (!context.ongoingOperation) {\n context.ongoingOperation = Dexie.ignoreTransaction(function () {\n return Dexie.vip(function () {\n return fn();\n });\n }).then(function (res) {\n delete context.ongoingOperation;\n return res;\n });\n } else {\n context.ongoingOperation = context.ongoingOperation.then(function () {\n return enque(context, fn, instanceID);\n });\n }\n return context.ongoingOperation;\n }\n\n if (!instanceID) {\n // Caller wants to enque it until database becomes open.\n if (db.isOpen()) {\n return _enque();\n } else {\n return Promise.reject(new Error(\"Database was closed\"));\n }\n } else if (db._localSyncNode && instanceID === db._localSyncNode.id) {\n // DB is already open but queuer doesnt want it to be queued if database has been closed (request bound to current instance of DB)\n return _enque();\n } else {\n return Promise.reject(new Error(\"Database was closed\"));\n }\n }\n\n function combineCreateAndUpdate(prevChange, nextChange) {\n var clonedChange = Dexie.deepClone(prevChange); // Clone object before modifying since the earlier change in db.changes[] would otherwise be altered.\n Object.keys(nextChange.mods).forEach(function (keyPath) {\n setByKeyPath(clonedChange.obj, keyPath, nextChange.mods[keyPath]);\n });\n return clonedChange;\n }\n\n function combineUpdateAndUpdate(prevChange, nextChange) {\n var clonedChange = Dexie.deepClone(prevChange); // Clone object before modifying since the earlier change in db.changes[] would otherwise be altered.\n Object.keys(nextChange.mods).forEach(function (keyPath) {\n // If prev-change was changing a parent path of this keyPath, we must update the parent path rather than adding this keyPath\n var hadParentPath = false;\n Object.keys(prevChange.mods).filter(function (parentPath) {\n return keyPath.indexOf(parentPath + '.') === 0;\n }).forEach(function (parentPath) {\n setByKeyPath(clonedChange[parentPath], keyPath.substr(parentPath.length + 1), nextChange.mods[keyPath]);\n hadParentPath = true;\n });\n if (!hadParentPath) {\n // Add or replace this keyPath and its new value\n clonedChange.mods[keyPath] = nextChange.mods[keyPath];\n }\n // In case prevChange contained sub-paths to the new keyPath, we must make sure that those sub-paths are removed since\n // we must mimic what would happen if applying the two changes after each other:\n Object.keys(prevChange.mods).filter(function (subPath) {\n return subPath.indexOf(keyPath + '.') === 0;\n }).forEach(function (subPath) {\n delete clonedChange[subPath];\n });\n });\n return clonedChange;\n }\n};\n\nSyncable.Statuses = {\n ERROR: -1, // An irrepairable error occurred and the sync provider is dead.\n OFFLINE: 0, // The sync provider hasnt yet become online, or it has been disconnected.\n CONNECTING: 1, // Trying to connect to server\n ONLINE: 2, // Connected to server and currently in sync with server\n SYNCING: 3, // Syncing with server. For poll pattern, this is every poll call. For react pattern, this is when local changes are being sent to server.\n ERROR_WILL_RETRY: 4 // An error occured such as net down but the sync provider will retry to connect.\n};\n\nSyncable.StatusTexts = {\n \"-1\": \"ERROR\",\n \"0\": \"OFFLINE\",\n \"1\": \"CONNECTING\",\n \"2\": \"ONLINE\",\n \"3\": \"SYNCING\",\n \"4\": \"ERROR_WILL_RETRY\"\n};\n\nSyncable.registeredProtocols = {}; // Map when key is the provider name.\n\nSyncable.registerSyncProtocol = function (name, protocolInstance) {\n /// \n /// Register a syncronization protocol that can syncronize databases with remote servers.\n /// \n /// Provider name\n /// Implementation of ISyncProtocol\n Syncable.registeredProtocols[name] = protocolInstance;\n};\n\n// Register addon in Dexie:\nDexie.Syncable = Syncable;\nDexie.addons.push(Syncable);"],"names":[],"mappings":";;;;;;;;QAsBI,QAAQ,GAAG,KAAK,CAAC,QAAQ;QACzB,OAAO,GAAG,KAAK,CAAC,OAAO;QACvB,YAAY,GAAG,KAAK,CAAC,YAAY;QACjC,UAAU,GAAG,KAAK,CAAC,UAAU;IAElB,SAAS,QAAQ,CAAC,EAAE,EAAE;;;QAGjC,IAAI,WAAW,GAAG,EAAE;;;QAGpB,IAAI,MAAM,GAAG,CAAC;YACV,MAAM,GAAG,CAAC;YACV,MAAM,GAAG,CAAC;;;QAGd,IAAI,QAAQ,GAAG,QAAQ,CAAC,QAAQ;;QAEhC,IAAI,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.min.js b/addons/Dexie.Syncable/dist/dexie-syncable.min.js new file mode 100644 index 000000000..d92c350f4 --- /dev/null +++ b/addons/Dexie.Syncable/dist/dexie-syncable.min.js @@ -0,0 +1,2 @@ +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("dexie"),require("dexie-observable")):"function"==typeof define&&define.amd?define(["dexie","dexie-observable"],n):e.Dexie.Syncable=n(e.Dexie,e.dexieObservable)}(this,function(e,n){"use strict";function t(n){function s(t,o,i,c,s){function p(){return n._localSyncNode&&n._localSyncNode.id===s}function m(t){return n.transaction("rw",n._syncNodes,function(){if(!i)throw new Error("Url cannot be empty");return n._syncNodes.where("url").equalsIgnoreCase(i).first(function(c){function s(n,t){this.nodeID=n,t&&e.extend(this,t)}return s.prototype.save=function(){return e.vip(function(){return c.save()})},c?(c.syncContext=new s(c.id,c.syncContext),c.syncProtocol=o,n._syncNodes.put(c)):(c=new n.observable.SyncNode,c.myRevision=-1,c.appliedRemoteRevision=null,c.remoteBaseRevisions=[],c.type="remote",c.syncProtocol=o,c.url=i,c.syncOptions=t,c.lastHeartBeat=Date.now(),c.dbUploadState=null,r.resolve(function(){return t.initialUpload===!1?n._changes.lastKey(function(e){c.myRevision=e}):void 0}).then(function(){n._syncNodes.add(c).then(function(e){c.syncContext=new s(e),n._syncNodes.put(c)})})),c})})}function N(o){function f(e){o.status!==e&&(o.status=e,o.save(),n.syncable.on.statusChanged.fire(e,i),n.broadcastMessage("syncStatusChanged",{newStatus:e,url:i},!1))}function m(){return a(m,function(){return g(o,function(n,s,a,u){function l(){Object.keys(u).forEach(function(n){e.setByKeyPath(o,n,u[n])}),o.save(),d.then(C)}var d=new r(function(r,u){O=function(e){u(e)},e.asap(function(){function e(e,n){u(e),p()&&(!isNaN(n)&&1/0>n?(setTimeout(function(){p()&&(f(h.SYNCING),m())},n),f(h.ERROR_WILL_RETRY,e),j&&j.disconnect&&j.disconnect(),j=null):N(e))}try{t.sync(o.syncContext,i,c,s,o.appliedRemoteRevision,n,a,S,l,function(e){r(e)},e)}catch(d){e(d,1/0)}})});return d.then(function(){})})},s)}function N(e){w.disconnect(h.ERROR,e)}function R(e){if(0===e.remoteBaseRevisions.length)return{maxClientRevision:1/0,remoteBaseRevision:null};for(var n=e.remoteBaseRevisions.length-1;n>=0;--n)if(e.myRevision>=e.remoteBaseRevisions[n].local)return{maxClientRevision:n===e.remoteBaseRevisions.length-1?1/0:e.remoteBaseRevisions[n+1].local,remoteBaseRevision:e.remoteBaseRevisions[n].remote};return{maxClientRevision:e.remoteBaseRevisions[0].local,remoteBaseRevision:null}}function g(n,t){return _(n,function o(r,i,c,s){return 0===r.length&&"myRevision"in s&&s.myRevision!==n.myRevision?(Object.keys(s).forEach(function(t){e.setByKeyPath(n,t,s[t])}),n.save(),_(n,o)):t(r,i,c,s)})}function _(t,o){function i(e,r,s){var a=!1;return s.until(function(){return r.length===b?(a=!0,!0):void 0}).each(function(n,t){r.push({type:d,table:e.currentTable,key:t.key,obj:t.value}),e.currentKey=t.key}).then(function(){if(a)return E=!0,o(r,null,!0,{dbUploadState:e});if(0===e.tablesToUpload.length){var s=R(t);return c(e.localBaseRevision,b-r.length,s.maxClientRevision,function(e,n,t){return r=r.concat(e),t.dbUploadState=null,o(r,s.remoteBaseRevision,n,t)})}return e.currentTable=e.tablesToUpload.shift(),i(e,r,n.table(e.currentTable).orderBy(":id"))})}function c(e,o,r,i){var c={},s=0,a=!1,f=t.id,h=e;return n.transaction("r",n._changes,function(){var t=r===1/0?n._changes.where("rev").above(e):n._changes.where("rev").between(e,r,!1,!0);t.until(function(){return s===o?(a=!0,!0):void 0}).each(function(e){if(h=e.rev,e.source!==f){var n={type:e.type,table:e.table,key:e.key};e.type===d?n.obj=e.obj:e.type===y&&(n.mods=e.mods);var t=e.table+":"+e.key,o=c[t];if(o){var r=n,i=function(){switch(o.type){case d:switch(r.type){case d:return r;case y:return u(o,r);case v:return r}break;case y:switch(r.type){case d:return r;case y:return l(o,r);case v:return r}break;case v:switch(r.type){case d:return r;case y:return o;case v:return o}}}();c[t]=i}else c[t]=n,++s}})}).then(function(){var e=Object.keys(c).map(function(e){return c[e]});return E=a,i(e,a,{myRevision:h})})}if(t.myRevision>=0){var s=R(t);return c(t.myRevision,b,s.maxClientRevision,function(e,n,t){return o(e,s.remoteBaseRevision,n,t)})}if(null===t.dbUploadState){var a=n.tables.filter(function(e){return e.schema.observable}).map(function(e){return e.name});if(0===a.length)return r.resolve(o([],null,!1,{}));var f={tablesToUpload:a,currentTable:a.shift(),currentKey:null};return n._changes.orderBy("rev").last(function(e){f.localBaseRevision=e&&e.rev||0;var t=n.table(f.currentTable).orderBy(":id");return i(f,[],t)})}if(t.dbUploadState.currentKey){var h=n.table(t.dbUploadState.currentTable).where(":id").above(t.dbUploadState.currentKey);return i(e.deepClone(t.dbUploadState),[],h)}var h=n.table(f.currentTable).orderBy(":id");return i(e.deepClone(t.dbUploadState),[],h)}function S(t,i,c,u){function l(e){return n.transaction("rw",n._uncommittedChanges,function(){e.forEach(function(e){var t={node:o.id,type:e.type,table:e.table,key:e.key};e.obj&&(t.obj=e.obj),e.mods&&(t.mods=e.mods),n._uncommittedChanges.add(t)})}).then(function(){o.appliedRemoteRevision=i,o.save()})}function f(t,i){return n.transaction("rw",n.tables.filter(function(e){return"_changes"===e.name||"_uncommittedChanges"===e.name||e.schema.observable}),function(){function c(e,n){var t=null;if(n>=e.length)return r.resolve(null);for(var o=e[n],i=s.tables[o.table];o&&o.type===d;){var a=!i.schema.primKey.keyPath;t=function(e,n,t){return(t?n.add(e.obj,e.key):n.add(e.obj))["catch"]("ConstraintError",function(o){return t?n.put(e.obj,e.key):n.put(e.obj)})}(o,i,a),o=e[++n],o&&(i=s.tables[o.table])}if(t)return t.then(function(){return n1)for(var t=o.remoteBaseRevisions.length-1;t>0;--t)if(o.myRevision>=o.remoteBaseRevisions[t].local){o.remoteBaseRevisions.splice(0,t);break}o.save()})})}return a(S,function(){return p()?(c?l(t):f(t,i))["catch"](function(e){return N(e),r.reject(e)}):r.reject("Database not open")},s)}function C(e){return p()?(j=e,w.on("disconnect",function(){if(j){if(j.react)try{j.disconnect()}catch(e){}j=null}}),void(e.react?B(e):I(e))):void(e.disconnect&&e.disconnect())}function B(t){function r(){j&&(f(h.SYNCING),s?c=!0:i())}function i(){j&&(c=!1,s=!0,g(o,function(n,r,a,u){j&&(n.length>0?t.react(n,r,a,function(){Object.keys(u).forEach(function(n){e.setByKeyPath(o,n,u[n])}),o.save(),i()}):(s=!1,c?i():f(h.ONLINE)))})["catch"](N))}var c,s;n.on("changes",r),w.on("disconnect",function(){n.on.changes.unsubscribe(r)}),i()}function I(){function n(){g(o,function(r,s,a,u){function l(){Object.keys(u).forEach(function(n){e.setByKeyPath(o,n,u[n])}),o.save()}function d(e){j&&(j=e,a?n():!isNaN(e.again)&&e.again<1/0?(f(h.ONLINE),setTimeout(function(){j&&(f(h.SYNCING),n())},e.again)):w.disconnect(h.OFFLINE))}function y(e,t){!isNaN(t)&&1/0>t?j&&(setTimeout(function(){j&&(f(h.SYNCING),n())},t),f(h.ERROR_WILL_RETRY)):N(e)}t.sync(o.syncContext,i,c,s,o.appliedRemoteRevision,r,a,S,l,d,y)})["catch"](N)}E?n():j&&!isNaN(j.again)&&j.again<1/0&&(f(h.ONLINE),setTimeout(function(){j&&(f(h.SYNCING),n())},j.again))}w.on("disconnect",function(e){isNaN(e)||f(e)});var j;return f(h.CONNECTING),m()}var R=f.filter(function(e){return e.url===i});if(R.length>0)return R[0].connectPromise;var g=m(c).then(function(e){return N(e)}),O=null,_=!1,E=!0,w={url:i,status:h.OFFLINE,connectPromise:g,on:e.events(null,"disconnect"),disconnect:function(e,n){if(!_){w.on.disconnect.fire(e,n);var t=f.indexOf(w);t>=0&&f.splice(t,1),n&&O&&O(n)}_=!0}};return f.push(w),g}function a(t,o,i){function c(){return t.ongoingOperation?t.ongoingOperation=t.ongoingOperation.then(function(){return a(t,o,i)}):t.ongoingOperation=e.ignoreTransaction(function(){return e.vip(function(){return o()})}).then(function(e){return delete t.ongoingOperation,e}),t.ongoingOperation}return i?n._localSyncNode&&i===n._localSyncNode.id?c():r.reject(new Error("Database was closed")):n.isOpen()?c():r.reject(new Error("Database was closed"))}function u(n,t){var o=e.deepClone(n);return Object.keys(t.mods).forEach(function(e){i(o.obj,e,t.mods[e])}),o}function l(n,t){var o=e.deepClone(n);return Object.keys(t.mods).forEach(function(e){var r=!1;Object.keys(n.mods).filter(function(n){return 0===e.indexOf(n+".")}).forEach(function(n){i(o[n],e.substr(n.length+1),t.mods[e]),r=!0}),r||(o.mods[e]=t.mods[e]),Object.keys(n.mods).filter(function(n){return 0===n.indexOf(e+".")}).forEach(function(e){delete o[e]})}),o}var f=[],d=1,y=2,v=3,h=t.Statuses,b=1e3;n.on("message",function(t){e.vip(function(){"connect"===t.type?n.syncable.connect(t.protocolName,t.url,t.options).then(t.resolve,t.reject):"disconnect"===t.type?n.syncable.disconnect(t.url).then(t.resolve,t.reject):"syncStatusChanged"===t.type&&n.syncable.on.statusChanged.fire(t.newStatus,t.url)})}),n.on("cleanup",function(t){t&&n._syncNodes.where("type").equals("remote").and(function(e){return e.status!==h.OFFLINE&&e.status!==h.ERROR}).each(function(t){e.ignoreTransaction(function(){e.vip(function(){n.syncable.connect(t.syncProtocol,t.url,t.syncOptions)})})})}),n.on("ready",function(){return n._localSyncNode&&n._localSyncNode.isMaster?n._syncNodes.where("type").equals("remote").and(function(e){return e.status!==h.OFFLINE&&e.status!==h.ERROR}).toArray(function(e){return e.length>0?r.all(e.map(function(e){return n.syncable.connect(e.syncProtocol,e.url,e.syncOptions)["catch"](function(e){})})):void 0}):void 0},!0),n.syncable={},n.syncable.getStatus=function(o,i){return n.isOpen()?e.vip(function(){return n._syncNodes.where("url").equals(o).first(function(e){return e?e.status:h.OFFLINE})}).then(i):r.resolve(t.Statuses.OFFLINE).then(i)},n.syncable.list=function(){return n._syncNodes.where("type").equals("remote").toArray(function(e){return e.map(function(e){return e.url})})},n.syncable.on=e.events(n,{statusChanged:"asap"}),n.syncable.disconnect=function(e){return n._localSyncNode&&n._localSyncNode.isMaster?f.filter(function(n){return n.url===e}).forEach(function(e){e.disconnect(h.OFFLINE)}):n._syncNodes.where("isMaster").above(0).first(function(t){n.sendMessage("disconnect",{url:e},t.id,{wantReply:!0})}),n._syncNodes.where("url").equals(e).modify(function(e){e.status=h.OFFLINE})},n.syncable.connect=function(o,i,c){c=c||{};var a=t.registeredProtocols[o];if(a)return n.isOpen()&&n._localSyncNode?n._localSyncNode.isMaster?s(a,o,i,c,n._localSyncNode.id):(n.table("_syncNodes").where("isMaster").above(0).first(function(e){return n.sendMessage("connect",{protocolName:o,url:i,options:c},e.id,{wantReply:!0})}),r.resolve()):new r(function(t,r){n.on("ready",function(){return e.vip(function(){return n.syncable.connect(o,i,c).then(t)["catch"](function(e){r(e)})})})});throw new Error("ISyncProtocol '"+o+"' is not registered in Dexie.Syncable.registerSyncProtocol()")},n.syncable["delete"]=function(e){return n.transaction("rw",n._syncNodes,n._changes,n._uncommittedChanges,function(){n._syncNodes.where("url").equals(e).toArray(function(e){if(e.length>0){var t=e.map(function(e){return e.id});return n._syncNodes.where("id").anyOf(t)["delete"]().then(function(){return c.deleteOldChanges(),n._uncommittedChanges.where("node").anyOf(t)["delete"]()})}})})},n.syncable.unsyncedChanges=function(e){return n._syncNodes.where("url").equals(e).first(function(e){return n._changes.where("rev").above(e.myRevision).toArray()})},n.close=o(n.close,function(e){return function(){return f.forEach(function(e){e.disconnect()}),e.apply(this,arguments)}});n.observable.SyncNode.prototype.save=function(){var e=this;return n.transaction("rw?",n._syncNodes,function(){n._syncNodes.put(e)})}}e="default"in e?e["default"]:e;var o=e.override,r=e.Promise,i=e.setByKeyPath,c=e.Observable;return t.Statuses={ERROR:-1,OFFLINE:0,CONNECTING:1,ONLINE:2,SYNCING:3,ERROR_WILL_RETRY:4},t.StatusTexts={"-1":"ERROR",0:"OFFLINE",1:"CONNECTING",2:"ONLINE",3:"SYNCING",4:"ERROR_WILL_RETRY"},t.registeredProtocols={},t.registerSyncProtocol=function(e,n){t.registeredProtocols[e]=n},e.Syncable=t,e.addons.push(t),t}); +//# sourceMappingURL=dist/dexie-syncable.min.js.map \ No newline at end of file diff --git a/addons/Dexie.Syncable/dist/dexie-syncable.min.js.map b/addons/Dexie.Syncable/dist/dexie-syncable.min.js.map new file mode 100644 index 000000000..1cb1479d9 --- /dev/null +++ b/addons/Dexie.Syncable/dist/dexie-syncable.min.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../C:/repos/dexie-release/addons/Dexie.Syncable/tools/tmp/src/Dexie.Syncable.js"],"names":["Syncable","db","connect","protocolInstance","protocolName","url","options","dbAliveID","stillAlive","_localSyncNode","id","getOrCreateSyncNode","transaction","_syncNodes","Error","where","equalsIgnoreCase","first","node","PersistedContext","nodeID","otherProps","this","Dexie","extend","prototype","save","vip","syncContext","syncProtocol","put","observable","SyncNode","myRevision","appliedRemoteRevision","remoteBaseRevisions","type","syncOptions","lastHeartBeat","Date","now","dbUploadState","Promise","resolve","initialUpload","_changes","lastKey","currentRevision","then","add","nodeId","connectProtocol","changeStatusTo","newStatus","status","syncable","on","statusChanged","fire","broadcastMessage","doSync","enque","getLocalChangesForNode_autoAckIfEmpty","changes","remoteBaseRevision","partial","nodeModificationsOnAck","onChangesAccepted","Object","keys","forEach","keyPath","setByKeyPath","finalSyncPromise","continueSendingChanges","reject","rejectConnectPromise","err","asap","onError","error","again","isNaN","Infinity","setTimeout","Statuses","SYNCING","ERROR_WILL_RETRY","connectedContinuation","disconnect","abortTheProvider","sync","applyRemoteChanges","continuation","ex","activePeer","ERROR","getBaseRevisionAndMaxClientRevision","length","maxClientRevision","i","local","remote","cb","getLocalChangesForNode","autoAck","getTableObjectsAsChanges","state","collection","limitReached","until","MAX_CHANGES_PER_CHUNK","each","item","cursor","push","CREATE","table","currentTable","key","obj","value","currentKey","hasMoreToGive","tablesToUpload","brmcr","getChangesSinceRevision","localBaseRevision","additionalChanges","concat","shift","orderBy","revision","maxChanges","maxRevision","changeSet","numChanges","ignoreSource","nextRevision","query","above","between","change","rev","source","changeToSend","UPDATE","mods","prevChange","nextChange","mergedChange","combineCreateAndUpdate","DELETE","combineUpdateAndUpdate","map","tables","filter","schema","name","last","lastChange","deepClone","remoteChanges","remoteRevision","clear","saveToUncommitedChanges","_uncommittedChanges","changeToAdd","finallyCommitAllChanges","applyChanges","offset","lastCreatePromise","trans","specifyKey","primKey","e","update","currentTransaction","localRevisionBeforeChanges","equals","toArray","uncommittedChanges","currentLocalRevision","splice","react","continueUsingReactPattern","continueUsingPollPattern","onChanges","isWaitingForServer","changesWaiting","reactToChanges","ONLINE","unsubscribe","syncAgain","onSuccess","OFFLINE","CONNECTING","existingPeer","activePeers","peer","connectPromise","disconnected","events","pos","indexOf","context","fn","instanceID","_enque","ongoingOperation","ignoreTransaction","res","isOpen","clonedChange","hadParentPath","parentPath","substr","subPath","msg","weBecameMaster","and","connectedRemoteNode","isMaster","connectedRemoteNodes","all","getStatus","list","a","masterNode","sendMessage","wantReply","modify","registeredProtocols","nodes","nodeIDs","anyOf","Observable","deleteOldChanges","unsyncedChanges","close","override","origClose","apply","arguments","self","StatusTexts","-1","0","1","2","3","4","registerSyncProtocol","addons"],"mappings":"8RA2Be,SAASA,GAASC,GA2L7B,QAASC,GAAQC,EAAkBC,EAAcC,EAAKC,EAASC,GAqC3D,QAASC,KAGL,MAAOP,GAAGQ,gBAAkBR,EAAGQ,eAAeC,KAAOH,EAGzD,QAASI,GAAoBL,GACzB,MAAOL,GAAGW,YAAY,KAAMX,EAAGY,WAAY,WACvC,IAAKR,EAAK,KAAM,IAAIS,OAAM,sBAG1B,OAAOb,GAAGY,WAAWE,MAAM,OAAOC,iBAAiBX,GAAKY,MAAM,SAAUC,GAIpE,QAASC,GAAiBC,EAAQC,GAC9BC,KAAKF,OAASA,EACVC,GAAYE,EAAMC,OAAOF,KAAMD,GAwCvC,MArCAF,GAAiBM,UAAUC,KAAO,WAE9B,MAAOH,GAAMI,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,MAAM,OAAOoK,OAAO9K,GAAKY,MAAM,SAAUC,GAC1D,MAAOjB,GAAG4C,SAAS9B,MAAM,OAAO6H,MAAM1H,EAAKe,YAAYmJ,aA+qB/DnL,EAAG8O,MAAQC,EAAS/O,EAAG8O,MAAO,SAAUE,GACpC,MAAO,YAIH,MAHA3C,GAAYhI,QAAQ,SAAUiI,GAC1BA,EAAK9G,eAEFwJ,EAAUC,MAAM5N,KAAM6N,aAKrClP,GAAG8B,WAAWC,SAASP,UAAUC,KAAO,WACpC,GAAI0N,GAAO9N,IACX,OAAOrB,GAAGW,YAAY,MAAOX,EAAGY,WAAY,WACxCZ,EAAGY,WAAWiB,IAAIsN,wCAx3B1BJ,GAAWzN,EAAMyN,SACjBtM,EAAUnB,EAAMmB,QAChB8B,EAAejD,EAAMiD,aACrBoK,EAAarN,EAAMqN,iBA87BvB5O,GAASqF,UACLW,MAAO,GACPmG,QAAS,EACTC,WAAY,EACZL,OAAQ,EACRzG,QAAS,EACTC,iBAAkB,GAGtBvF,EAASqP,aACLC,KAAM,QACNC,EAAK,UACLC,EAAK,aACLC,EAAK,SACLC,EAAK,UACLC,EAAK,oBAGT3P,EAASwO,uBAETxO,EAAS4P,qBAAuB,SAAU9F,EAAM3J,GAM5CH,EAASwO,oBAAoB1E,GAAQ3J,GAIzCoB,EAAMvB,SAAWA,EACjBuB,EAAMsO,OAAO1I,KAAKnH","file":"dist/dexie-syncable.min.js.map"} \ No newline at end of file diff --git a/bower.json b/bower.json index 6dbc9422e..2e7342f10 100644 --- a/bower.json +++ b/bower.json @@ -24,5 +24,6 @@ "addons/*/bower.json", "samples/", "*.njsproj" - ] + ], + "version": "1.3.6-beta.1" } diff --git a/dist/README.md b/dist/README.md deleted file mode 100644 index d28890585..000000000 --- a/dist/README.md +++ /dev/null @@ -1,51 +0,0 @@ -## Can't find dexie.js? -Dexie's dist files are no longer checked in to github except temporarily when tagging -a release version (just so that bower will continue to work). The reason for this is because -checking in dist files bloats the commit history and makes it error prone to contribute to the -repo. To support bower though, we have to continue checking in dist files when releasing, -but that is now handled by the release.sh script, who also removes them directly afterwards. - -If you still just want to download dexie.js to include in a test HTML page, go -to the following download site: - -### Download -[dexie.min.js](https://npmcdn.com/dexie/dist/dexie.min.js) - -[dexie.min.js.map](https://npmcdn.com/dexie/dist/dexie.min.js.map) - -### Typings -[dexie.d.ts](https://npmcdn.com/dexie/dist/dexie.d.ts) - -### Optional Stuff -[dexie.js (non-minified version)](https://npmcdn.com/dexie/dist/dexie.js) - -[dexie.js.map](https://npmcdn.com/dexie/dist/dexie.js.map) - -[dexie.min.js.gz (Minified and gzipped)](https://npmcdn.com/dexie/dist/dexie.min.js.gz) - -## Install from NPM -``` -npm install dexie --save -``` - -## Install from bower -``` -bower install dexie --save -``` - -## How to build -1. cd to dexie package -2. npm install -3. npm run build - -## Contributing to Dexie.js? - -Watch: -``` -npm run watch -``` - -Test: -``` -npm test -``` diff --git a/dist/dexie.d.ts b/dist/dexie.d.ts new file mode 100644 index 000000000..e1a5a645d --- /dev/null +++ b/dist/dexie.d.ts @@ -0,0 +1,440 @@ +// Type definitions for Dexie v1.3.6-beta.1 +// Project: https://github.com/dfahlander/Dexie.js +// Definitions by: David Fahlander +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Thenable { + then(onFulfilled: (value: R) => Thenable, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled: (value: R) => Thenable, onRejected?: (error: any) => U): Thenable; + then(onFulfilled: (value: R) => U, onRejected: (error: any) => Thenable): Thenable; + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Thenable; +} + +declare type IndexableType = string | number | Date | Array; + +declare class Dexie { + constructor(databaseName: string, options?: { + addons?: Array<(db: Dexie) => void>, + autoOpen?: boolean + }); + + name: string; + tables: Dexie.Table[]; + verno: number; + + static addons: Array<(db: Dexie) => void>; + static version: number; + static semVer: string; + static currentTransaction: Dexie.Transaction; + + static getDatabaseNames(): Dexie.Promise>; + + static getDatabaseNames(onFulfilled: (value: Array) => Thenable): Dexie.Promise; + + static getDatabaseNames(onFulfilled: (value: Array) => U): Dexie.Promise; + + static override (origFunc:F, overridedFactory: (fn:any)=>any) : F; + + static getByKeyPath(obj: Object, keyPath: string): any; + + static setByKeyPath(obj: Object, keyPath: string, value: any): void; + + static delByKeyPath(obj: Object, keyPath: string): void; + + static shallowClone (obj: T): T; + + static deepClone(obj: T): T; + + static asap(fn: Function) : void; + + static maxKey: Array; + + static dependencies: { + indexedDB: IDBFactory, + IDBKeyRange: IDBKeyRange, + localStorage?: Storage + }; + + static default: Dexie; + + version(versionNumber: Number): Dexie.Version; + + on: { + (eventName: string, subscriber: Function, ...args : any[]): void; + (eventName: 'ready', subscriber: () => any, bSticky: boolean): void; + (eventName: 'error', subscriber: (error: any) => any): void; + (eventName: 'populate', subscriber: () => any): void; + (eventName: 'blocked', subscriber: () => any): void; + (eventName: 'versionchange', subscriber: (event: IDBVersionChangeEvent) => any): void; + ready: Dexie.DexieOnReadyEvent; + error: Dexie.DexieErrorEvent; + populate: Dexie.DexieEvent; + blocked: Dexie.DexieEvent; + versionchange: Dexie.DexieVersionChangeEvent; + } + + open(): Dexie.Promise; + + table(tableName: string): Dexie.Table; + + table(tableName: string): Dexie.Table; + + table(tableName: string): Dexie.Table; + + transaction(mode: string, table: Dexie.Table, scope: () => Thenable): Dexie.Promise; + + transaction(mode: string, table: Dexie.Table, table2: Dexie.Table, scope: () => Thenable): Dexie.Promise; + + transaction(mode: string, table: Dexie.Table, table2: Dexie.Table, table3: Dexie.Table, scope: () => Thenable): Dexie.Promise; + + transaction(mode: string, tables: Dexie.Table[], scope: () => Thenable): Dexie.Promise; + + transaction(mode: string, table: Dexie.Table, scope: () => U): Dexie.Promise; + + transaction(mode: string, table: Dexie.Table, table2: Dexie.Table, scope: () => U): Dexie.Promise; + + transaction(mode: string, table: Dexie.Table, table2: Dexie.Table, table3: Dexie.Table, scope: () => U): Dexie.Promise; + + transaction(mode: string, tables: Dexie.Table[], scope: () => U): Dexie.Promise; + + close(): void; + + delete(): Dexie.Promise; + + exists(name : string) : Dexie.Promise; + + isOpen(): boolean; + + hasFailed(): boolean; + + backendDB(): IDBDatabase; + + vip(scopeFunction: () => U): U; + + // Make it possible to touch physical class constructors where they reside - as properties on db instance. + // For example, checking if (x instanceof db.Table). Can't do (x instanceof Dexie.Table because it's just a virtual interface) + Table : new()=>Dexie.Table; + WhereClause: new()=>Dexie.WhereClause; + Version: new()=>Dexie.Version; + WriteableTable: new()=>Dexie.Table; + Transaction: new()=>Dexie.Transaction; + Collection: new()=>Dexie.Collection; + WriteableCollection: new()=>Dexie.Collection; +} + +declare module Dexie { + + class Promise implements Thenable { + constructor(callback: (resolve: (value?: Thenable) => void, reject: (error?: any) => void) => void); + + constructor(callback: (resolve: (value?: R) => void, reject: (error?: any) => void) => void); + + then(onFulfilled: (value: R) => Thenable, onRejected: (error: any) => Thenable): Promise; + + then(onFulfilled: (value: R) => Thenable, onRejected?: (error: any) => U): Promise; + + then(onFulfilled: (value: R) => U, onRejected: (error: any) => Thenable): Promise; + + then(onFulfilled?: (value: R) => U, onRejected?: (error: any) => U): Promise; + + catch(onRejected: (error: any) => Thenable): Promise; + + catch(onRejected: (error: any) => U): Promise; + + catch(ExceptionType: (new() => ET), onRejected: (error: ET) => Promise): Promise; + + catch(ExceptionType: (new() => ET), onRejected: (error: ET) => U): Promise; + + catch(errorName: string, onRejected: (error: {name: string}) => Promise): Promise; + + catch(errorName: string, onRejected: (error: {name: string}) => U): Promise; + + finally(onFinally: () => any): Promise; + + onuncatched: () => any; + } + + module Promise { + function resolve(value?: Thenable): Promise; + + function resolve(value?: R): Promise; + + function reject(error: any): Promise; + + function all(promises: Thenable[]): Promise; + + function all(...promises: Thenable[]): Promise; + + function race(promises: Thenable[]): Promise; + + function newPSD(scope: () => R): R; + + var PSD: any; + + var on: { + (eventName: string, subscriber: Function): void; + (eventName: 'error', subscriber: (error: any) => any): void; + error: DexieErrorEvent; + } + } + + + interface Version { + stores(schema: { [key: string]: string }): Version; + upgrade(fn: (trans: Transaction) => void): Version; + } + + interface Transaction { + active: boolean; + db: Dexie; + mode: string; + idbtrans: IDBTransaction; + tables: { [type: string]: Table }; + storeNames: Array; + on: { + (eventName: string, subscriber: () => any): void; + (eventName: 'complete', subscriber: () => any): void; + (eventName: 'abort', subscriber: () => any): void; + (eventName: 'error', subscriber: (error:any) => any): void; + complete: DexieEvent; + abort: DexieEvent; + error: DexieEvent; + } + abort(): void; + table(tableName: string): Table; + table(tableName: string): Table; + table(tableName: string): Table; + } + + interface DexieEvent { + subscribe(fn: () => any): void; + unsubscribe(fn: () => any): void; + fire(): any; + } + + interface DexieErrorEvent { + subscribe(fn: (error: any) => any): void; + unsubscribe(fn: (error: any) => any): void; + fire(error: any): any; + } + + interface DexieVersionChangeEvent { + subscribe(fn: (event: IDBVersionChangeEvent) => any): void; + unsubscribe(fn: (event: IDBVersionChangeEvent) => any): void; + fire(event: IDBVersionChangeEvent): any; + } + + interface DexieOnReadyEvent { + subscribe(fn: () => any, bSticky: boolean): void; + unsubscribe(fn: () => any): void; + fire(): any; + } + + interface Table { + name: string; + schema: TableSchema; + hook: { + (eventName: string, subscriber: () => any): void; + creating: DexieEvent; + reading: DexieEvent; + updating: DexieEvent; + deleting: DexieEvent; + } + + get(key: Key): Promise; + where(index: string): WhereClause; + + filter(fn: (obj: T) => boolean): Collection; + + count(): Promise; + count(onFulfilled: (value: number) => Thenable): Promise; + count(onFulfilled: (value: number) => U): Promise; + + offset(n: number): Collection; + + limit(n: number): Collection; + + each(callback: (obj: T, cursor: IDBCursor) => any): Promise; + + toArray(): Promise>; + toArray(onFulfilled: (value: Array) => Thenable): Promise; + toArray(onFulfilled: (value: Array) => U): Promise; + + toCollection(): Collection; + orderBy(index: string): Collection; + reverse(): Collection; + mapToClass(constructor: Function): Function; + add(item: T, key?: Key): Promise; + update(key: Key, changes: { [keyPath: string]: any }): Promise; + put(item: T, key?: Key): Promise; + delete(key: Key): Promise; + clear(): Promise; + bulkAdd(items: T[], keys?: IndexableType[]): Promise; + bulkPut(items: T[], keys?: IndexableType[]): Promise; + bulkDelete(keys: IndexableType[]) : Promise; + } + + interface WhereClause { + above(key: IndexableType): Collection; + aboveOrEqual(key: IndexableType): Collection; + anyOf(keys: IndexableType[]): Collection; + anyOf(...keys: IndexableType[]): Collection; + anyOfIgnoreCase(keys: string[]): Collection; + anyOfIgnoreCase(...keys: string[]): Collection; + below(key: IndexableType): Collection; + belowOrEqual(key: IndexableType): Collection; + between(lower: IndexableType, upper: IndexableType, includeLower?: boolean, includeUpper?: boolean): Collection; + equals(key: IndexableType): Collection; + equalsIgnoreCase(key: string): Collection; + inAnyRange(ranges: Array): Collection; + startsWith(key: string): Collection; + startsWithAnyOf(prefixes: string[]): Collection; + startsWithAnyOf(...prefixes: string[]): Collection; + startsWithIgnoreCase(key: string): Collection; + startsWithAnyOfIgnoreCase(prefixes: string[]): Collection; + startsWithAnyOfIgnoreCase(...prefixes: string[]): Collection; + noneOf(keys: Array): Collection; + notEqual(key: IndexableType): Collection; + } + + interface Collection { + and(filter: (x: T) => boolean): Collection; + clone(props?: Object): Collection; + count(): Promise; + count(onFulfilled: (value: number) => Thenable): Promise; + count(onFulfilled: (value: number) => U): Promise; + distinct(): Collection; + each(callback: (obj: T, cursor: IDBCursor) => any): Promise; + eachKey(callback: (key: Key, cursor: IDBCursor) => any): Promise; + eachUniqueKey(callback: (key: Key, cursor: IDBCursor) => any): Promise; + first(): Promise; + first(onFulfilled: (value: T) => Thenable): Promise; + first(onFulfilled: (value: T) => U): Promise; + keys(): Promise; + keys(onFulfilled: (value: Key[]) => Thenable): Promise; + keys(onFulfilled: (value: Key[]) => U): Promise; + last(): Promise; + last(onFulfilled: (value: T) => Thenable): Promise; + last(onFulfilled: (value: T) => U): Promise; + limit(n: number): Collection; + offset(n: number): Collection; + or(indexOrPrimayKey: string): WhereClause; + raw(): Collection; + reverse(): Collection; + sortBy(keyPath: string): Promise; + sortBy(keyPath: string, onFulfilled: (value: T[]) => Thenable): Promise; + sortBy(keyPath: string, onFulfilled: (value: T[]) => U): Promise; + toArray(): Promise>; + toArray(onFulfilled: (value: Array) => Thenable): Promise; + toArray(onFulfilled: (value: Array) => U): Promise; + uniqueKeys(): Promise; + uniqueKeys(onFulfilled: (value: Key[]) => Thenable): Promise; + uniqueKeys(onFulfilled: (value: Key[]) => U): Promise; + until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection; + // WriteableCollection: + delete(): Promise; + modify(changeCallback: (obj: T, ctx:{value: T}) => void): Promise; + modify(changes: { [keyPath: string]: any } ): Promise; + } + + interface TableSchema { + name: string; + primKey: IndexSpec; + indexes: IndexSpec[]; + mappedClass: Function; + } + + interface IndexSpec { + name: string; + keyPath: string | Array; + unique: boolean; + multi: boolean; + auto: boolean; + compound: boolean; + src: string; + } + + // Make it possible to touch physical classes as they are + var TableSchema: new()=>TableSchema, + IndexSpec: new()=>IndexSpec, + Events: any; // Too complex to define correctly right now. + + // errnames - handy spellcheck in switch (error.name) {} cases. + var errnames: { + // Error names generated by indexedDB: + Unknown: 'UnknownError'; + Constraint: 'ConstraintError'; + Data: 'DataError'; + TransactionInactive: 'TransactionInactiveError'; + ReadOnly: 'ReadOnlyError'; + Version: 'VersionError'; + NotFound: 'NotFoundError'; + InvalidState: 'InvalidStateError'; + InvalidAccess: 'InvalidAccessError'; + Abort: 'AbortError'; + Timeout: 'TimeoutError'; + QuotaExceeded: 'QuotaExceededError'; + Syntax: 'SyntaxError'; + DataClone: 'DataCloneError'; + + // Dexie-specific error names: + Modify: 'ModifyError'; + OpenFailed: 'OpenFailedError'; + VersionChange: 'VersionChangeError'; + Schema: 'SchemaError'; + Upgrade: 'UpgradeError'; + InvalidTable: 'InvalidTableError'; + MissingAPI: 'MissingAPIError'; + NoSuchDatabase: 'NoSuchDatabaseError'; + InvalidArgument: 'InvalidArgumentError'; + SubTransaction: 'Error'; + Unsupported: 'UnsupportedError'; + Internal: 'InternalError'; + DatabaseClosed: 'DatabaseClosedError'; + }; + + class DexieError extends Error { + name: string; + message: string; + stack: string; + inner: any; + constructor (name?:string, message?:string); + toString(): string; + } + + class ModifyError extends DexieError{ + constructor (msg?:string, failures?: any[], successCount?: number, failedKeys?: IndexableType[]); + failures: Array; + failedKeys: Array; + successCount: number; + } + + class OpenFailedError extends DexieError {constructor (msg?: string, inner?: Object);constructor (inner: Object);} + class VersionChangeError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class SchemaError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class UpgradeError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class InvalidTableError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class MissingAPIError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class NoSuchDatabaseError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class InvalidArgumentError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class SubTransactionError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class UnsupportedError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class InternalError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class DatabaseClosedError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class UnknownError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class ConstraintError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class DataError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class TransactionInactiveError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class ReadOnlyError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class VersionError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class NotFoundError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class InvalidStateError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class InvalidAccessError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class AbortError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class TimeoutError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class QuotaExceededError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class SyntaxError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} + class DataCloneError extends DexieError {constructor (msg?: string, inner?: Object); constructor (inner: Object);} +} + +export default Dexie; diff --git a/dist/dexie.js b/dist/dexie.js new file mode 100644 index 000000000..82d8bdf4e --- /dev/null +++ b/dist/dexie.js @@ -0,0 +1,4157 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + global.Dexie = factory(); +}(this, function () { 'use strict'; + + var keys = Object.keys; + var isArray = Array.isArray; + var _global = typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : global; + + function extend(obj, extension) { + if (typeof extension !== 'object') extension = extension(); // Allow to supply a function returning the extension. Useful for simplifying private scopes. + keys(extension).forEach(function (key) { + obj[key] = extension[key]; + }); + return obj; + } + + function derive(Child) { + return { + from: function (Parent) { + Child.prototype = Object.create(Parent.prototype); + Child.prototype.constructor = Child; + return { + extend: function (extension) { + extend(Child.prototype, typeof extension !== 'object' ? extension(Parent.prototype) : extension); + } + }; + } + }; + } + + var _slice = [].slice; + function slice(args, start, end) { + return _slice.call(args, start, end); + } + + function override(origFunc, overridedFactory) { + return overridedFactory(origFunc); + } + + function doFakeAutoComplete(fn) { + var to = setTimeout(fn, 1000); + clearTimeout(to); + } + + function assert(b) { + if (!b) throw new exceptions.Internal("Assertion failed"); + } + + function asap(fn) { + if (_global.setImmediate) setImmediate(fn);else setTimeout(fn, 0); + } + + function miniTryCatch(fn, onerror) { + try { + fn(); + } catch (ex) { + onerror && onerror(ex); + } + } + + function fail(err) { + // Get the call stack and return a rejected promise. + try { + throw err; + } catch (e) { + return Promise.reject(err); + } + } + + function getByKeyPath(obj, keyPath) { + // http://www.w3.org/TR/IndexedDB/#steps-for-extracting-a-key-from-a-value-using-a-key-path + if (obj.hasOwnProperty(keyPath)) return obj[keyPath]; // This line is moved from last to first for optimization purpose. + if (!keyPath) return obj; + if (typeof keyPath !== 'string') { + var rv = []; + for (var i = 0, l = keyPath.length; i < l; ++i) { + var val = getByKeyPath(obj, keyPath[i]); + rv.push(val); + } + return rv; + } + var period = keyPath.indexOf('.'); + if (period !== -1) { + var innerObj = obj[keyPath.substr(0, period)]; + return innerObj === undefined ? undefined : getByKeyPath(innerObj, keyPath.substr(period + 1)); + } + return undefined; + } + + function setByKeyPath(obj, keyPath, value) { + if (!obj || keyPath === undefined) return; + if ('isFrozen' in Object && Object.isFrozen(obj)) return; + if (typeof keyPath !== 'string' && 'length' in keyPath) { + assert(typeof value !== 'string' && 'length' in value); + for (var i = 0, l = keyPath.length; i < l; ++i) { + setByKeyPath(obj, keyPath[i], value[i]); + } + } else { + var period = keyPath.indexOf('.'); + if (period !== -1) { + var currentKeyPath = keyPath.substr(0, period); + var remainingKeyPath = keyPath.substr(period + 1); + if (remainingKeyPath === "") { + if (value === undefined) delete obj[currentKeyPath];else obj[currentKeyPath] = value; + } else { + var innerObj = obj[currentKeyPath]; + if (!innerObj) innerObj = obj[currentKeyPath] = {}; + setByKeyPath(innerObj, remainingKeyPath, value); + } + } else { + if (value === undefined) delete obj[keyPath];else obj[keyPath] = value; + } + } + } + + function delByKeyPath(obj, keyPath) { + if (typeof keyPath === 'string') setByKeyPath(obj, keyPath, undefined);else if ('length' in keyPath) [].map.call(keyPath, function (kp) { + setByKeyPath(obj, kp, undefined); + }); + } + + function shallowClone(obj) { + var rv = {}; + for (var m in obj) { + if (obj.hasOwnProperty(m)) rv[m] = obj[m]; + } + return rv; + } + + function deepClone(any) { + if (!any || typeof any !== 'object') return any; + var rv; + if (isArray(any)) { + rv = []; + for (var i = 0, l = any.length; i < l; ++i) { + rv.push(deepClone(any[i])); + } + } else if (any instanceof Date) { + rv = new Date(); + rv.setTime(any.getTime()); + } else { + rv = any.constructor ? Object.create(any.constructor.prototype) : {}; + for (var prop in any) { + if (any.hasOwnProperty(prop)) { + rv[prop] = deepClone(any[prop]); + } + } + } + return rv; + } + + function getObjectDiff(a, b, rv, prfx) { + // This is a simplified version that will always return keypaths on the root level. + // If for example a and b differs by: (a.somePropsObject.x != b.somePropsObject.x), we will return that "somePropsObject" is changed + // and not "somePropsObject.x". This is acceptable and true but could be optimized to support nestled changes if that would give a + // big optimization benefit. + rv = rv || {}; + prfx = prfx || ''; + for (var prop in a) { + if (a.hasOwnProperty(prop)) { + if (!b.hasOwnProperty(prop)) rv[prfx + prop] = undefined; // Property removed + else { + var ap = a[prop], + bp = b[prop]; + if (typeof ap === 'object' && typeof bp === 'object') getObjectDiff(ap, bp, rv, prfx + prop + ".");else if (ap !== bp) rv[prfx + prop] = b[prop]; // Primitive value changed + } + } + }for (var prop in b) { + if (b.hasOwnProperty(prop) && !a.hasOwnProperty(prop)) { + rv[prfx + prop] = b[prop]; // Property added + } + }return rv; + } + + function nop() {} + function mirror(val) { + return val; + } + function pureFunctionChain(f1, f2) { + // Enables chained events that takes ONE argument and returns it to the next function in chain. + // This pattern is used in the hook("reading") event. + if (f1 == null || f1 === mirror) return f2; + return function (val) { + return f2(f1(val)); + }; + } + + function callBoth(on1, on2) { + return function () { + on1.apply(this, arguments); + on2.apply(this, arguments); + }; + } + + function hookCreatingChain(f1, f2) { + // Enables chained events that takes several arguments and may modify first argument by making a modification and then returning the same instance. + // This pattern is used in the hook("creating") event. + if (f1 === nop) return f2; + return function () { + var res = f1.apply(this, arguments); + if (res !== undefined) arguments[0] = res; + var onsuccess = this.onsuccess, + // In case event listener has set this.onsuccess + onerror = this.onerror; // In case event listener has set this.onerror + this.onsuccess = null; + this.onerror = null; + var res2 = f2.apply(this, arguments); + if (onsuccess) this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess; + if (onerror) this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror; + return res2 !== undefined ? res2 : res; + }; + } + + function hookDeletingChain(f1, f2) { + if (f1 === nop) return f2; + return function () { + f1.apply(this, arguments); + var onsuccess = this.onsuccess, + // In case event listener has set this.onsuccess + onerror = this.onerror; // In case event listener has set this.onerror + this.onsuccess = this.onerror = null; + f2.apply(this, arguments); + if (onsuccess) this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess; + if (onerror) this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror; + }; + } + + function hookUpdatingChain(f1, f2) { + if (f1 === nop) return f2; + return function () { + var res = f1.apply(this, arguments); + if (res !== undefined) extend(arguments[0], res); // If f1 returns new modifications, extend caller's modifications with the result before calling next in chain. + var onsuccess = this.onsuccess, + // In case event listener has set this.onsuccess + onerror = this.onerror; // In case event listener has set this.onerror + this.onsuccess = null; + this.onerror = null; + var res2 = f2.apply(this, arguments); + if (onsuccess) this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess; + if (onerror) this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror; + return res === undefined ? res2 === undefined ? undefined : res2 : res2 === undefined ? res : extend(res, res2); + }; + } + + function stoppableEventChain(f1, f2) { + // Enables chained events that may return false to stop the event chain. + if (f1 === nop) return f2; + return function () { + if (f1.apply(this, arguments) === false) return false; + return f2.apply(this, arguments); + }; + } + + function reverseStoppableEventChain(f1, f2) { + if (f1 === nop) return f2; + return function () { + if (f2.apply(this, arguments) === false) return false; + return f1.apply(this, arguments); + }; + } + + function promisableChain(f1, f2) { + if (f1 === nop) return f2; + return function () { + var res = f1.apply(this, arguments); + if (res && typeof res.then === 'function') { + var thiz = this, + args = arguments; + return res.then(function () { + return f2.apply(thiz, args); + }); + } + return f2.apply(this, arguments); + }; + } + + var dexieErrorNames = ['Modify', 'Bulk', 'OpenFailed', 'VersionChange', 'Schema', 'Upgrade', 'InvalidTable', 'MissingAPI', 'NoSuchDatabase', 'InvalidArgument', 'SubTransaction', 'Unsupported', 'Internal', 'DatabaseClosed']; + + var idbDomErrorNames = ['Unknown', 'Constraint', 'Data', 'TransactionInactive', 'ReadOnly', 'Version', 'NotFound', 'InvalidState', 'InvalidAccess', 'Abort', 'Timeout', 'QuotaExceeded', 'Syntax', 'DataClone']; + + var errorList = dexieErrorNames.concat(idbDomErrorNames); + + var defaultTexts = { + VersionChanged: "Database version changed by other database connection", + DatabaseClosed: "Database has been closed" + }; + + // + // DexieError - base class of all out exceptions. + // + function DexieError(name, msg) { + // Reason we don't use ES6 classes is because: + // 1. It bloats transpiled code and increases size of minified code. + // 2. It doesn't give us much in this case. + // 3. It would require sub classes to call super(), which + // is not needed when deriving from Error. + this.name = name; + this.message = msg; + } + derive(DexieError).from(Error); + + function getMultiErrorMessage(msg, failures) { + return msg + ". Errors: " + failures.map(function (f) { + return f.toString(); + }).filter(function (v, i, s) { + return s.indexOf(v) === i; + }) // Only unique error strings + .join('\n'); + } + // + // ModifyError - thrown in WriteableCollection.modify() + // Specific constructor because it contains members failures and failedKeys. + // + function ModifyError(msg, failures, successCount, failedKeys) { + this.name = "ModifyError"; + this.failures = failures; + this.failedKeys = failedKeys; + this.successCount = successCount; + this.message = getMultiErrorMessage(msg, failures); + } + derive(ModifyError).from(DexieError); + + function BulkError(msg, failures) { + this.name = "BulkError"; + this.failures = failures; + this.message = getMultiErrorMessage(msg, failures); + } + derive(BulkError).from(DexieError); + + // + // + // Dynamically generate error names and exception classes based + // on the names in errorList. + // + // + + // Map of {ErrorName -> ErrorName + "Error"} + var errnames = errorList.reduce(function (obj, name) { + return obj[name] = name + "Error", obj; + }, {}); + + // Need an alias for DexieError because we're gonna create subclasses with the same name. + var BaseException = DexieError; + // Map of {ErrorName -> exception constructor} + var exceptions$1 = errorList.reduce(function (obj, name) { + // Let the name be "DexieError" because this name may + // be shown in call stack and when debugging. DexieError is + // the most true name because it derives from DexieError, + // and we cannot change Function.name programatically without + // dynamically create a Function object, which would be considered + // 'eval-evil'. + var fullName = name + "Error"; + function DexieError(msgOrInner, inner) { + this.name = fullName; + if (typeof msgOrInner === 'string') { + this.message = msgOrInner; + this.inner = inner || null; + } else if (typeof msgOrInner === 'object') { + this.message = msgOrInner.name + ' ' + msgOrInner.message; + this.inner = msgOrInner; + } else { + this.message = defaultTexts[name]; + this.inner = null; + } + } + derive(DexieError).from(BaseException); + obj[name] = DexieError; + return obj; + }, {}); + + // Use ECMASCRIPT standard exceptions where applicable: + exceptions$1.Syntax = SyntaxError; + exceptions$1.Type = TypeError; + exceptions$1.Range = RangeError; + + var exceptionMap = idbDomErrorNames.reduce(function (obj, name) { + obj[name + "Error"] = exceptions$1[name]; + return obj; + }, {}); + + function mapError(domError, message) { + var rv = domError; + if (!(domError instanceof DexieError) && domError.name && exceptionMap[domError.name]) { + rv = new exceptionMap[domError.name](message || domError.message, domError); + if (domError.stack) rv.stack = domError.stack; + } + return rv; + } + + function stack(error) { + if (error.stack) return error; + try { + throw new Error(); + } catch (e) { + error.stack = e.stack; + } + return error; + } + + var fullNameExceptions = errorList.reduce(function (obj, name) { + if (["Syntax", "Type", "Range"].indexOf(name) === -1) obj[name + "Error"] = exceptions$1[name]; + return obj; + }, {}); + + fullNameExceptions.ModifyError = ModifyError; + fullNameExceptions.DexieError = DexieError; + fullNameExceptions.BulkError = BulkError; + + function Events(ctx, eventNames) { + var args = arguments; + var evs = {}; + var rv = function (eventName, subscriber) { + if (subscriber) { + // Subscribe + var args = slice(arguments, 1); + var ev = evs[eventName]; + ev.subscribe.apply(ev, args); + return ctx; + } else if (typeof eventName === 'string') { + // Return interface allowing to fire or unsubscribe from event + return evs[eventName]; + } + }; + rv.addEventType = add; + + function add(eventName, chainFunction, defaultFunction) { + if (isArray(eventName)) return addEventGroup(eventName); + if (typeof eventName === 'object') return addConfiguredEvents(eventName); + if (!chainFunction) chainFunction = stoppableEventChain; + if (!defaultFunction) defaultFunction = nop; + + var context = { + subscribers: [], + fire: defaultFunction, + subscribe: function (cb) { + context.subscribers.push(cb); + context.fire = chainFunction(context.fire, cb); + }, + unsubscribe: function (cb) { + context.subscribers = context.subscribers.filter(function (fn) { + return fn !== cb; + }); + context.fire = context.subscribers.reduce(chainFunction, defaultFunction); + } + }; + evs[eventName] = rv[eventName] = context; + return context; + } + + function addConfiguredEvents(cfg) { + // events(this, {reading: [functionChain, nop]}); + keys(cfg).forEach(function (eventName) { + var args = cfg[eventName]; + if (isArray(args)) { + add(eventName, cfg[eventName][0], cfg[eventName][1]); + } else if (args === 'asap') { + // Rather than approaching event subscription using a functional approach, we here do it in a for-loop where subscriber is executed in its own stack + // enabling that any exception that occur wont disturb the initiator and also not nescessary be catched and forgotten. + var context = add(eventName, null, function fire() { + var args = arguments; + context.subscribers.forEach(function (fn) { + asap(function fireEvent() { + fn.apply(_global, args); + }); + }); + }); + context.subscribe = function (fn) { + // Change how subscribe works to not replace the fire function but to just add the subscriber to subscribers + if (context.subscribers.indexOf(fn) === -1) context.subscribers.push(fn); + }; + context.unsubscribe = function (fn) { + // Change how unsubscribe works for the same reason as above. + var idxOfFn = context.subscribers.indexOf(fn); + if (idxOfFn !== -1) context.subscribers.splice(idxOfFn, 1); + }; + } else throw new exceptions$1.InvalidArgument("Invalid event config"); + }); + } + + function addEventGroup(eventGroup) { + // promise-based event group (i.e. we promise to call one and only one of the events in the pair, and to only call it once. + var done = false; + eventGroup.forEach(function (name) { + add(name).subscribe(checkDone); + }); + function checkDone() { + if (done) return false; + done = true; + } + } + + for (var i = 1, l = args.length; i < l; ++i) { + add(args[i]); + } + + return rv; + } + + // + // Promise Class + // + // A variant of promise-light (https://github.com/taylorhakes/promise-light) by https://github.com/taylorhakes - an A+ and ECMASCRIPT 6 compliant Promise implementation. + // + // Modified by David Fahlander to be indexedDB compliant (See discussion: https://github.com/promises-aplus/promises-spec/issues/45) . + // This implementation will not use setTimeout or setImmediate when it's not needed. The behavior is 100% Promise/A+ compliant since + // the caller of new Promise() can be certain that the promise wont be triggered the lines after constructing the promise. We fix this by using the member variable constructing to check + // whether the object is being constructed when reject or resolve is called. If so, the use setTimeout/setImmediate to fulfill the promise, otherwise, we know that it's not needed. + // + // This topic was also discussed in the following thread: https://github.com/promises-aplus/promises-spec/issues/45 and this implementation solves that issue. + // + // Another feature with this Promise implementation is that reject will return false in case no one catched the reject call. This is used + // to stopPropagation() on the IDBRequest error event in case it was catched but not otherwise. + // + // Also, the event new Promise().onuncatched is called in case no one catches a reject call. This is used for us to manually bubble any request + // errors to the transaction. We must not rely on IndexedDB implementation to do this, because it only does so when the source of the rejection + // is an error event on a request, not in case an ordinary exception is thrown. + + var _asap = _global.setImmediate || function (fn) { + var args = slice(arguments, 1); + + // If not FF13 and earlier failed, we could use this call here instead: setTimeout.call(this, [fn, 0].concat(arguments)); + setTimeout(function () { + fn.apply(_global, args); + }, 0); + }; + + doFakeAutoComplete(function () { + // Simplify the job for VS Intellisense. This piece of code is one of the keys to the new marvellous intellisense support in Dexie. + _asap = asap$1 = enqueueImmediate = function (fn) { + var args = arguments;setTimeout(function () { + fn.apply(_global, slice(args, 1)); + }, 0); + }; + }); + + var asap$1 = _asap; + var isRootExecution = true; + var operationsQueue = []; + var tickFinalizers = []; + function enqueueImmediate(fn, args) { + operationsQueue.push([fn, slice(arguments, 1)]); + } + + function executeOperationsQueue() { + var queue = operationsQueue; + operationsQueue = []; + for (var i = 0, l = queue.length; i < l; ++i) { + var item = queue[i]; + item[0].apply(_global, item[1]); + } + } + + function Promise(fn) { + if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new'); + if (typeof fn !== 'function') throw new TypeError('not a function'); + this._state = null; // null (=pending), false (=rejected) or true (=resolved) + this._value = null; // error or result + this._deferreds = []; + this._catched = false; // for onuncatched + //this._id = ++PromiseID; + var self = this; + var constructing = true; + this._PSD = Promise.PSD; + + try { + doResolve(this, fn, function (data) { + if (constructing) asap$1(resolve, self, data);else resolve(self, data); + }, function (reason) { + if (constructing) { + asap$1(reject, self, reason); + return false; + } else { + return reject(self, reason); + } + }); + } finally { + constructing = false; + } + } + + function handle(self, deferred) { + if (self._state === null) { + self._deferreds.push(deferred); + return; + } + + var cb = self._state ? deferred.onFulfilled : deferred.onRejected; + if (cb === null) { + // This Deferred doesnt have a listener for the event being triggered (onFulfilled or onReject) so lets forward the event to any eventual listeners on the Promise instance returned by then() or catch() + return (self._state ? deferred.resolve : deferred.reject)(self._value); + } + var ret, + isRootExec = isRootExecution; + isRootExecution = false; + asap$1 = enqueueImmediate; + try { + var outerPSD = Promise.PSD; + Promise.PSD = self._PSD; + ret = cb(self._value); + if (!self._state && (!ret || typeof ret.then !== 'function' || ret._state !== false)) setCatched(self); // Caller did 'return Promise.reject(err);' - don't regard it as catched! + deferred.resolve(ret); + } catch (e) { + deferred.reject(e); + } finally { + Promise.PSD = outerPSD; + if (isRootExec) { + do { + while (operationsQueue.length > 0) { + executeOperationsQueue(); + }var finalizer = tickFinalizers.pop(); + if (finalizer) try { + finalizer(); + } catch (e) {} + } while (tickFinalizers.length > 0 || operationsQueue.length > 0); + asap$1 = _asap; + isRootExecution = true; + } + } + } + + function _rootExec(fn) { + var isRootExec = isRootExecution; + isRootExecution = false; + asap$1 = enqueueImmediate; + try { + return fn(); + } finally { + if (isRootExec) { + do { + while (operationsQueue.length > 0) { + executeOperationsQueue(); + }var finalizer = tickFinalizers.pop(); + if (finalizer) try { + finalizer(); + } catch (e) {} + } while (tickFinalizers.length > 0 || operationsQueue.length > 0); + asap$1 = _asap; + isRootExecution = true; + } + } + } + + function setCatched(promise) { + promise._catched = true; + if (promise._parent && !promise._parent._catched) setCatched(promise._parent); + } + + function resolve(promise, newValue) { + var outerPSD = Promise.PSD; + Promise.PSD = promise._PSD; + try { + //Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure + if (newValue === promise) throw new TypeError('A promise cannot be resolved with itself.'); + if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) { + if (typeof newValue.then === 'function') { + if (newValue instanceof Promise && newValue._state !== null) { + promise._state = newValue._state; + promise._value = newValue._value; + finale.call(promise); + return; + } + doResolve(promise, function (resolve, reject) { + //newValue instanceof Promise ? newValue._then(resolve, reject) : newValue.then(resolve, reject); + newValue.then(resolve, reject); + }, function (data) { + resolve(promise, data); + }, function (reason) { + reject(promise, reason); + }); + return; + } + } + promise._state = true; + promise._value = newValue; + finale.call(promise); + } catch (e) { + reject(e); + } finally { + Promise.PSD = outerPSD; + } + } + + function reject(promise, newValue) { + var outerPSD = Promise.PSD; + Promise.PSD = promise._PSD; + promise._state = false; + promise._value = newValue; + + finale.call(promise); + if (!promise._catched) { + try { + if (promise.onuncatched) promise.onuncatched(promise._value);else Promise.on.error.fire(promise._value); + } catch (e) {} + } + Promise.PSD = outerPSD; + return promise._catched; + } + + function finale() { + for (var i = 0, len = this._deferreds.length; i < len; i++) { + handle(this, this._deferreds[i]); + } + this._deferreds = []; + } + + function Deferred(onFulfilled, onRejected, resolve, reject) { + this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null; + this.onRejected = typeof onRejected === 'function' ? onRejected : null; + this.resolve = resolve; + this.reject = reject; + } + + /** + * Take a potentially misbehaving resolver function and make sure + * onFulfilled and onRejected are only called once. + * + * Makes no guarantees about asynchrony. + */ + function doResolve(promise, fn, onFulfilled, onRejected) { + var done = false; + try { + fn(function Promise_resolve(value) { + if (done) return; + done = true; + onFulfilled(value); + }, function Promise_reject(reason) { + if (done) return promise._catched; + done = true; + return onRejected(reason); + }); + } catch (ex) { + if (done) return; + return onRejected(ex); + } + } + + Promise.all = function () { + var args = slice(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments); + + return new Promise(function (resolve, reject) { + if (args.length === 0) return resolve([]); + var remaining = args.length; + function res(i, val) { + try { + if (val && (typeof val === 'object' || typeof val === 'function')) { + var then = val.then; + if (typeof then === 'function') { + then.call(val, function (val) { + res(i, val); + }, reject); + return; + } + } + args[i] = val; + if (--remaining === 0) { + resolve(args); + } + } catch (ex) { + reject(ex); + } + } + for (var i = 0; i < args.length; i++) { + res(i, args[i]); + } + }); + }; + + /* Prototype Methods */ + Promise.prototype.then = function (onFulfilled, onRejected) { + var self = this; + var p = new Promise(function (resolve, reject) { + if (self._state === null) handle(self, new Deferred(onFulfilled, onRejected, resolve, reject));else asap$1(handle, self, new Deferred(onFulfilled, onRejected, resolve, reject)); + }); + p._PSD = this._PSD; + p.onuncatched = this.onuncatched; // Needed when exception occurs in a then() clause of a successful parent promise. Want onuncatched to be called even in callbacks of callbacks of the original promise. + p._parent = this; // Used for recursively calling onuncatched event on self and all parents. + return p; + }; + + Promise.prototype._then = function (onFulfilled, onRejected) { + handle(this, new Deferred(onFulfilled, onRejected, nop, nop)); + }; + + Promise.prototype['catch'] = function (onRejected) { + if (arguments.length === 1) return this.then(null, onRejected); + // First argument is the Error type to catch + var type = arguments[0], + callback = arguments[1]; + if (typeof type === 'function') return this.then(null, function (e) { + // Catching errors by its constructor type (similar to java / c++ / c#) + // Sample: promise.catch(TypeError, function (e) { ... }); + if (e instanceof type) return callback(e);else return Promise.reject(e); + });else return this.then(null, function (e) { + // Catching errors by the error.name property. Makes sense for indexedDB where error type + // is always DOMError but where e.name tells the actual error type. + // Sample: promise.catch('ConstraintError', function (e) { ... }); + if (e && e.name === type) return callback(e);else return Promise.reject(e); + }); + }; + + Promise.prototype['finally'] = function (onFinally) { + return this.then(function (value) { + onFinally(); + return value; + }, function (err) { + onFinally(); + return Promise.reject(err); + }); + }; + + Promise.prototype.onuncatched = null; // Optional event triggered if promise is rejected but no one listened. + + Promise.resolve = function (value) { + if (value && typeof value.then === 'function') return value; + var p = new Promise(function () {}); + p._state = true; + p._value = value; + return p; + }; + + Promise.reject = function (value) { + var p = new Promise(function () {}); + p._state = false; + p._value = value; + return p; + }; + + Promise.race = function (values) { + return new Promise(function (resolve, reject) { + values.map(function (value) { + value.then(resolve, reject); + }); + }); + }; + + Promise.PSD = null; // Promise Specific Data - a TLS Pattern (Thread Local Storage) for Promises. TODO: Rename Promise.PSD to Promise.data + + Promise.newPSD = function (fn) { + // Create new PSD scope (Promise Specific Data) + var outerScope = Promise.PSD; + Promise.PSD = outerScope ? Object.create(outerScope) : {}; + try { + return fn(); + } finally { + Promise.PSD = outerScope; + } + }; + + Promise.usePSD = function (psd, fn) { + var outerScope = Promise.PSD; + Promise.PSD = psd; + try { + return fn(); + } finally { + Promise.PSD = outerScope; + } + }; + + Promise._rootExec = _rootExec; + Promise._tickFinalize = function (callback) { + if (isRootExecution) throw new Error("Not in a virtual tick"); + tickFinalizers.push(callback); + }; + + Promise.on = Events(null, { "error": [function (f1, f2) { + return f2; + }, // Only use the most recent handler (only allow one handler at a time). + defaultErrorHandler] // Default to defaultErrorHandler + }); + + // By default, log uncaught errors to the console + function defaultErrorHandler(e) { + console.error('Uncaught Promise: ' + (e.stack || e)); + } + + var maxString = String.fromCharCode(65535); + var maxKey = function () { + try { + IDBKeyRange.only([[]]);return [[]]; + } catch (e) { + return maxString; + } + }(); + var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array."; + var STRING_EXPECTED = "String expected."; + var connections = []; + var isIEOrEdge = typeof navigator !== 'undefined' && /(MSIE|Trident|Edge)/.test(navigator.userAgent); + var hasIEDeleteObjectStoreBug = isIEOrEdge; + var hangsOnDeleteLargeKeyRange = isIEOrEdge; + function Dexie(dbName, options) { + /// Specify only if you wich to control which addons that should run on this instance + var deps = Dexie.dependencies; + var opts = extend({ + // Default Options + addons: Dexie.addons, // Pick statically registered addons by default + autoOpen: true, // Don't require db.open() explicitely. + indexedDB: deps.indexedDB, // Backend IndexedDB api. Default to IDBShim or browser env. + IDBKeyRange: deps.IDBKeyRange // Backend IDBKeyRange api. Default to IDBShim or browser env. + }, options || {}); + var addons = opts.addons, + autoOpen = opts.autoOpen, + indexedDB = opts.indexedDB, + IDBKeyRange = opts.IDBKeyRange; + + var globalSchema = this._dbSchema = {}; + var versions = []; + var dbStoreNames = []; + var allTables = {}; + var notInTransFallbackTables = {}; + /// + var idbdb = null; // Instance of IDBDatabase + var db_is_blocked = true; + var dbOpenError = null; + var isBeingOpened = false; + var READONLY = "readonly", + READWRITE = "readwrite"; + var db = this; + var pausedResumeables = []; + var autoSchema = true; + var hasNativeGetDatabaseNames = !!getNativeGetDatabaseNamesFn(indexedDB); + + function init() { + // Default subscribers to "versionchange" and "blocked". + // Can be overridden by custom handlers. If custom handlers return false, these default + // behaviours will be prevented. + db.on("versionchange", function (ev) { + // Default behavior for versionchange event is to close database connection. + // Caller can override this behavior by doing db.on("versionchange", function(){ return false; }); + // Let's not block the other window from making it's delete() or open() call. + // NOTE! This event is never fired in IE,Edge or Safari. + if (ev.newVersion > 0) console.warn('Another connection wants to upgrade database \'' + db.name + '\'. Closing db now to resume the upgrade.');else console.warn('Another connection wants to delete database \'' + db.name + '\'. Closing db now to resume the delete request.'); + db.close(); + // In many web applications, it would be recommended to force window.reload() + // when this event occurs. To do that, subscribe to the versionchange event + // and call window.location.reload(true) if ev.newVersion > 0 (not a deletion) + // The reason for this is that your current web app obviously has old schema code that needs + // to be updated. Another window got a newer version of the app and needs to upgrade DB but + // your window is blocking it unless we close it here. + }); + db.on("blocked", function (ev) { + if (!ev.newVersion || ev.newVersion < ev.oldVersion) console.warn('Dexie.delete(\'' + db.name + '\') was blocked');else console.warn('Upgrade \'' + db.name + '\' blocked by other connection holding version ' + ev.oldVersion / 10); + }); + } + + // + // + // + // ------------------------- Versioning Framework--------------------------- + // + // + // + + this.version = function (versionNumber) { + /// + /// + if (idbdb || isBeingOpened) throw new exceptions$1.Schema("Cannot add version when database is open"); + this.verno = Math.max(this.verno, versionNumber); + var versionInstance = versions.filter(function (v) { + return v._cfg.version === versionNumber; + })[0]; + if (versionInstance) return versionInstance; + versionInstance = new Version(versionNumber); + versions.push(versionInstance); + versions.sort(lowerVersionFirst); + return versionInstance; + }; + + function Version(versionNumber) { + this._cfg = { + version: versionNumber, + storesSource: null, + dbschema: {}, + tables: {}, + contentUpgrade: null + }; + this.stores({}); // Derive earlier schemas by default. + } + + extend(Version.prototype, { + stores: function (stores) { + /// + /// Defines the schema for a particular version + /// + /// + /// Example:
+ /// {users: "id++,first,last,&username,*email",
+ /// passwords: "id++,&username"}
+ ///
+ /// Syntax: {Table: "[primaryKey][++],[&][*]index1,[&][*]index2,..."}

+ /// Special characters:
+ /// "&" means unique key,
+ /// "*" means value is multiEntry,
+ /// "++" means auto-increment and only applicable for primary key
+ /// + this._cfg.storesSource = this._cfg.storesSource ? extend(this._cfg.storesSource, stores) : stores; + + // Derive stores from earlier versions if they are not explicitely specified as null or a new syntax. + var storesSpec = {}; + versions.forEach(function (version) { + // 'versions' is always sorted by lowest version first. + extend(storesSpec, version._cfg.storesSource); + }); + + var dbschema = this._cfg.dbschema = {}; + this._parseStoresSpec(storesSpec, dbschema); + // Update the latest schema to this version + // Update API + globalSchema = db._dbSchema = dbschema; + removeTablesApi([allTables, db, notInTransFallbackTables]); + setApiOnPlace([notInTransFallbackTables], tableNotInTransaction, keys(dbschema), READWRITE, dbschema); + setApiOnPlace([allTables, db, this._cfg.tables], db._transPromiseFactory, keys(dbschema), READWRITE, dbschema, true); + dbStoreNames = keys(dbschema); + return this; + }, + upgrade: function (upgradeFunction) { + /// Function that performs upgrading actions. + var self = this; + fakeAutoComplete(function () { + upgradeFunction(db._createTransaction(READWRITE, keys(self._cfg.dbschema), self._cfg.dbschema)); // BUGBUG: No code completion for prev version's tables wont appear. + }); + this._cfg.contentUpgrade = upgradeFunction; + return this; + }, + _parseStoresSpec: function (stores, outSchema) { + keys(stores).forEach(function (tableName) { + if (stores[tableName] !== null) { + var instanceTemplate = {}; + var indexes = parseIndexSyntax(stores[tableName]); + var primKey = indexes.shift(); + if (primKey.multi) throw new exceptions$1.Schema("Primary key cannot be multi-valued"); + if (primKey.keyPath) setByKeyPath(instanceTemplate, primKey.keyPath, primKey.auto ? 0 : primKey.keyPath); + indexes.forEach(function (idx) { + if (idx.auto) throw new exceptions$1.Schema("Only primary key can be marked as autoIncrement (++)"); + if (!idx.keyPath) throw new exceptions$1.Schema("Index must have a name and cannot be an empty string"); + setByKeyPath(instanceTemplate, idx.keyPath, idx.compound ? idx.keyPath.map(function () { + return ""; + }) : ""); + }); + outSchema[tableName] = new TableSchema(tableName, primKey, indexes, instanceTemplate); + } + }); + } + }); + + function runUpgraders(oldVersion, idbtrans, reject, openReq) { + if (oldVersion === 0) { + //globalSchema = versions[versions.length - 1]._cfg.dbschema; + // Create tables: + keys(globalSchema).forEach(function (tableName) { + createTable(idbtrans, tableName, globalSchema[tableName].primKey, globalSchema[tableName].indexes); + }); + // Populate data + var t = db._createTransaction(READWRITE, dbStoreNames, globalSchema); + t.idbtrans = idbtrans; + t.idbtrans.onerror = eventRejectHandler(reject, ["populating database"]); + t.on('error').subscribe(reject); + Promise.newPSD(function () { + Promise.PSD.trans = t; + try { + db.on("populate").fire(t); + } catch (err) { + openReq.onerror = idbtrans.onerror = function (ev) { + ev.preventDefault(); + }; // Prohibit AbortError fire on db.on("error") in Firefox. + try { + idbtrans.abort(); + } catch (e) {} + idbtrans.db.close(); + reject(err); + } + }); + } else { + // Upgrade version to version, step-by-step from oldest to newest version. + // Each transaction object will contain the table set that was current in that version (but also not-yet-deleted tables from its previous version) + var queue = []; + var oldVersionStruct = versions.filter(function (version) { + return version._cfg.version === oldVersion; + })[0]; + if (!oldVersionStruct) throw new exceptions$1.Upgrade("Dexie specification of currently installed DB version is missing"); + globalSchema = db._dbSchema = oldVersionStruct._cfg.dbschema; + var anyContentUpgraderHasRun = false; + + var versToRun = versions.filter(function (v) { + return v._cfg.version > oldVersion; + }); + versToRun.forEach(function (version) { + /// + var oldSchema = globalSchema; + var newSchema = version._cfg.dbschema; + adjustToExistingIndexNames(oldSchema, idbtrans); + adjustToExistingIndexNames(newSchema, idbtrans); + globalSchema = db._dbSchema = newSchema; + { + var diff = getSchemaDiff(oldSchema, newSchema); + diff.add.forEach(function (tuple) { + queue.push(function (idbtrans, cb) { + createTable(idbtrans, tuple[0], tuple[1].primKey, tuple[1].indexes); + cb(); + }); + }); + diff.change.forEach(function (change) { + if (change.recreate) { + throw new exceptions$1.Upgrade("Not yet support for changing primary key"); + } else { + queue.push(function (idbtrans, cb) { + var store = idbtrans.objectStore(change.name); + change.add.forEach(function (idx) { + addIndex(store, idx); + }); + change.change.forEach(function (idx) { + store.deleteIndex(idx.name); + addIndex(store, idx); + }); + change.del.forEach(function (idxName) { + store.deleteIndex(idxName); + }); + cb(); + }); + } + }); + if (version._cfg.contentUpgrade) { + queue.push(function (idbtrans, cb) { + anyContentUpgraderHasRun = true; + var t = db._createTransaction(READWRITE, slice(idbtrans.db.objectStoreNames), newSchema); + t.idbtrans = idbtrans; + var uncompletedRequests = 0; + t._promise = override(t._promise, function (orig_promise) { + return function (mode, fn, writeLock) { + ++uncompletedRequests; + function proxy(fn) { + return function () { + fn.apply(this, arguments); + if (--uncompletedRequests === 0) cb(); // A called db operation has completed without starting a new operation. The flow is finished, now run next upgrader. + }; + } + return orig_promise.call(this, mode, function (resolve, reject, trans) { + arguments[0] = proxy(resolve); + arguments[1] = proxy(reject); + fn.apply(this, arguments); + }, writeLock); + }; + }); + idbtrans.onerror = eventRejectHandler(reject, ["running upgrader function for version", version._cfg.version]); + t.on('error').subscribe(reject); + version._cfg.contentUpgrade(t); + if (uncompletedRequests === 0) cb(); // contentUpgrade() didnt call any db operations at all. + }); + } + if (!anyContentUpgraderHasRun || hasIEDeleteObjectStoreBug) { + // Dont delete old tables if ieBug is present and a content upgrader has run. Let tables be left in DB so far. This needs to be taken care of. + queue.push(function (idbtrans, cb) { + // Delete old tables + deleteRemovedTables(newSchema, idbtrans); + cb(); + }); + } + } + }); + + // Now, create a queue execution engine + var runNextQueuedFunction = function () { + try { + if (queue.length) queue.shift()(idbtrans, runNextQueuedFunction);else createMissingTables(globalSchema, idbtrans); // At last, make sure to create any missing tables. (Needed by addons that add stores to DB without specifying version) + } catch (err) { + openReq.onerror = idbtrans.onerror = function (ev) { + ev.preventDefault(); + }; // Prohibit AbortError fire on db.on("error") in Firefox. + try { + idbtrans.abort(); + } catch (e) {} + idbtrans.db.close(); + reject(err); + } + }; + runNextQueuedFunction(); + } + } + + function getSchemaDiff(oldSchema, newSchema) { + var diff = { + del: [], // Array of table names + add: [], // Array of [tableName, newDefinition] + change: [] // Array of {name: tableName, recreate: newDefinition, del: delIndexNames, add: newIndexDefs, change: changedIndexDefs} + }; + for (var table in oldSchema) { + if (!newSchema[table]) diff.del.push(table); + } + for (var table in newSchema) { + var oldDef = oldSchema[table], + newDef = newSchema[table]; + if (!oldDef) diff.add.push([table, newDef]);else { + var change = { + name: table, + def: newSchema[table], + recreate: false, + del: [], + add: [], + change: [] + }; + if (oldDef.primKey.src !== newDef.primKey.src) { + // Primary key has changed. Remove and re-add table. + change.recreate = true; + diff.change.push(change); + } else { + var oldIndexes = oldDef.indexes.reduce(function (prev, current) { + prev[current.name] = current;return prev; + }, {}); + var newIndexes = newDef.indexes.reduce(function (prev, current) { + prev[current.name] = current;return prev; + }, {}); + for (var idxName in oldIndexes) { + if (!newIndexes[idxName]) change.del.push(idxName); + } + for (var idxName in newIndexes) { + var oldIdx = oldIndexes[idxName], + newIdx = newIndexes[idxName]; + if (!oldIdx) change.add.push(newIdx);else if (oldIdx.src !== newIdx.src) change.change.push(newIdx); + } + if (change.recreate || change.del.length > 0 || change.add.length > 0 || change.change.length > 0) { + diff.change.push(change); + } + } + } + } + return diff; + } + + function createTable(idbtrans, tableName, primKey, indexes) { + /// + var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath ? { keyPath: primKey.keyPath, autoIncrement: primKey.auto } : { autoIncrement: primKey.auto }); + indexes.forEach(function (idx) { + addIndex(store, idx); + }); + return store; + } + + function createMissingTables(newSchema, idbtrans) { + keys(newSchema).forEach(function (tableName) { + if (!idbtrans.db.objectStoreNames.contains(tableName)) { + createTable(idbtrans, tableName, newSchema[tableName].primKey, newSchema[tableName].indexes); + } + }); + } + + function deleteRemovedTables(newSchema, idbtrans) { + for (var i = 0; i < idbtrans.db.objectStoreNames.length; ++i) { + var storeName = idbtrans.db.objectStoreNames[i]; + if (newSchema[storeName] === null || newSchema[storeName] === undefined) { + idbtrans.db.deleteObjectStore(storeName); + } + } + } + + function addIndex(store, idx) { + store.createIndex(idx.name, idx.keyPath, { unique: idx.unique, multiEntry: idx.multi }); + } + + function executePausedResumeables() { + pausedResumeables.forEach(function (resumable) { + // Resume all stalled operations. They will fail once they wake up. + resumable.resume(); + }); + } + + // + // + // Dexie Protected API + // + // + + this._allTables = allTables; + + this._tableFactory = function createTable(mode, tableSchema, transactionPromiseFactory) { + /// + if (mode === READONLY) return new Table(tableSchema.name, transactionPromiseFactory, tableSchema, Collection);else return new WriteableTable(tableSchema.name, transactionPromiseFactory, tableSchema); + }; + + this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) { + return new Transaction(mode, storeNames, dbschema, parentTransaction); + }; + + function tableNotInTransaction(mode, storeNames) { + throw new exceptions$1.InvalidTable("Table " + storeNames[0] + " not part of transaction. Original Scope Function Source: " + Dexie.Promise.PSD.trans.scopeFunc.toString()); + } + + this._transPromiseFactory = function transactionPromiseFactory(mode, storeNames, fn) { + // Last argument is "writeLocked". But this doesnt apply to oneshot direct db operations, so we ignore it. + if (db_is_blocked && (!Promise.PSD || !Promise.PSD.letThrough)) { + // Database is paused. Wait til resumed. + if (!isBeingOpened && !autoOpen) { + return fail(new exceptions$1.DatabaseClosed()); + } + var blockedPromise = new Promise(function (resolve, reject) { + pausedResumeables.push({ + resume: function () { + var p = db._transPromiseFactory(mode, storeNames, fn); + blockedPromise.onuncatched = p.onuncatched; + p.then(resolve, reject); + } + }); + }); + if (autoOpen && !isBeingOpened) { + db.open().catch(nop); // catching to get rid of error logging of uncaught Promise. dbOpenError will be returned again as a rejected Promise. + } + return blockedPromise; + } else { + var trans = db._createTransaction(mode, storeNames, globalSchema); + return trans._promise(mode, function (resolve, reject) { + // An uncatched operation will bubble to this anonymous transaction. Make sure + // to continue bubbling it up to db.on('error'): + trans.error(function (err) { + db.on('error').fire(err); + }); + Promise.newPSD(function () { + Promise.PSD.trans = trans; + fn(function (value) { + // Instead of resolving value directly, wait with resolving it until transaction has completed. + // Otherwise the data would not be in the DB if requesting it in the then() operation. + // Specifically, to ensure that the following expression will work: + // + // db.friends.put({name: "Arne"}).then(function () { + // db.friends.where("name").equals("Arne").count(function(count) { + // assert (count === 1); + // }); + // }); + // + trans.complete(function () { + resolve(value); + }); + }, reject, trans); + }); + }); + } + }; + + this._whenReady = function (fn) { + if (!fake && db_is_blocked && (!Promise.PSD || !Promise.PSD.letThrough)) { + if (!isBeingOpened) { + if (autoOpen) { + db.open().catch(nop); // catching to get rid of error logging of uncaught Promise. dbOpenError will be returned again as a rejected Promise. + } else { + return fail(new exceptions$1.DatabaseClosed()); + } + } + return new Promise(function (resolve, reject) { + pausedResumeables.push({ + resume: function () { + fn(resolve, reject); + } + }); + }); + } + return new Promise(fn); + }; + + // + // + // + // + // Dexie API + // + // + // + + this.verno = 0; + + this.open = function () { + if (idbdb) return Promise.resolve(db); + if (isBeingOpened) return new Promise(function (resolve, reject) { + return db._whenReady(function () { + resolve(db); + }, function (e) { + reject(e); + }); + }); + dbOpenError = null; + isBeingOpened = true; + db_is_blocked = true; + return new Promise(function (resolve, reject) { + if (fake) resolve(); + var req, + dbWasCreated = false; + function openError(err) { + try { + req.transaction.abort(); + } catch (e) {} + if (idbdb) try { + idbdb.close(); + } catch (e) {} + idbdb = null; + isBeingOpened = false; + dbOpenError = mapError(err); + db_is_blocked = false; + reject(dbOpenError); + executePausedResumeables(); + } + try { + // Make sure caller has specified at least one version + if (versions.length > 0) autoSchema = false; + + // Multiply db.verno with 10 will be needed to workaround upgrading bug in IE: + // IE fails when deleting objectStore after reading from it. + // A future version of Dexie.js will stopover an intermediate version to workaround this. + // At that point, we want to be backward compatible. Could have been multiplied with 2, but by using 10, it is easier to map the number to the real version number. + if (!indexedDB) throw new exceptions$1.MissingAPI("indexedDB API not found. If using IE10+, make sure to run your code on a server URL " + "(not locally). If using Safari, make sure to include indexedDB polyfill."); + req = autoSchema ? indexedDB.open(dbName) : indexedDB.open(dbName, Math.round(db.verno * 10)); + if (!req) throw new exceptions$1.MissingAPI("IndexedDB API not available"); // May happen in Safari private mode, see https://github.com/dfahlander/Dexie.js/issues/134 + req.onerror = eventRejectHandler(openError, ["opening database", dbName]); + req.onblocked = fireOnBlocked; + req.onupgradeneeded = trycatch(function (e) { + if (autoSchema && !db._allowEmptyDB) { + // Unless an addon has specified db._allowEmptyDB, lets make the call fail. + // Caller did not specify a version or schema. Doing that is only acceptable for opening alread existing databases. + // If onupgradeneeded is called it means database did not exist. Reject the open() promise and make sure that we + // do not create a new database by accident here. + req.onerror = function (event) { + event.preventDefault(); + }; // Prohibit onabort error from firing before we're done! + req.transaction.abort(); // Abort transaction (would hope that this would make DB disappear but it doesnt.) + // Close database and delete it. + req.result.close(); + var delreq = indexedDB.deleteDatabase(dbName); // The upgrade transaction is atomic, and javascript is single threaded - meaning that there is no risk that we delete someone elses database here! + delreq.onsuccess = delreq.onerror = function () { + openError(new exceptions$1.NoSuchDatabase('Database ' + dbName + ' doesnt exist')); + }; + } else { + if (e.oldVersion === 0) dbWasCreated = true; + req.transaction.onerror = eventRejectHandler(openError); + var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion; // Safari 8 fix. + runUpgraders(oldVer / 10, req.transaction, openError, req); + } + }, openError); + req.onsuccess = trycatch(function (e) { + isBeingOpened = false; + idbdb = req.result; + if (autoSchema) readGlobalSchema();else if (idbdb.objectStoreNames.length > 0) { + try { + adjustToExistingIndexNames(globalSchema, idbdb.transaction(safariMultiStoreFix(idbdb.objectStoreNames), READONLY)); + } catch (e) { + // Safari may bail out if > 1 store names. However, this shouldnt be a showstopper. Issue #120. + } + } + + idbdb.onversionchange = function (ev) { + db._vcFired = true; // detect implementations that not support versionchange (IE/Edge/Safari) + db.on("versionchange").fire(ev); + }; + if (!hasNativeGetDatabaseNames) { + // Update localStorage with list of database names + globalDatabaseList(function (databaseNames) { + if (databaseNames.indexOf(dbName) === -1) return databaseNames.push(dbName); + }); + } + // Now, let any subscribers to the on("ready") fire BEFORE any other db operations resume! + // If an the on("ready") subscriber returns a Promise, we will wait til promise completes or rejects before + Promise.newPSD(function () { + Promise.PSD.letThrough = true; // Set a Promise-Specific Data property informing that onready is firing. This will make db._whenReady() let the subscribers use the DB but block all others (!). Quite cool ha? + try { + var res = db.on.ready.fire(); + if (res && typeof res.then === 'function') { + // If on('ready') returns a promise, wait for it to complete and then resume any pending operations. + res.then(resume, function (err) { + idbdb.close(); + idbdb = null; + openError(err); + }); + } else { + asap(resume); // Cannot call resume directly because then the pauseResumables would inherit from our PSD scope. + } + } catch (e) { + openError(e); + } + + function resume() { + db_is_blocked = false; + executePausedResumeables(); + resolve(); + } + }); + }, openError); + } catch (err) { + openError(err); + } + }).then(function () { + connections.push(db); + return db; + }); + }; + + this.close = function () { + var idx = connections.indexOf(db); + if (idx >= 0) connections.splice(idx, 1); + if (idbdb) { + idbdb.close(); + idbdb = null; + autoOpen = false; + if (db_is_blocked) { + executePausedResumeables(); + } + db_is_blocked = false; + dbOpenError = new exceptions$1.DatabaseClosed(); + } else if (isBeingOpened) { + db.on('ready', function () { + return Promise.reject(new exceptions$1.DatabaseClosed()); + }); + } + }; + + this.delete = function () { + var args = arguments; + return new Promise(function (resolve, reject) { + if (args.length > 0) throw new exceptions$1.InvalidArgument("Arguments not allowed in db.delete()"); + function doDelete() { + db.close(); + var req = indexedDB.deleteDatabase(dbName); + req.onsuccess = function () { + if (!hasNativeGetDatabaseNames) { + globalDatabaseList(function (databaseNames) { + var pos = databaseNames.indexOf(dbName); + if (pos >= 0) return databaseNames.splice(pos, 1); + }); + } + resolve(); + }; + req.onerror = eventRejectHandler(reject, ["deleting", dbName]); + req.onblocked = fireOnBlocked; + } + if (isBeingOpened) { + pausedResumeables.push({ resume: doDelete }); + } else { + doDelete(); + } + }); + }; + + this.backendDB = function () { + return idbdb; + }; + + this.isOpen = function () { + return idbdb !== null; + }; + this.hasFailed = function () { + return dbOpenError !== null; + }; + this.dynamicallyOpened = function () { + return autoSchema; + }; + + // + // Properties + // + this.name = dbName; + + // db.tables - an array of all Table instances. + // TODO: Change so that tables is a simple member and make sure to update it whenever allTables changes. + Object.defineProperty(this, "tables", { + get: function () { + /// + return keys(allTables).map(function (name) { + return allTables[name]; + }); + } + }); + + // + // Events + // + this.on = Events(this, "error", "populate", { blocked: [reverseStoppableEventChain, nop], "ready": [promisableChain, nop], "versionchange": [reverseStoppableEventChain, nop] }); + + // Handle on('ready') specifically: If DB is already open, trigger the event immediately. Also, default to unsubscribe immediately after being triggered. + this.on.ready.subscribe = override(this.on.ready.subscribe, function (origSubscribe) { + return function (subscriber, bSticky) { + function proxy() { + if (!bSticky) db.on.ready.unsubscribe(proxy); + return subscriber.apply(this, arguments); + } + origSubscribe.call(this, proxy); + if (db.isOpen()) { + if (db_is_blocked) { + pausedResumeables.push({ resume: proxy }); + } else { + proxy(); + } + } + }; + }); + + fakeAutoComplete(function () { + db.on("populate").fire(db._createTransaction(READWRITE, dbStoreNames, globalSchema)); + db.on("error").fire(new Error()); + }); + + this.transaction = function (mode, tableInstances, scopeFunc) { + /// + /// + /// + /// "r" for readonly, or "rw" for readwrite + /// Table instance, Array of Table instances, String or String Array of object stores to include in the transaction + /// Function to execute with transaction + + // Let table arguments be all arguments between mode and last argument. + tableInstances = slice(arguments, 1, arguments.length - 1); + // Let scopeFunc be the last argument + scopeFunc = arguments[arguments.length - 1]; + var parentTransaction = Promise.PSD && Promise.PSD.trans; + // Check if parent transactions is bound to this db instance, and if caller wants to reuse it + if (!parentTransaction || parentTransaction.db !== db || mode.indexOf('!') !== -1) parentTransaction = null; + var onlyIfCompatible = mode.indexOf('?') !== -1; + mode = mode.replace('!', '').replace('?', ''); + // + // Get storeNames from arguments. Either through given table instances, or through given table names. + // + var tables = isArray(tableInstances[0]) ? tableInstances.reduce(function (a, b) { + return a.concat(b); + }) : tableInstances; + var error = null; + var storeNames = tables.map(function (tableInstance) { + if (typeof tableInstance === "string") { + return tableInstance; + } else { + if (!(tableInstance instanceof Table)) error = error || new TypeError("Invalid type. Arguments following mode must be instances of Table or String"); + return tableInstance.name; + } + }); + + // + // Resolve mode. Allow shortcuts "r" and "rw". + // + if (mode == "r" || mode == READONLY) mode = READONLY;else if (mode == "rw" || mode == READWRITE) mode = READWRITE;else error = new exceptions$1.InvalidArgument("Invalid transaction mode: " + mode); + + if (parentTransaction) { + // Basic checks + if (!error) { + if (parentTransaction && parentTransaction.mode === READONLY && mode === READWRITE) { + if (onlyIfCompatible) parentTransaction = null; // Spawn new transaction instead. + else error = error || new exceptions$1.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY"); + } + if (parentTransaction) { + storeNames.forEach(function (storeName) { + if (!parentTransaction.tables.hasOwnProperty(storeName)) { + if (onlyIfCompatible) parentTransaction = null; // Spawn new transaction instead. + else error = error || new exceptions$1.SubTransaction("Table " + storeName + " not included in parent transaction. Parent Transaction function: " + parentTransaction.scopeFunc.toString()); + } + }); + } + } + } + if (parentTransaction) { + // If this is a sub-transaction, lock the parent and then launch the sub-transaction. + return parentTransaction._promise(mode, enterTransactionScope, "lock"); + } else { + // If this is a root-level transaction, wait til database is ready and then launch the transaction. + return db._whenReady(enterTransactionScope); + } + + function enterTransactionScope(resolve, reject) { + // Our transaction. To be set later. + var trans = null; + var isConstructing = true; + + try { + // Throw any error if any of the above checks failed. + // Real error defined some lines up. We throw it here from within a Promise to reject Promise + // rather than make caller need to both use try..catch and promise catching. The reason we still + // throw here rather than do Promise.reject(error) is that we like to have the stack attached to the + // error. Also because there is a catch() clause bound to this try() that will bubble the error + // to the parent transaction. + if (error) throw error; + + // + // Create Transaction instance + // + trans = db._createTransaction(mode, storeNames, globalSchema, parentTransaction); + + // Provide arguments to the scope function (for backward compatibility) + var tableArgs = storeNames.map(function (name) { + return trans.tables[name]; + }); + tableArgs.push(trans); + + // If transaction completes, resolve the Promise with the return value of scopeFunc. + var returnValue; + var uncompletedRequests = 0; + + // Create a new PSD frame to hold Promise.PSD.trans. Must not be bound to the current PSD frame since we want + // it to pop before then() callback is called of our returned Promise. + Promise.newPSD(function () { + // Let the transaction instance be part of a Promise-specific data (PSD) value. + Promise.PSD.trans = trans; + trans.scopeFunc = scopeFunc; // For Error ("Table " + storeNames[0] + " not part of transaction") when it happens. This may help localizing the code that started a transaction used on another place. + + if (parentTransaction) { + // Emulate transaction commit awareness for inner transaction (must 'commit' when the inner transaction has no more operations ongoing) + trans.idbtrans = parentTransaction.idbtrans; + trans._promise = override(trans._promise, function (orig) { + return function (mode, fn, writeLock) { + ++uncompletedRequests; + function proxy(fn2) { + return function (val) { + var retval; + // _rootExec needed so that we do not loose any IDBTransaction in a setTimeout() call. + Promise._rootExec(function () { + retval = fn2(val); + // _tickFinalize makes sure to support lazy micro tasks executed in Promise._rootExec(). + // We certainly do not want to copy the bad pattern from IndexedDB but instead allow + // execution of Promise.then() callbacks until the're all done. + Promise._tickFinalize(function () { + if (--uncompletedRequests === 0 && trans.active) { + trans.active = false; + trans.on.complete.fire(); // A called db operation has completed without starting a new operation. The flow is finished + } + }); + }); + return retval; + }; + } + return orig.call(this, mode, function (resolve2, reject2, trans) { + return fn(proxy(resolve2), proxy(reject2), trans); + }, writeLock); + }; + }); + } + trans.complete(function () { + resolve(returnValue); + }); + // If transaction fails, reject the Promise and bubble to db if noone catched this rejection. + trans.error(function (e) { + if (trans.idbtrans) trans.idbtrans.onerror = preventDefault; // Prohibit AbortError from firing. + try { + trans.abort(); + } catch (e2) {} + if (parentTransaction) { + parentTransaction.active = false; + parentTransaction.on.error.fire(e); // Bubble to parent transaction + } + + if (isConstructing) asap(doReject);else doReject(); + function doReject() { + var catched = reject(e); + if (!parentTransaction && !catched) { + db.on.error.fire(e); // If not catched, bubble error to db.on("error"). + } + } + }); + + // Finally, call the scope function with our table and transaction arguments. + Promise._rootExec(function () { + returnValue = scopeFunc.apply(trans, tableArgs); // NOTE: returnValue is used in trans.on.complete() not as a returnValue to this func. + if (returnValue && typeof returnValue.next === 'function' && typeof returnValue.throw === 'function') { + // scopeFunc returned an iterable. Handle yield as await. + returnValue = awaitIterable(returnValue); + } + }); + }); + if (!trans.idbtrans || parentTransaction && uncompletedRequests === 0) { + trans._nop(); // Make sure transaction is being used so that it will resolve. + } + } catch (e) { + // If exception occur, abort the transaction and reject Promise. + if (trans && trans.idbtrans) trans.idbtrans.onerror = preventDefault; // Prohibit AbortError from firing. + if (trans) trans.abort(); + if (parentTransaction) parentTransaction.on.error.fire(e); + asap(function () { + // Need to use asap(=setImmediate/setTimeout) before calling reject because we are in the Promise constructor and reject() will always return false if so. + if (!reject(e)) db.on("error").fire(e); // If not catched, bubble exception to db.on("error"); + }); + } + isConstructing = false; + } + }; + + this.table = function (tableName) { + /// + if (fake && autoSchema) return new WriteableTable(tableName); + if (!allTables.hasOwnProperty(tableName)) { + throw new exceptions$1.InvalidTable('Table ' + tableName + ' does not exist'); + } + return allTables[tableName]; + }; + + // + // + // + // Table Class + // + // + // + function Table(name, transactionPromiseFactory, tableSchema, collClass) { + /// + this.name = name; + this.schema = tableSchema; + this.hook = allTables[name] ? allTables[name].hook : Events(null, { + "creating": [hookCreatingChain, nop], + "reading": [pureFunctionChain, mirror], + "updating": [hookUpdatingChain, nop], + "deleting": [hookDeletingChain, nop] + }); + this._tpf = transactionPromiseFactory; + this._collClass = collClass || Collection; + } + + extend(Table.prototype, function () { + function failReadonly() { + // It's ok to throw here because this can only happen within a transaction, + // and will always be caught by the transaction scope and returned as a + // failed promise. + throw new exceptions$1.ReadOnly("Current Transaction is READONLY"); + } + return { + // + // Table Protected Methods + // + + _trans: function getTransaction(mode, fn, writeLocked) { + return this._tpf(mode, [this.name], fn, writeLocked); + }, + _idbstore: function getIDBObjectStore(mode, fn, writeLocked) { + if (fake) return new Promise(fn); // Simplify the work for Intellisense/Code completion. + var self = this; + return this._tpf(mode, [this.name], function (resolve, reject, trans) { + fn(resolve, reject, trans.idbtrans.objectStore(self.name), trans); + }, writeLocked); + }, + + // + // Table Public Methods + // + get: function (key, cb) { + var self = this; + return this._idbstore(READONLY, function (resolve, reject, idbstore) { + fake && resolve(self.schema.instanceTemplate); + var req = idbstore.get(key); + req.onerror = eventRejectHandler(reject, ["getting", key, "from", self.name]); + req.onsuccess = function () { + resolve(self.hook.reading.fire(req.result)); + }; + }).then(cb); + }, + where: function (indexName) { + return new WhereClause(this, indexName); + }, + count: function (cb) { + return this.toCollection().count(cb); + }, + offset: function (offset) { + return this.toCollection().offset(offset); + }, + limit: function (numRows) { + return this.toCollection().limit(numRows); + }, + reverse: function () { + return this.toCollection().reverse(); + }, + filter: function (filterFunction) { + return this.toCollection().and(filterFunction); + }, + each: function (fn) { + return this.toCollection().each(fn); + }, + toArray: function (cb) { + return this.toCollection().toArray(cb); + }, + orderBy: function (index) { + return new this._collClass(new WhereClause(this, index)); + }, + + toCollection: function () { + return new this._collClass(new WhereClause(this)); + }, + + mapToClass: function (constructor, structure) { + /// + /// Map table to a javascript constructor function. Objects returned from the database will be instances of this class, making + /// it possible to the instanceOf operator as well as extending the class using constructor.prototype.method = function(){...}. + /// + /// Constructor function representing the class. + /// Helps IDE code completion by knowing the members that objects contain and not just the indexes. Also + /// know what type each member has. Example: {name: String, emailAddresses: [String], password} + this.schema.mappedClass = constructor; + var instanceTemplate = Object.create(constructor.prototype); + if (structure) { + // structure and instanceTemplate is for IDE code competion only while constructor.prototype is for actual inheritance. + applyStructure(instanceTemplate, structure); + } + this.schema.instanceTemplate = instanceTemplate; + + // Now, subscribe to the when("reading") event to make all objects that come out from this table inherit from given class + // no matter which method to use for reading (Table.get() or Table.where(...)... ) + var readHook = function (obj) { + if (!obj) return obj; // No valid object. (Value is null). Return as is. + // Create a new object that derives from constructor: + var res = Object.create(constructor.prototype); + // Clone members: + for (var m in obj) { + if (obj.hasOwnProperty(m)) res[m] = obj[m]; + }return res; + }; + + if (this.schema.readHook) { + this.hook.reading.unsubscribe(this.schema.readHook); + } + this.schema.readHook = readHook; + this.hook("reading", readHook); + return constructor; + }, + defineClass: function (structure) { + /// + /// Define all members of the class that represents the table. This will help code completion of when objects are read from the database + /// as well as making it possible to extend the prototype of the returned constructor function. + /// + /// Helps IDE code completion by knowing the members that objects contain and not just the indexes. Also + /// know what type each member has. Example: {name: String, emailAddresses: [String], properties: {shoeSize: Number}} + return this.mapToClass(Dexie.defineClass(structure), structure); + }, + add: failReadonly, + put: failReadonly, + 'delete': failReadonly, + clear: failReadonly, + update: failReadonly + }; + }); + + // + // + // + // WriteableTable Class (extends Table) + // + // + // + function WriteableTable(name, transactionPromiseFactory, tableSchema, collClass) { + Table.call(this, name, transactionPromiseFactory, tableSchema, collClass || WriteableCollection); + } + + function BulkErrorHandlerCatchAll(errorList, done) { + var psd = Promise.PSD; + return function (ev) { + try { + if (ev.stopPropagation) ev.stopPropagation(); + if (ev.preventDefault) ev.preventDefault(); + var err = ev.target.error; + errorList.push(err); + if (ev.target._err) { + Promise.usePSD(psd, ev.target._err.bind(null, err)); + } + } finally { + if (done) done(); + } + }; + } + + function BulkErrorHandler(done) { + var psd = Promise.PSD; + return function (ev) { + var err = void 0; + try { + err = ev.target.error; + if (ev.target._err) { + Promise.usePSD(psd, ev.target._err.bind(null, err)); + } + } finally { + done(err); + } + }; + } + + function BulkSuccessHandler(done, hookListener) { + var psd = Promise.PSD; + return hookListener ? function (ev) { + var res = void 0; + try { + res = ev.target.result; + ev.target._suc && Promise.usePSD(psd, ev.target._suc.bind(null, res)); + } finally { + if (done) done(res); + } + } : function (ev) { + done(ev.target.result); + }; + } + + function bulkDelete(idbstore, trans, keysOrTuples, hasDeleteHook, deletingHook) { + // If hasDeleteHook, keysOrTuples must be an array of tuples: [[key1, value2],[key2,value2],...], + // else keysOrTuples must be just an array of keys: [key1, key2, ...]. + return new Promise(function (resolve, reject) { + var len = keysOrTuples.length, + lastItem = len - 1; + if (len === 0) return resolve(); + if (!hasDeleteHook) { + for (var i = 0; i < len; ++i) { + var req = idbstore.delete(keysOrTuples[i]); + req.onerror = function (ev) { + return reject(mapError(ev.target.error)); + }; + if (i === lastItem) req.onsuccess = function () { + return resolve(); + }; + } + } else { + (function () { + var hookCtx = { onsuccess: null, onerror: null }, + errorHandler = BulkErrorHandler(function (e) { + return reject(mapError(e)); + }), + successHandler = BulkSuccessHandler(null, true); + miniTryCatch(function () { + for (var i = 0; i < len; ++i) { + var tuple = keysOrTuples[i]; + deletingHook.call(hookCtx, tuple[0], tuple[1], trans); + var req = idbstore.delete(tuple[0]); + if (hookCtx.onerror) req._err = hookCtx.onerror; + if (hookCtx.onsuccess) req._suc = hookCtx.onsuccess; + req.onerror = errorHandler; + if (i === lastItem) req.onsuccess = BulkSuccessHandler(resolve, true);else req.onsuccess = successHandler; + hookCtx.onsuccess = null; + hookCtx.onerror = null; + } + }, function (err) { + hookCtx.onerror && hookCtx.onerror(err); + throw err; + }); + })(); + } + }); + } + + derive(WriteableTable).from(Table).extend(function () { + + return { + bulkDelete: function (keys) { + if (this.hook.deleting.fire === nop) { + return this._idbstore(READWRITE, function (resolve, reject, idbstore, trans) { + resolve(bulkDelete(idbstore, trans, keys, false, nop)); + }); + } else { + return this.where(':id').anyOf(keys).delete().then(function () {}); // Resolve with undefined. + } + }, + bulkPut: function (objects, keys) { + var _this = this; + + return this._idbstore(READWRITE, function (resolve, reject, idbstore, trans) { + if (!idbstore.keyPath && !_this.schema.primKey.auto && !keys) throw new exceptions$1.InvalidArgument("bulkPut() with non-inbound keys requires keys array in second argument"); + if (idbstore.keyPath && keys) throw new exceptions$1.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys"); + if (keys && keys.length !== objects.length) throw new exceptions$1.InvalidArgument("Arguments objects and keys must have the same length"); + if (objects.length === 0) return resolve(); // Caller provided empty list. + var done = function (result) { + if (errorList.length === 0) resolve(result);else reject(new BulkError(_this.name + '.bulkPut(): ' + errorList.length + ' of ' + numObjs + ' operations failed', errorList)); + }; + var req, + errorList = [], + errorHandler, + successHandler, + numObjs = objects.length, + table = trans.tables[_this.name]; // Enable us to do stuff in several steps with same transaction. + if (_this.hook.creating.fire === nop && _this.hook.updating.fire === nop) { + // + // Standard Bulk (no 'creating' or 'updating' hooks to care about) + // + errorHandler = BulkErrorHandlerCatchAll(errorList); + for (var i = 0, l = objects.length; i < l; ++i) { + req = keys ? idbstore.put(objects[i], keys[i]) : idbstore.put(objects[i]); + req.onerror = errorHandler; + } + // Only need to catch success or error on the last operation + // according to the IDB spec. + req.onerror = BulkErrorHandlerCatchAll(errorList, done); + req.onsuccess = BulkSuccessHandler(done); + } else { + (function () { + var effectiveKeys = keys || idbstore.keyPath && objects.map(function (o) { + return getByKeyPath(o, idbstore.keyPath); + }); + var objectLookup = effectiveKeys && effectiveKeys.reduce(function (res, key, i) { + if (key != null) res[key] = objects[i]; + return res; + }, {}); // Generates map of {[key]: object} + + var promise = !effectiveKeys ? + + // Auto-incremented key-less objects only without any keys argument. + table.bulkAdd(objects) : + + // Keys provided. Either as inbound in provided objects, or as a keys argument. + // Begin with updating those that exists in DB: + table.where(':id').anyOf(Object.keys(objectLookup)).modify(function () { + this.value = objectLookup[this.primKey]; + objectLookup[this.primKey] = null; // Mark as "don't add this" + }).then(function () { + // Now, let's examine which items didnt exist so we can add them: + var objsToAdd = [], + keysToAdd = keys && []; + effectiveKeys.forEach(function (key, i) { + if (key == null || objectLookup[key]) { + objsToAdd.push(objects[i]); + keys && keysToAdd.push(key); + } + }); + return table.bulkAdd(objsToAdd, keysToAdd); + }).then(function (lastAddedKey) { + // Resolve with key of the last object in given arguments to bulkPut(): + var lastEffectiveKey = effectiveKeys[effectiveKeys.length - 1]; // Key was provided. + return lastEffectiveKey != null ? lastEffectiveKey : lastAddedKey; + }); + + promise.then(resolve).catch(ModifyError, function (e) { + // Map ModifyError to BulkError + reject(new BulkError(e.msg, e.failures)); + }).catch(reject); + })(); + } + }, "locked"); // If called from transaction scope, lock transaction til all steps are done. + }, + bulkAdd: function (objects, keys) { + var self = this, + creatingHook = this.hook.creating.fire; + return this._idbstore(READWRITE, function (resolve, reject, idbstore, trans) { + if (!idbstore.keyPath && !self.schema.primKey.auto && !keys) throw new exceptions$1.InvalidArgument("bulkAdd() with non-inbound keys requires keys array in second argument"); + if (idbstore.keyPath && keys) throw new exceptions$1.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys"); + if (keys && keys.length !== objects.length) throw new exceptions$1.InvalidArgument("Arguments objects and keys must have the same length"); + if (objects.length === 0) return resolve(); // Caller provided empty list. + function done(result) { + if (errorList.length === 0) resolve(result);else reject(new BulkError(self.name + '.bulkAdd(): ' + errorList.length + ' of ' + numObjs + ' operations failed', errorList)); + } + var req, + errorList = [], + errorHandler, + successHandler, + numObjs = objects.length; + if (creatingHook !== nop) { + // + // There are subscribers to hook('creating') + // Must behave as documented. + // + var keyPath = idbstore.keyPath, + hookCtx = { onerror: null, onsuccess: null }; + errorHandler = BulkErrorHandlerCatchAll(errorList, null); + successHandler = BulkSuccessHandler(null, true); + + miniTryCatch(function () { + for (var i = 0, l = objects.length; i < l; ++i) { + var key = keys && keys[i]; + var obj = objects[i], + effectiveKey = keys ? key : keyPath ? getByKeyPath(obj, keyPath) : undefined, + keyToUse = creatingHook.call(hookCtx, effectiveKey, obj, trans); + if (effectiveKey == null && keyToUse != null) { + if (keyPath) { + obj = deepClone(obj); + setByKeyPath(obj, keyPath, keyToUse); + } else { + key = keyToUse; + } + } + req = key != null ? idbstore.add(obj, key) : idbstore.add(obj); + if (hookCtx.onerror) req._err = hookCtx.onerror; + if (hookCtx.onsuccess) req._suc = hookCtx.onsuccess; + if (i < l - 1) { + req.onerror = errorHandler; + if (hookCtx.onsuccess) req.onsuccess = successHandler; + // Reset event listeners for next iteration. + hookCtx.onerror = null; + hookCtx.onsuccess = null; + } + } + }, function (err) { + hookCtx.onerror && hookCtx.onerror(err); + throw err; + }); + + req.onerror = BulkErrorHandlerCatchAll(errorList, done); + req.onsuccess = BulkSuccessHandler(done, true); + } else { + // + // Standard Bulk (no 'creating' hook to care about) + // + errorHandler = BulkErrorHandlerCatchAll(errorList); + for (var i = 0, l = objects.length; i < l; ++i) { + req = keys ? idbstore.add(objects[i], keys[i]) : idbstore.add(objects[i]); + req.onerror = errorHandler; + } + // Only need to catch success or error on the last operation + // according to the IDB spec. + req.onerror = BulkErrorHandlerCatchAll(errorList, done); + req.onsuccess = BulkSuccessHandler(done); + } + }); + }, + add: function (obj, key) { + /// + /// Add an object to the database. In case an object with same primary key already exists, the object will not be added. + /// + /// A javascript object to insert + /// Primary key + var self = this, + creatingHook = this.hook.creating.fire; + return this._idbstore(READWRITE, function (resolve, reject, idbstore, trans) { + var thisCtx = { onsuccess: null, onerror: null }; + if (creatingHook !== nop) { + var effectiveKey = key != null ? key : idbstore.keyPath ? getByKeyPath(obj, idbstore.keyPath) : undefined; + var keyToUse = creatingHook.call(thisCtx, effectiveKey, obj, trans); // Allow subscribers to when("creating") to generate the key. + if (effectiveKey == null && keyToUse != null) { + // Using "==" and "!=" to check for either null or undefined! + if (idbstore.keyPath) setByKeyPath(obj, idbstore.keyPath, keyToUse);else key = keyToUse; + } + } + try { + var req = key != null ? idbstore.add(obj, key) : idbstore.add(obj), + psd = Promise.PSD; + req.onerror = eventRejectHandler(function (e) { + if (thisCtx.onerror) Promise.usePSD(psd, thisCtx.onerror.bind(thisCtx, e)); + return reject(e); + }, ["adding", obj, "into", self.name]); + req.onsuccess = function (ev) { + var keyPath = idbstore.keyPath; + if (keyPath) setByKeyPath(obj, keyPath, ev.target.result); + if (thisCtx.onsuccess) Promise.usePSD(psd, thisCtx.onsuccess.bind(thisCtx, ev.target.result)); + resolve(req.result); + }; + } catch (e) { + if (thisCtx.onerror) thisCtx.onerror(e); + throw e; + } + }); + }, + + put: function (obj, key) { + /// + /// Add an object to the database but in case an object with same primary key alread exists, the existing one will get updated. + /// + /// A javascript object to insert or update + /// Primary key + var self = this, + creatingHook = this.hook.creating.fire, + updatingHook = this.hook.updating.fire; + if (creatingHook !== nop || updatingHook !== nop) { + // + // People listens to when("creating") or when("updating") events! + // We must know whether the put operation results in an CREATE or UPDATE. + // + return this._trans(READWRITE, function (resolve, reject, trans) { + // Since key is optional, make sure we get it from obj if not provided + var effectiveKey = key !== undefined ? key : self.schema.primKey.keyPath && getByKeyPath(obj, self.schema.primKey.keyPath); + if (effectiveKey == null) { + // "== null" means checking for either null or undefined. + // No primary key. Must use add(). + trans.tables[self.name].add(obj).then(resolve, reject); + } else { + // Primary key exist. Lock transaction and try modifying existing. If nothing modified, call add(). + trans._lock(); // Needed because operation is splitted into modify() and add(). + // clone obj before this async call. If caller modifies obj the line after put(), the IDB spec requires that it should not affect operation. + obj = deepClone(obj); + trans.tables[self.name].where(":id").equals(effectiveKey).modify(function (value) { + // Replace extisting value with our object + // CRUD event firing handled in WriteableCollection.modify() + this.value = obj; + }).then(function (count) { + if (count === 0) { + // Object's key was not found. Add the object instead. + // CRUD event firing will be done in add() + return trans.tables[self.name].add(obj, key); // Resolving with another Promise. Returned Promise will then resolve with the new key. + } else { + return effectiveKey; // Resolve with the provided key. + } + }).finally(function () { + trans._unlock(); + }).then(resolve, reject); + } + }); + } else { + // Use the standard IDB put() method. + return this._idbstore(READWRITE, function (resolve, reject, idbstore) { + var req = key !== undefined ? idbstore.put(obj, key) : idbstore.put(obj); + req.onerror = eventRejectHandler(reject, ["putting", obj, "into", self.name]); + req.onsuccess = function (ev) { + var keyPath = idbstore.keyPath; + if (keyPath) setByKeyPath(obj, keyPath, ev.target.result); + resolve(req.result); + }; + }); + } + }, + + 'delete': function (key) { + /// Primary key of the object to delete + if (this.hook.deleting.subscribers.length) { + // People listens to when("deleting") event. Must implement delete using WriteableCollection.delete() that will + // call the CRUD event. Only WriteableCollection.delete() will know whether an object was actually deleted. + return this.where(":id").equals(key).delete(); + } else { + // No one listens. Use standard IDB delete() method. + return this._idbstore(READWRITE, function (resolve, reject, idbstore) { + var req = idbstore.delete(key); + req.onerror = eventRejectHandler(reject, ["deleting", key, "from", idbstore.name]); + req.onsuccess = function (ev) { + resolve(req.result); + }; + }); + } + }, + + clear: function () { + if (this.hook.deleting.subscribers.length) { + // People listens to when("deleting") event. Must implement delete using WriteableCollection.delete() that will + // call the CRUD event. Only WriteableCollection.delete() will knows which objects that are actually deleted. + return this.toCollection().delete(); + } else { + return this._idbstore(READWRITE, function (resolve, reject, idbstore) { + var req = idbstore.clear(); + req.onerror = eventRejectHandler(reject, ["clearing", idbstore.name]); + req.onsuccess = function (ev) { + resolve(req.result); + }; + }); + } + }, + + update: function (keyOrObject, modifications) { + if (typeof modifications !== 'object' || isArray(modifications)) throw new exceptions$1.InvalidArgument("db.update(keyOrObject, modifications). modifications must be an object."); + if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) { + // object to modify. Also modify given object with the modifications: + keys(modifications).forEach(function (keyPath) { + setByKeyPath(keyOrObject, keyPath, modifications[keyPath]); + }); + var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath); + if (key === undefined) Promise.reject(new exceptions$1.InvalidArgument("Given object does not contain its primary key")); + return this.where(":id").equals(key).modify(modifications); + } else { + // key to modify + return this.where(":id").equals(keyOrObject).modify(modifications); + } + } + }; + }); + + // + // + // + // Transaction Class + // + // + // + function Transaction(mode, storeNames, dbschema, parent) { + /// + /// Transaction class. Represents a database transaction. All operations on db goes through a Transaction. + /// + /// Any of "readwrite" or "readonly" + /// Array of table names to operate on + var self = this; + this.db = db; + this.mode = mode; + this.storeNames = storeNames; + this.idbtrans = null; + this.on = Events(this, ["complete", "error"], "abort"); + this._reculock = 0; + this._blockedFuncs = []; + this._psd = null; + this.active = true; + this._dbschema = dbschema; + if (parent) this.parent = parent; + this._tpf = transactionPromiseFactory; + this.tables = Object.create(notInTransFallbackTables); // ...so that all non-included tables exists as instances (possible to call table.name for example) but will fail as soon as trying to execute a query on it. + + function transactionPromiseFactory(mode, storeNames, fn, writeLocked) { + // Creates a Promise instance and calls fn (resolve, reject, trans) where trans is the instance of this transaction object. + // Support for write-locking the transaction during the promise life time from creation to success/failure. + // This is actually not needed when just using single operations on IDB, since IDB implements this internally. + // However, when implementing a write operation as a series of operations on top of IDB(collection.delete() and collection.modify() for example), + // lock is indeed needed if Dexie APIshould behave in a consistent manner for the API user. + // Another example of this is if we want to support create/update/delete events, + // we need to implement put() using a series of other IDB operations but still need to lock the transaction all the way. + return self._promise(mode, fn, writeLocked); + } + + for (var i = storeNames.length - 1; i !== -1; --i) { + var name = storeNames[i]; + var table = db._tableFactory(mode, dbschema[name], transactionPromiseFactory); + this.tables[name] = table; + if (!this[name]) this[name] = table; + } + } + + extend(Transaction.prototype, { + // + // Transaction Protected Methods (not required by API users, but needed internally and eventually by dexie extensions) + // + + _lock: function () { + // Temporary set all requests into a pending queue if they are called before database is ready. + ++this._reculock; // Recursive read/write lock pattern using PSD (Promise Specific Data) instead of TLS (Thread Local Storage) + if (this._reculock === 1 && Promise.PSD) Promise.PSD.lockOwnerFor = this; + return this; + }, + _unlock: function () { + if (--this._reculock === 0) { + if (Promise.PSD) Promise.PSD.lockOwnerFor = null; + while (this._blockedFuncs.length > 0 && !this._locked()) { + var fn = this._blockedFuncs.shift(); + try { + fn(); + } catch (e) {} + } + } + return this; + }, + _locked: function () { + // Checks if any write-lock is applied on this transaction. + // To simplify the Dexie API for extension implementations, we support recursive locks. + // This is accomplished by using "Promise Specific Data" (PSD). + // PSD data is bound to a Promise and any child Promise emitted through then() or resolve( new Promise() ). + // Promise.PSD is local to code executing on top of the call stacks of any of any code executed by Promise(): + // * callback given to the Promise() constructor (function (resolve, reject){...}) + // * callbacks given to then()/catch()/finally() methods (function (value){...}) + // If creating a new independant Promise instance from within a Promise call stack, the new Promise will derive the PSD from the call stack of the parent Promise. + // Derivation is done so that the inner PSD __proto__ points to the outer PSD. + // Promise.PSD.lockOwnerFor will point to current transaction object if the currently executing PSD scope owns the lock. + return this._reculock && (!Promise.PSD || Promise.PSD.lockOwnerFor !== this); + }, + _nop: function (cb) { + // An asyncronic no-operation that may call given callback when done doing nothing. An alternative to asap() if we must not lose the transaction. + this.tables[this.storeNames[0]].get(0).then(cb); + }, + _promise: function (mode, fn, bWriteLock) { + var self = this; + return Promise.newPSD(function () { + var p; + // Read lock always + if (!self._locked()) { + p = self.active ? new Promise(function (resolve, reject) { + if (!self.idbtrans && mode) { + if (!idbdb) throw !dbOpenError || ["DatabaseClosedError", "MissingAPIError"].indexOf(dbOpenError.name) >= 0 ? dbOpenError : // Errors where it is no difference whether it was caused by the user operation or an earlier call to db.open() + new exceptions$1.OpenFailed(dbOpenError); // Make it clear that the user operation was not what caused the error - the error had occurred earlier on db.open()! + + var idbtrans = self.idbtrans = idbdb.transaction(safariMultiStoreFix(self.storeNames), self.mode); + idbtrans.onerror = function (e) { + self.on("error").fire(e && e.target.error); + e.preventDefault(); // Prohibit default bubbling to window.error + self.abort(); // Make sure transaction is aborted since we preventDefault. + }; + idbtrans.onabort = function (e) { + // Workaround for issue #78 - low disk space on chrome. + // onabort is called but never onerror. Call onerror explicitely. + // Do this in a future tick so we allow default onerror to execute before doing the fallback. + asap(function () { + self.on('error').fire(new exceptions$1.Abort("Transaction aborted for unknown reason")); + }); + + self.active = false; + self.on("abort").fire(e); + }; + idbtrans.oncomplete = function (e) { + self.active = false; + self.on("complete").fire(e); + }; + } + if (bWriteLock) self._lock(); // Write lock if write operation is requested + try { + fn(resolve, reject, self); + } catch (e) { + (function () { + // Direct exception happened when doing operation. + // We must immediately fire the error and abort the transaction. + // When this happens we are still constructing the Promise so we don't yet know + // whether the caller is about to catch() the error or not. Have to make + // transaction fail. Catching such an error wont stop transaction from failing. + // This is a limitation we have to live with. + var e2 = stack(mapError(e)); + Dexie.ignoreTransaction(function () { + self.on('error').fire(e2); + }); + self.abort(); + reject(e2); + })(); + } + }) : Promise.reject(stack(new exceptions$1.TransactionInactive("Transaction is inactive. Original Scope Function Source: " + self.scopeFunc.toString()))); + if (self.active && bWriteLock) p.finally(function () { + self._unlock(); + }); + } else { + // Transaction is write-locked. Wait for mutex. + p = new Promise(function (resolve, reject) { + self._blockedFuncs.push(function () { + self._promise(mode, fn, bWriteLock).then(resolve, reject); + }); + }); + } + p.onuncatched = function (e) { + // Bubble to transaction. Even though IDB does this internally, it would just do it for error events and not for caught exceptions. + Dexie.ignoreTransaction(function () { + self.on("error").fire(e); + }); + self.abort(); + }; + return p; + }); + }, + + // + // Transaction Public Methods + // + + complete: function (cb) { + return this.on("complete", cb); + }, + error: function (cb) { + return this.on("error", cb); + }, + abort: function () { + if (this.idbtrans && this.active) try { + // TODO: if !this.idbtrans, enqueue an abort() operation. + this.active = false; + this.idbtrans.abort(); + this.on.error.fire(new exceptions$1.Abort("Transaction Aborted")); + } catch (e) {} + }, + table: function (name) { + if (!this.tables.hasOwnProperty(name)) { + throw new exceptions$1.InvalidTable("Table " + name + " not in transaction"); + } + return this.tables[name]; + } + }); + + // + // + // + // WhereClause + // + // + // + function WhereClause(table, index, orCollection) { + /// + /// + /// + this._ctx = { + table: table, + index: index === ":id" ? null : index, + collClass: table._collClass, + or: orCollection + }; + } + + extend(WhereClause.prototype, function () { + + // WhereClause private methods + + function fail(c, err, T) { + var collection = c instanceof WhereClause ? new c._ctx.collClass(c) : c; + try { + throw T ? new T(err) : new TypeError(err); + } catch (e) { + collection._ctx.error = e; + } + return collection; + } + + function emptyCollection(whereClause) { + return new whereClause._ctx.collClass(whereClause, function () { + return IDBKeyRange.only(""); + }).limit(0); + } + + function getSetArgs(args) { + return slice(args.length === 1 && isArray(args[0]) ? args[0] : args); + } + + function upperFactory(dir) { + return dir === "next" ? function (s) { + return s.toUpperCase(); + } : function (s) { + return s.toLowerCase(); + }; + } + function lowerFactory(dir) { + return dir === "next" ? function (s) { + return s.toLowerCase(); + } : function (s) { + return s.toUpperCase(); + }; + } + function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) { + var length = Math.min(key.length, lowerNeedle.length); + var llp = -1; + for (var i = 0; i < length; ++i) { + var lwrKeyChar = lowerKey[i]; + if (lwrKeyChar !== lowerNeedle[i]) { + if (cmp(key[i], upperNeedle[i]) < 0) return key.substr(0, i) + upperNeedle[i] + upperNeedle.substr(i + 1); + if (cmp(key[i], lowerNeedle[i]) < 0) return key.substr(0, i) + lowerNeedle[i] + upperNeedle.substr(i + 1); + if (llp >= 0) return key.substr(0, llp) + lowerKey[llp] + upperNeedle.substr(llp + 1); + return null; + } + if (cmp(key[i], lwrKeyChar) < 0) llp = i; + } + if (length < lowerNeedle.length && dir === "next") return key + upperNeedle.substr(key.length); + if (length < key.length && dir === "prev") return key.substr(0, upperNeedle.length); + return llp < 0 ? null : key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1); + } + + function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) { + /// + var upper, + lower, + compare, + upperNeedles, + lowerNeedles, + direction, + nextKeySuffix, + needlesLen = needles.length; + function initDirection(dir) { + upper = upperFactory(dir); + lower = lowerFactory(dir); + compare = dir === "next" ? simpleCompare : simpleCompareReverse; + var needleBounds = needles.map(function (needle) { + return { lower: lower(needle), upper: upper(needle) }; + }).sort(function (a, b) { + return compare(a.lower, b.lower); + }); + upperNeedles = needleBounds.map(function (nb) { + return nb.upper; + }); + lowerNeedles = needleBounds.map(function (nb) { + return nb.lower; + }); + direction = dir; + nextKeySuffix = dir === "next" ? "" : suffix; + } + initDirection("next"); + + var c = new whereClause._ctx.collClass(whereClause, function () { + return IDBKeyRange.bound(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix); + }); + + c._ondirectionchange = function (direction) { + // This event onlys occur before filter is called the first time. + initDirection(direction); + }; + + var firstPossibleNeedle = 0; + + c._addAlgorithm(function (cursor, advance, resolve) { + /// + /// + /// + var key = cursor.key; + if (typeof key !== 'string') return false; + var lowerKey = lower(key); + if (match(lowerKey, lowerNeedles, firstPossibleNeedle)) { + return true; + } else { + var lowestPossibleCasing = null; + for (var i = firstPossibleNeedle; i < needlesLen; ++i) { + var casing = nextCasing(key, lowerKey, upperNeedles[i], lowerNeedles[i], compare, direction); + if (casing === null && lowestPossibleCasing === null) firstPossibleNeedle = i + 1;else if (lowestPossibleCasing === null || compare(lowestPossibleCasing, casing) > 0) { + lowestPossibleCasing = casing; + } + } + if (lowestPossibleCasing !== null) { + advance(function () { + cursor.continue(lowestPossibleCasing + nextKeySuffix); + }); + } else { + advance(resolve); + } + return false; + } + }); + return c; + } + + // + // WhereClause public methods + // + return { + between: function (lower, upper, includeLower, includeUpper) { + /// + /// Filter out records whose where-field lays between given lower and upper values. Applies to Strings, Numbers and Dates. + /// + /// + /// + /// Whether items that equals lower should be included. Default true. + /// Whether items that equals upper should be included. Default false. + /// + includeLower = includeLower !== false; // Default to true + includeUpper = includeUpper === true; // Default to false + try { + if (cmp(lower, upper) > 0 || cmp(lower, upper) === 0 && (includeLower || includeUpper) && !(includeLower && includeUpper)) return emptyCollection(this); // Workaround for idiotic W3C Specification that DataError must be thrown if lower > upper. The natural result would be to return an empty collection. + return new this._ctx.collClass(this, function () { + return IDBKeyRange.bound(lower, upper, !includeLower, !includeUpper); + }); + } catch (e) { + return fail(this, INVALID_KEY_ARGUMENT); + } + }, + equals: function (value) { + return new this._ctx.collClass(this, function () { + return IDBKeyRange.only(value); + }); + }, + above: function (value) { + return new this._ctx.collClass(this, function () { + return IDBKeyRange.lowerBound(value, true); + }); + }, + aboveOrEqual: function (value) { + return new this._ctx.collClass(this, function () { + return IDBKeyRange.lowerBound(value); + }); + }, + below: function (value) { + return new this._ctx.collClass(this, function () { + return IDBKeyRange.upperBound(value, true); + }); + }, + belowOrEqual: function (value) { + return new this._ctx.collClass(this, function () { + return IDBKeyRange.upperBound(value); + }); + }, + startsWith: function (str) { + /// + if (typeof str !== 'string') return fail(this, STRING_EXPECTED); + return this.between(str, str + maxString, true, true); + }, + startsWithIgnoreCase: function (str) { + /// + if (typeof str !== 'string') return fail(this, STRING_EXPECTED); + if (str === "") return this.startsWith(str); + return addIgnoreCaseAlgorithm(this, function (x, a) { + return x.indexOf(a[0]) === 0; + }, [str], maxString); + }, + equalsIgnoreCase: function (str) { + /// + if (typeof str !== 'string') return fail(this, STRING_EXPECTED); + return addIgnoreCaseAlgorithm(this, function (x, a) { + return x === a[0]; + }, [str], ""); + }, + anyOfIgnoreCase: function (stringsToFind) { + var set = getSetArgs(arguments); + if (set.length === 0) return emptyCollection(this); + if (!set.every(function (s) { + return typeof s === 'string'; + })) { + return fail(this, "anyOfIgnoreCase() only works with strings"); + } + return addIgnoreCaseAlgorithm(this, function (x, a) { + return a.indexOf(x) !== -1; + }, set, ""); + }, + startsWithAnyOfIgnoreCase: function (stringsToFind) { + var set = getSetArgs(arguments); + if (set.length === 0) return emptyCollection(this); + if (!set.every(function (s) { + return typeof s === 'string'; + })) { + return fail(this, "startsWithAnyOfIgnoreCase() only works with strings"); + } + return addIgnoreCaseAlgorithm(this, function (x, a) { + return a.some(function (n) { + return x.indexOf(n) === 0; + }); + }, set, maxString); + }, + anyOf: function (valueArray) { + var set = getSetArgs(arguments); + var compare = ascending; + try { + set.sort(compare); + } catch (e) { + return fail(this, INVALID_KEY_ARGUMENT); + } + if (set.length === 0) return emptyCollection(this); + var c = new this._ctx.collClass(this, function () { + return IDBKeyRange.bound(set[0], set[set.length - 1]); + }); + + c._ondirectionchange = function (direction) { + compare = direction === "next" ? ascending : descending; + set.sort(compare); + }; + var i = 0; + c._addAlgorithm(function (cursor, advance, resolve) { + var key = cursor.key; + while (compare(key, set[i]) > 0) { + // The cursor has passed beyond this key. Check next. + ++i; + if (i === set.length) { + // There is no next. Stop searching. + advance(resolve); + return false; + } + } + if (compare(key, set[i]) === 0) { + // The current cursor value should be included and we should continue a single step in case next item has the same key or possibly our next key in set. + return true; + } else { + // cursor.key not yet at set[i]. Forward cursor to the next key to hunt for. + advance(function () { + cursor.continue(set[i]); + }); + return false; + } + }); + return c; + }, + + notEqual: function (value) { + return this.inAnyRange([[-Infinity, value], [value, maxKey]], { includeLowers: false, includeUppers: false }); + }, + + noneOf: function (valueArray) { + var set = getSetArgs(arguments); + if (set.length === 0) return new this._ctx.collClass(this); // Return entire collection. + try { + set.sort(ascending); + } catch (e) { + return fail(this, INVALID_KEY_ARGUMENT); + } + // Transform ["a","b","c"] to a set of ranges for between/above/below: [[-Infinity,"a"], ["a","b"], ["b","c"], ["c",maxKey]] + var ranges = set.reduce(function (res, val) { + return res ? res.concat([[res[res.length - 1][1], val]]) : [[-Infinity, val]]; + }, null); + ranges.push([set[set.length - 1], maxKey]); + return this.inAnyRange(ranges, { includeLowers: false, includeUppers: false }); + }, + + /** Filter out values withing given set of ranges. + * Example, give children and elders a rebate of 50%: + * + * db.friends.where('age').inAnyRange([[0,18],[65,Infinity]]).modify({Rebate: 1/2}); + * + * @param {(string|number|Date|Array)[][]} ranges + * @param {{includeLowers: boolean, includeUppers: boolean}} options + */ + inAnyRange: function (ranges, options) { + var ctx = this._ctx; + if (ranges.length === 0) return emptyCollection(this); + if (!ranges.every(function (range) { + return range[0] !== undefined && range[1] !== undefined && ascending(range[0], range[1]) <= 0; + })) { + return fail(this, "First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower", exceptions$1.InvalidArgument); + } + var includeLowers = !options || options.includeLowers !== false; // Default to true + var includeUppers = options && options.includeUppers === true; // Default to false + + function addRange(ranges, newRange) { + for (var i = 0, l = ranges.length; i < l; ++i) { + var range = ranges[i]; + if (cmp(newRange[0], range[1]) < 0 && cmp(newRange[1], range[0]) > 0) { + range[0] = min(range[0], newRange[0]); + range[1] = max(range[1], newRange[1]); + break; + } + } + if (i === l) ranges.push(newRange); + return ranges; + } + + var sortDirection = ascending; + function rangeSorter(a, b) { + return sortDirection(a[0], b[0]); + } + + // Join overlapping ranges + var set; + try { + set = ranges.reduce(addRange, []); + set.sort(rangeSorter); + } catch (ex) { + return fail(this, INVALID_KEY_ARGUMENT); + } + + var i = 0; + var keyIsBeyondCurrentEntry = includeUppers ? function (key) { + return ascending(key, set[i][1]) > 0; + } : function (key) { + return ascending(key, set[i][1]) >= 0; + }; + + var keyIsBeforeCurrentEntry = includeLowers ? function (key) { + return descending(key, set[i][0]) > 0; + } : function (key) { + return descending(key, set[i][0]) >= 0; + }; + + function keyWithinCurrentRange(key) { + return !keyIsBeyondCurrentEntry(key) && !keyIsBeforeCurrentEntry(key); + } + + var checkKey = keyIsBeyondCurrentEntry; + + var c = new ctx.collClass(this, function () { + return IDBKeyRange.bound(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers); + }); + + c._ondirectionchange = function (direction) { + if (direction === "next") { + checkKey = keyIsBeyondCurrentEntry; + sortDirection = ascending; + } else { + checkKey = keyIsBeforeCurrentEntry; + sortDirection = descending; + } + set.sort(rangeSorter); + }; + + c._addAlgorithm(function (cursor, advance, resolve) { + var key = cursor.key; + while (checkKey(key)) { + // The cursor has passed beyond this key. Check next. + ++i; + if (i === set.length) { + // There is no next. Stop searching. + advance(resolve); + return false; + } + } + if (keyWithinCurrentRange(key)) { + // The current cursor value should be included and we should continue a single step in case next item has the same key or possibly our next key in set. + return true; + } else if (cmp(key, set[i][1]) === 0 || cmp(key, set[i][0]) === 0) { + // includeUpper or includeLower is false so keyWithinCurrentRange() returns false even though we are at range border. + // Continue to next key but don't include this one. + return false; + } else { + // cursor.key not yet at set[i]. Forward cursor to the next key to hunt for. + advance(function () { + if (sortDirection === ascending) cursor.continue(set[i][0]);else cursor.continue(set[i][1]); + }); + return false; + } + }); + return c; + }, + startsWithAnyOf: function (valueArray) { + var set = getSetArgs(arguments); + + if (!set.every(function (s) { + return typeof s === 'string'; + })) { + return fail(this, "startsWithAnyOf() only works with strings"); + } + if (set.length === 0) return emptyCollection(this); + + return this.inAnyRange(set.map(function (str) { + return [str, str + maxString]; + })); + } + }; + }); + + // + // + // + // Collection Class + // + // + // + function Collection(whereClause, keyRangeGenerator) { + /// + /// + /// + /// Where clause instance + /// + var keyRange = null, + error = null; + if (keyRangeGenerator) try { + keyRange = keyRangeGenerator(); + } catch (ex) { + error = stack(mapError(ex)); + } + + var whereCtx = whereClause._ctx, + table = whereCtx.table; + this._ctx = { + table: table, + index: whereCtx.index, + isPrimKey: !whereCtx.index || table.schema.primKey.keyPath && whereCtx.index === table.schema.primKey.name, + range: keyRange, + keysOnly: false, + dir: "next", + unique: "", + algorithm: null, + filter: null, + replayFilter: null, + isMatch: null, + offset: 0, + limit: Infinity, + error: error, // If set, any promise must be rejected with this error + or: whereCtx.or, + valueFilter: table.hook.reading.fire + }; + } + + extend(Collection.prototype, function () { + + // + // Collection Private Functions + // + + function addFilter(ctx, fn) { + ctx.filter = combine(ctx.filter, fn); + } + + function addReplayFilter(ctx, factory) { + var curr = ctx.replayFilter; + ctx.replayFilter = curr ? function () { + return combine(curr(), factory()); + } : factory; + } + + function addMatchFilter(ctx, fn) { + ctx.isMatch = combine(ctx.isMatch, fn); + } + + function getIndexOrStore(ctx, store) { + if (ctx.isPrimKey) return store; + var indexSpec = ctx.table.schema.idxByName[ctx.index]; + if (!indexSpec) throw new exceptions$1.Schema("KeyPath " + ctx.index + " on object store " + store.name + " is not indexed"); + return store.index(indexSpec.name); + } + + function openCursor(ctx, store) { + var idxOrStore = getIndexOrStore(ctx, store); + return ctx.keysOnly && 'openKeyCursor' in idxOrStore ? idxOrStore.openKeyCursor(ctx.range || null, ctx.dir + ctx.unique) : idxOrStore.openCursor(ctx.range || null, ctx.dir + ctx.unique); + } + + function iter(ctx, fn, resolve, reject, idbstore) { + var filter = ctx.replayFilter ? combine(ctx.filter, ctx.replayFilter()) : ctx.filter; + if (!ctx.or) { + iterate(openCursor(ctx, idbstore), combine(ctx.algorithm, filter), fn, resolve, reject, !ctx.keysOnly && ctx.valueFilter); + } else { + (function () { + var set = {}; + var resolved = 0; + + function resolveboth() { + if (++resolved === 2) resolve(); // Seems like we just support or btwn max 2 expressions, but there are no limit because we do recursion. + } + + function union(item, cursor, advance) { + if (!filter || filter(cursor, advance, resolveboth, reject)) { + var key = cursor.primaryKey.toString(); // Converts any Date to String, String to String, Number to String and Array to comma-separated string + if (!set.hasOwnProperty(key)) { + set[key] = true; + fn(item, cursor, advance); + } + } + } + + ctx.or._iterate(union, resolveboth, reject, idbstore); + iterate(openCursor(ctx, idbstore), ctx.algorithm, union, resolveboth, reject, !ctx.keysOnly && ctx.valueFilter); + })(); + } + } + function getInstanceTemplate(ctx) { + return ctx.table.schema.instanceTemplate; + } + + return { + + // + // Collection Protected Functions + // + + _read: function (fn, cb) { + var ctx = this._ctx; + if (ctx.error) return ctx.table._trans(null, function rejector(resolve, reject) { + reject(ctx.error); + });else return ctx.table._idbstore(READONLY, fn).then(cb); + }, + _write: function (fn) { + var ctx = this._ctx; + if (ctx.error) return ctx.table._trans(null, function rejector(resolve, reject) { + reject(ctx.error); + });else return ctx.table._idbstore(READWRITE, fn, "locked"); // When doing write operations on collections, always lock the operation so that upcoming operations gets queued. + }, + _addAlgorithm: function (fn) { + var ctx = this._ctx; + ctx.algorithm = combine(ctx.algorithm, fn); + }, + + _iterate: function (fn, resolve, reject, idbstore) { + return iter(this._ctx, fn, resolve, reject, idbstore); + }, + + clone: function (props) { + var rv = Object.create(this.constructor.prototype), + ctx = Object.create(this._ctx); + if (props) extend(ctx, props); + rv._ctx = ctx; + return rv; + }, + + raw: function () { + this._ctx.valueFilter = null; + return this; + }, + + // + // Collection Public methods + // + + each: function (fn) { + var ctx = this._ctx; + + fake && fn(getInstanceTemplate(ctx)); + + return this._read(function (resolve, reject, idbstore) { + iter(ctx, fn, resolve, reject, idbstore); + }); + }, + + count: function (cb) { + if (fake) return Promise.resolve(0).then(cb); + var self = this, + ctx = this._ctx; + + if (ctx.filter || ctx.algorithm || ctx.or || ctx.replayFilter) { + // When filters are applied or 'ored' collections are used, we must count manually + var count = 0; + return this._read(function (resolve, reject, idbstore) { + iter(ctx, function () { + ++count;return false; + }, function () { + resolve(count); + }, reject, idbstore); + }, cb); + } else { + // Otherwise, we can use the count() method if the index. + return this._read(function (resolve, reject, idbstore) { + var idx = getIndexOrStore(ctx, idbstore); + var req = ctx.range ? idx.count(ctx.range) : idx.count(); + req.onerror = eventRejectHandler(reject, ["calling", "count()", "on", self.name]); + req.onsuccess = function (e) { + resolve(e.target.result); + }; + }, cb); + } + }, + + sortBy: function (keyPath, cb) { + /// + var parts = keyPath.split('.').reverse(), + lastPart = parts[0], + lastIndex = parts.length - 1; + function getval(obj, i) { + if (i) return getval(obj[parts[i]], i - 1); + return obj[lastPart]; + } + var order = this._ctx.dir === "next" ? 1 : -1; + + function sorter(a, b) { + var aVal = getval(a, lastIndex), + bVal = getval(b, lastIndex); + return aVal < bVal ? -order : aVal > bVal ? order : 0; + } + return this.toArray(function (a) { + return a.sort(sorter); + }).then(cb); + }, + + toArray: function (cb) { + var ctx = this._ctx; + return this._read(function (resolve, reject, idbstore) { + fake && resolve([getInstanceTemplate(ctx)]); + var a = []; + iter(ctx, function (item) { + a.push(item); + }, function arrayComplete() { + resolve(a); + }, reject, idbstore); + }, cb); + }, + + offset: function (offset) { + var ctx = this._ctx; + if (offset <= 0) return this; + ctx.offset += offset; // For count() + if (!ctx.or && !ctx.algorithm && !ctx.filter && !ctx.replayFilter) { + addReplayFilter(ctx, function () { + var offsetLeft = offset; + return function offsetFilter(cursor, advance, resolve) { + if (offsetLeft === 0) return true; + if (offsetLeft === 1) { + --offsetLeft;return false; + } + advance(function () { + cursor.advance(offsetLeft);offsetLeft = 0; + }); + return false; + }; + }); + } else { + addReplayFilter(ctx, function () { + var offsetLeft = offset; + return function () { + return --offsetLeft < 0; + }; + }); + } + return this; + }, + + limit: function (numRows) { + this._ctx.limit = Math.min(this._ctx.limit, numRows); // For count() + addReplayFilter(this._ctx, function () { + var rowsLeft = numRows; + return function (cursor, advance, resolve) { + if (--rowsLeft <= 0) advance(resolve); // Stop after this item has been included + return rowsLeft >= 0; // If numRows is already below 0, return false because then 0 was passed to numRows initially. Otherwise we wouldnt come here. + }; + }); + return this; + }, + + until: function (filterFunction, bIncludeStopEntry) { + var ctx = this._ctx; + fake && filterFunction(getInstanceTemplate(ctx)); + addFilter(this._ctx, function (cursor, advance, resolve) { + if (filterFunction(cursor.value)) { + advance(resolve); + return bIncludeStopEntry; + } else { + return true; + } + }); + return this; + }, + + first: function (cb) { + return this.limit(1).toArray(function (a) { + return a[0]; + }).then(cb); + }, + + last: function (cb) { + return this.reverse().first(cb); + }, + + and: function (filterFunction) { + /// function(val){return true/false} + fake && filterFunction(getInstanceTemplate(this._ctx)); + addFilter(this._ctx, function (cursor) { + return filterFunction(cursor.value); + }); + addMatchFilter(this._ctx, filterFunction); // match filters not used in Dexie.js but can be used by 3rd part libraries to test a collection for a match without querying DB. Used by Dexie.Observable. + return this; + }, + + or: function (indexName) { + return new WhereClause(this._ctx.table, indexName, this); + }, + + reverse: function () { + this._ctx.dir = this._ctx.dir === "prev" ? "next" : "prev"; + if (this._ondirectionchange) this._ondirectionchange(this._ctx.dir); + return this; + }, + + desc: function () { + return this.reverse(); + }, + + eachKey: function (cb) { + var ctx = this._ctx; + fake && cb(getByKeyPath(getInstanceTemplate(this._ctx), this._ctx.index ? this._ctx.table.schema.idxByName[this._ctx.index].keyPath : this._ctx.table.schema.primKey.keyPath)); + ctx.keysOnly = true; + return this.each(function (val, cursor) { + cb(cursor.key, cursor); + }); + }, + + eachUniqueKey: function (cb) { + this._ctx.unique = "unique"; + return this.eachKey(cb); + }, + + keys: function (cb) { + var ctx = this._ctx; + ctx.keysOnly = true; + var a = []; + if (fake) return new Promise(this.eachKey.bind(this)).then(function (x) { + return [x]; + }).then(cb); + return this.each(function (item, cursor) { + a.push(cursor.key); + }).then(function () { + return a; + }).then(cb); + }, + + uniqueKeys: function (cb) { + this._ctx.unique = "unique"; + return this.keys(cb); + }, + + firstKey: function (cb) { + return this.limit(1).keys(function (a) { + return a[0]; + }).then(cb); + }, + + lastKey: function (cb) { + return this.reverse().firstKey(cb); + }, + + distinct: function () { + var ctx = this._ctx, + idx = ctx.index && ctx.table.schema.idxByName[ctx.index]; + if (!idx || !idx.multi) return this; // distinct() only makes differencies on multiEntry indexes. + var set = {}; + addFilter(this._ctx, function (cursor) { + var strKey = cursor.primaryKey.toString(); // Converts any Date to String, String to String, Number to String and Array to comma-separated string + var found = set.hasOwnProperty(strKey); + set[strKey] = true; + return !found; + }); + return this; + } + }; + }); + + // + // + // WriteableCollection Class + // + // + function WriteableCollection() { + Collection.apply(this, arguments); + } + + derive(WriteableCollection).from(Collection).extend({ + + // + // WriteableCollection Public Methods + // + + modify: function (changes) { + var self = this, + ctx = this._ctx, + hook = ctx.table.hook, + updatingHook = hook.updating.fire, + deletingHook = hook.deleting.fire; + + fake && typeof changes === 'function' && changes.call({ value: ctx.table.schema.instanceTemplate }, ctx.table.schema.instanceTemplate); + + return this._write(function (resolve, reject, idbstore, trans) { + var modifyer; + if (typeof changes === 'function') { + // Changes is a function that may update, add or delete propterties or even require a deletion the object itself (delete this.item) + if (updatingHook === nop && deletingHook === nop) { + // Noone cares about what is being changed. Just let the modifier function be the given argument as is. + modifyer = changes; + } else { + // People want to know exactly what is being modified or deleted. + // Let modifyer be a proxy function that finds out what changes the caller is actually doing + // and call the hooks accordingly! + modifyer = function (item) { + var origItem = deepClone(item); // Clone the item first so we can compare laters. + if (changes.call(this, item, this) === false) return false; // Call the real modifyer function (If it returns false explicitely, it means it dont want to modify anyting on this object) + if (!this.hasOwnProperty("value")) { + // The real modifyer function requests a deletion of the object. Inform the deletingHook that a deletion is taking place. + deletingHook.call(this, this.primKey, item, trans); + } else { + // No deletion. Check what was changed + var objectDiff = getObjectDiff(origItem, this.value); + var additionalChanges = updatingHook.call(this, objectDiff, this.primKey, origItem, trans); + if (additionalChanges) { + // Hook want to apply additional modifications. Make sure to fullfill the will of the hook. + item = this.value; + keys(additionalChanges).forEach(function (keyPath) { + setByKeyPath(item, keyPath, additionalChanges[keyPath]); // Adding {keyPath: undefined} means that the keyPath should be deleted. Handled by setByKeyPath + }); + } + } + }; + } + } else if (updatingHook === nop) { + // changes is a set of {keyPath: value} and no one is listening to the updating hook. + var keyPaths = keys(changes); + var numKeys = keyPaths.length; + modifyer = function (item) { + var anythingModified = false; + for (var i = 0; i < numKeys; ++i) { + var keyPath = keyPaths[i], + val = changes[keyPath]; + if (getByKeyPath(item, keyPath) !== val) { + setByKeyPath(item, keyPath, val); // Adding {keyPath: undefined} means that the keyPath should be deleted. Handled by setByKeyPath + anythingModified = true; + } + } + return anythingModified; + }; + } else { + // changes is a set of {keyPath: value} and people are listening to the updating hook so we need to call it and + // allow it to add additional modifications to make. + var origChanges = changes; + changes = shallowClone(origChanges); // Let's work with a clone of the changes keyPath/value set so that we can restore it in case a hook extends it. + modifyer = function (item) { + var anythingModified = false; + var additionalChanges = updatingHook.call(this, changes, this.primKey, deepClone(item), trans); + if (additionalChanges) extend(changes, additionalChanges); + keys(changes).forEach(function (keyPath) { + var val = changes[keyPath]; + if (getByKeyPath(item, keyPath) !== val) { + setByKeyPath(item, keyPath, val); + anythingModified = true; + } + }); + if (additionalChanges) changes = shallowClone(origChanges); // Restore original changes for next iteration + return anythingModified; + }; + } + + var count = 0; + var successCount = 0; + var iterationComplete = false; + var failures = []; + var failKeys = []; + var currentKey = null; + + function modifyItem(item, cursor, advance) { + currentKey = cursor.primaryKey; + var thisContext = { + primKey: cursor.primaryKey, + value: item, + onsuccess: null, + onerror: null + }; + + function onerror(e) { + failures.push(e); + failKeys.push(thisContext.primKey); + if (thisContext.onerror) Promise.newPSD(function () { + Promise.PSD.trans = trans; + thisContext.onerror(e); + }); + checkFinished(); + return true; // Catch these errors and let a final rejection decide whether or not to abort entire transaction + } + + if (modifyer.call(thisContext, item, thisContext) !== false) { + // If a callback explicitely returns false, do not perform the update! + var bDelete = !thisContext.hasOwnProperty("value"); + ++count; + miniTryCatch(function () { + var req = bDelete ? cursor.delete() : cursor.update(thisContext.value); + req.onerror = eventRejectHandler(onerror, bDelete ? ["deleting", item, "from", ctx.table.name] : ["modifying", item, "on", ctx.table.name]); + req.onsuccess = function (ev) { + if (thisContext.onsuccess) Promise.newPSD(function () { + Promise.PSD.trans = trans; + thisContext.onsuccess(thisContext.value); + }); + ++successCount; + checkFinished(); + }; + }, onerror); + } else if (thisContext.onsuccess) { + // Hook will expect either onerror or onsuccess to always be called! + thisContext.onsuccess(thisContext.value); + } + } + + function doReject(e) { + if (e) { + failures.push(e); + failKeys.push(currentKey); + } + return reject(new ModifyError("Error modifying one or more objects", failures, successCount, failKeys)); + } + + function checkFinished() { + if (iterationComplete && successCount + failures.length === count) { + if (failures.length > 0) doReject();else resolve(successCount); + } + } + self.clone().raw()._iterate(modifyItem, function () { + iterationComplete = true; + checkFinished(); + }, doReject, idbstore); + }); + }, + + 'delete': function () { + var _this2 = this; + + var ctx = this._ctx, + range = ctx.range, + deletingHook = ctx.table.hook.deleting.fire, + hasDeleteHook = deletingHook !== nop; + if (!hasDeleteHook && !ctx.or && !ctx.algorithm && !ctx.filter && !ctx.replayFilter && (ctx.isPrimKey && !hangsOnDeleteLargeKeyRange || !range)) // if no range, we'll use clear(). + { + // May use IDBObjectStore.delete(IDBKeyRange) in this case (Issue #208) + // For chromium, this is the way most optimized version. + // For IE/Edge, this could hang the indexedDB engine and make operating system instable + // (https://gist.github.com/dfahlander/5a39328f029de18222cf2125d56c38f7) + return this._write(function (resolve, reject, idbstore) { + // Our API contract is to return a count of deleted items, so we have to count() before delete(). + var onerror = eventRejectHandler(reject, ["deleting range from", ctx.table.name]); + var countReq = range ? idbstore.count(range) : idbstore.count(); + countReq.onerror = onerror; + countReq.onsuccess = function () { + var count = countReq.result; + miniTryCatch(function () { + var delReq = range ? idbstore.delete(range) : idbstore.clear(); + delReq.onerror = onerror; + delReq.onsuccess = function () { + return resolve(count); + }; + }, function (err) { + return reject(mapError(err)); + }); + }; + }); + } + + // Default version to use when collection is not a vanilla IDBKeyRange on the primary key. + // Divide into chunks to not starve RAM. + // If has delete hook, we will have to collect not just keys but also objects, so it will use + // more memory and need lower chunk size. + var CHUNKSIZE = hasDeleteHook ? 2000 : 10000; + + return this._write(function (resolve, reject, idbstore, trans) { + var totalCount = 0; + // Clone table and change the way transaction promises are generated. + // This is to be able to call other Collection methods within the same + // transaction even if the caller calls us without a transaction. + var table = Object.create(ctx.table); + table._tpf = trans._tpf; // Enable us to keep same transaction even if called without transaction. + // Clone collection and change its table and set a limit of CHUNKSIZE on the cloned Collection instance. + var collection = _this2.clone({ + table: table, // Execute in same transaction + keysOnly: !hasDeleteHook }) // load just keys (unless deleteHook has subscribers) + .distinct() // In case multiEntry is used, never delete same key twice because resulting count + // would become larger than actual delete count. + .limit(CHUNKSIZE).raw(); // Don't filter through reading-hooks (like mapped classes etc) + + var keysOrTuples = []; + + // We're gonna do things on as many chunks that are needed. + // Use recursion of nextChunk function: + var nextChunk = function () { + return collection.each(hasDeleteHook ? function (val, cursor) { + // Somebody subscribes to hook('deleting'). Collect all primary keys and their values, + // so that the hook can be called with its values in bulkDelete(). + keysOrTuples.push([cursor.primaryKey, cursor.value]); + } : function (val, cursor) { + // No one subscribes to hook('deleting'). Collect only primary keys: + keysOrTuples.push(cursor.primaryKey); + }).then(function () { + // Chromium deletes faster when doing it in sort order. + hasDeleteHook ? keysOrTuples.sort(function (a, b) { + return ascending(a[0], b[0]); + }) : keysOrTuples.sort(ascending); + return bulkDelete(idbstore, trans, keysOrTuples, hasDeleteHook, deletingHook); + }).then(function () { + var count = keysOrTuples.length; + totalCount += count; + keysOrTuples = []; + return count < CHUNKSIZE ? totalCount : nextChunk(); + }); + }; + + resolve(nextChunk()); + }); + } + }); + + // + // + // + // ------------------------- Help functions --------------------------- + // + // + // + + function lowerVersionFirst(a, b) { + return a._cfg.version - b._cfg.version; + } + + function setApiOnPlace(objs, transactionPromiseFactory, tableNames, mode, dbschema, enableProhibitedDB) { + tableNames.forEach(function (tableName) { + var tableInstance = db._tableFactory(mode, dbschema[tableName], transactionPromiseFactory); + objs.forEach(function (obj) { + if (!obj[tableName]) { + if (enableProhibitedDB) { + Object.defineProperty(obj, tableName, { + configurable: true, + enumerable: true, + get: function () { + var currentTrans = Promise.PSD && Promise.PSD.trans; + if (currentTrans && currentTrans.db === db) { + return currentTrans.tables[tableName]; + } + return tableInstance; + } + }); + } else { + obj[tableName] = tableInstance; + } + } + }); + }); + } + + function removeTablesApi(objs) { + objs.forEach(function (obj) { + for (var key in obj) { + if (obj[key] instanceof Table) delete obj[key]; + } + }); + } + + function iterate(req, filter, fn, resolve, reject, valueFilter) { + valueFilter = valueFilter || mirror; + if (!req.onerror) req.onerror = eventRejectHandler(reject); + if (filter) { + req.onsuccess = trycatch(function filter_record(e) { + var cursor = req.result; + if (cursor) { + var c = function () { + cursor.continue(); + }; + if (filter(cursor, function (advancer) { + c = advancer; + }, resolve, reject)) fn(valueFilter(cursor.value), cursor, function (advancer) { + c = advancer; + }); + c(); + } else { + resolve(); + } + }, reject); + } else { + req.onsuccess = trycatch(function filter_record(e) { + var cursor = req.result; + if (cursor) { + var c = function () { + cursor.continue(); + }; + fn(valueFilter(cursor.value), cursor, function (advancer) { + c = advancer; + }); + c(); + } else { + resolve(); + } + }, reject); + } + } + + function parseIndexSyntax(indexes) { + /// + /// + var rv = []; + indexes.split(',').forEach(function (index) { + index = index.trim(); + var name = index.replace("&", "").replace("++", "").replace("*", ""); + var keyPath = name.indexOf('[') !== 0 ? name : index.substring(index.indexOf('[') + 1, index.indexOf(']')).split('+'); + + rv.push(new IndexSpec(name, keyPath || null, index.indexOf('&') !== -1, index.indexOf('*') !== -1, index.indexOf("++") !== -1, isArray(keyPath), keyPath.indexOf('.') !== -1)); + }); + return rv; + } + + function cmp(key1, key2) { + return indexedDB.cmp(key1, key2); + } + + function min(a, b) { + return cmp(a, b) < 0 ? a : b; + } + + function max(a, b) { + return cmp(a, b) > 0 ? a : b; + } + + function ascending(a, b) { + return indexedDB.cmp(a, b); + } + + function descending(a, b) { + return indexedDB.cmp(b, a); + } + + function simpleCompare(a, b) { + return a < b ? -1 : a === b ? 0 : 1; + } + + function simpleCompareReverse(a, b) { + return a > b ? -1 : a === b ? 0 : 1; + } + + function combine(filter1, filter2) { + return filter1 ? filter2 ? function () { + return filter1.apply(this, arguments) && filter2.apply(this, arguments); + } : filter1 : filter2; + } + + function readGlobalSchema() { + db.verno = idbdb.version / 10; + db._dbSchema = globalSchema = {}; + dbStoreNames = slice(idbdb.objectStoreNames, 0); + if (dbStoreNames.length === 0) return; // Database contains no stores. + var trans = idbdb.transaction(safariMultiStoreFix(dbStoreNames), 'readonly'); + dbStoreNames.forEach(function (storeName) { + var store = trans.objectStore(storeName), + keyPath = store.keyPath, + dotted = keyPath && typeof keyPath === 'string' && keyPath.indexOf('.') !== -1; + var primKey = new IndexSpec(keyPath, keyPath || "", false, false, !!store.autoIncrement, keyPath && typeof keyPath !== 'string', dotted); + var indexes = []; + for (var j = 0; j < store.indexNames.length; ++j) { + var idbindex = store.index(store.indexNames[j]); + keyPath = idbindex.keyPath; + dotted = keyPath && typeof keyPath === 'string' && keyPath.indexOf('.') !== -1; + var index = new IndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== 'string', dotted); + indexes.push(index); + } + globalSchema[storeName] = new TableSchema(storeName, primKey, indexes, {}); + }); + setApiOnPlace([allTables], db._transPromiseFactory, keys(globalSchema), READWRITE, globalSchema); + } + + function adjustToExistingIndexNames(schema, idbtrans) { + /// + /// Issue #30 Problem with existing db - adjust to existing index names when migrating from non-dexie db + /// + /// Map between name and TableSchema + /// + var storeNames = idbtrans.db.objectStoreNames; + for (var i = 0; i < storeNames.length; ++i) { + var storeName = storeNames[i]; + var store = idbtrans.objectStore(storeName); + for (var j = 0; j < store.indexNames.length; ++j) { + var indexName = store.indexNames[j]; + var keyPath = store.index(indexName).keyPath; + var dexieName = typeof keyPath === 'string' ? keyPath : "[" + slice(keyPath).join('+') + "]"; + if (schema[storeName]) { + var indexSpec = schema[storeName].idxByName[dexieName]; + if (indexSpec) indexSpec.name = indexName; + } + } + } + } + + function fireOnBlocked(ev) { + db.on("blocked").fire(ev); + // Workaround (not fully*) for missing "versionchange" event in IE,Edge and Safari: + connections.filter(function (c) { + return c.name === db.name && c !== db && !c._vcFired; + }).map(function (c) { + return c.on("versionchange").fire(ev); + }); + } + + extend(this, { + Collection: Collection, + Table: Table, + Transaction: Transaction, + Version: Version, + WhereClause: WhereClause, + WriteableCollection: WriteableCollection, + WriteableTable: WriteableTable + }); + + init(); + + addons.forEach(function (fn) { + fn(db); + }); + } + + var fakeAutoComplete = function () {}; // Will never be changed. We just fake for the IDE that we change it (see doFakeAutoComplete()) + var fake = false; // Will never be changed. We just fake for the IDE that we change it (see doFakeAutoComplete()) + + function trycatch(fn, reject) { + var psd = Promise.PSD; + return function () { + var outerPSD = Promise.PSD; // Support Promise-specific data (PSD) in callback calls + Promise.PSD = psd; + try { + fn.apply(this, arguments); + } catch (e) { + reject(e); + } finally { + Promise.PSD = outerPSD; + } + }; + } + + function parseType(type) { + if (typeof type === 'function') { + return new type(); + } else if (isArray(type)) { + return [parseType(type[0])]; + } else if (type && typeof type === 'object') { + var rv = {}; + applyStructure(rv, type); + return rv; + } else { + return type; + } + } + + function applyStructure(obj, structure) { + keys(structure).forEach(function (member) { + var value = parseType(structure[member]); + obj[member] = value; + }); + return obj; + } + + function eventRejectHandler(reject, sentance) { + return function (event) { + var errObj = event && event.target.error || new Error(""); + if (sentance) { + var occurredWhen = " occurred when " + sentance.map(function (word) { + switch (typeof word) { + case 'function': + return word(); + case 'string': + return word; + default: + return JSON.stringify(word); + } + }).join(" "); + if (errObj.message && errObj.message != errObj.name) occurredWhen += ". " + errObj.message; + if (errObj.name) { + errObj = mapError(errObj, errObj.name + occurredWhen); + } else { + // Non-standard exceptions from IndexedDBPolyfill + errObj = errObj + occurredWhen; + } + }; + reject(errObj); + + if (event) { + // Old versions of IndexedDBShim doesnt provide an error event + // Stop error from propagating to IDBTransaction. Let us handle that manually instead. + if (event.stopPropagation) // IndexedDBShim doesnt support this + event.stopPropagation(); + if (event.preventDefault) // IndexedDBShim doesnt support this + event.preventDefault(); + } + + return false; + }; + } + + function preventDefault(e) { + e.preventDefault(); + } + + function globalDatabaseList(cb) { + var val, + localStorage = Dexie.dependencies.localStorage; + if (!localStorage) return cb([]); // Envs without localStorage support + try { + val = JSON.parse(localStorage.getItem('Dexie.DatabaseNames') || "[]"); + } catch (e) { + val = []; + } + if (cb(val)) { + localStorage.setItem('Dexie.DatabaseNames', JSON.stringify(val)); + } + } + + function awaitIterable(iterable) { + var callNext = function (result) { + return iterable.next(result); + }, + doThrow = function (error) { + return iterable.throw(error); + }, + onSuccess = step(callNext), + onError = step(doThrow); + + function step(getNext) { + return function (val) { + var next = getNext(val), + value = next.value; + + return next.done ? value : !value || typeof value.then !== 'function' ? Array.isArray(value) ? awaitAll(value, 0) : onSuccess(value) : value.then(onSuccess, onError); + }; + } + + function awaitAll(values, i) { + if (i === values.length) return onSuccess(values); + var value = values[i]; + return value.constructor && typeof value.constructor.all == 'function' ? value.constructor.all(values).then(onSuccess, onError) : awaitAll(values, i + 1); + } + + return step(callNext)(); + } + + // + // IndexSpec struct + // + function IndexSpec(name, keyPath, unique, multi, auto, compound, dotted) { + /// + /// + /// + /// + /// + /// + /// + this.name = name; + this.keyPath = keyPath; + this.unique = unique; + this.multi = multi; + this.auto = auto; + this.compound = compound; + this.dotted = dotted; + var keyPathSrc = typeof keyPath === 'string' ? keyPath : keyPath && '[' + [].join.call(keyPath, '+') + ']'; + this.src = (unique ? '&' : '') + (multi ? '*' : '') + (auto ? "++" : "") + keyPathSrc; + } + + // + // TableSchema struct + // + function TableSchema(name, primKey, indexes, instanceTemplate) { + /// + /// + /// + /// + this.name = name; + this.primKey = primKey || new IndexSpec(); + this.indexes = indexes || [new IndexSpec()]; + this.instanceTemplate = instanceTemplate; + this.mappedClass = null; + this.idxByName = indexes.reduce(function (hashSet, index) { + hashSet[index.name] = index; + return hashSet; + }, {}); + } + + // + // Static delete() method. + // + Dexie.delete = function (databaseName) { + var db = new Dexie(databaseName), + promise = db.delete(); + promise.onblocked = function (fn) { + db.on("blocked", fn); + return this; + }; + return promise; + }; + + // + // Static exists() method. + // + Dexie.exists = function (name) { + return new Dexie(name).open().then(function (db) { + db.close(); + return true; + }).catch(Dexie.NoSuchDatabaseError, function () { + return false; + }); + }; + + // + // Static method for retrieving a list of all existing databases at current host. + // + Dexie.getDatabaseNames = function (cb) { + return new Promise(function (resolve, reject) { + var getDatabaseNames = getNativeGetDatabaseNamesFn(indexedDB); + if (getDatabaseNames) { + // In case getDatabaseNames() becomes standard, let's prepare to support it: + var req = getDatabaseNames(); + req.onsuccess = function (event) { + resolve(slice(event.target.result, 0)); // Converst DOMStringList to Array + }; + req.onerror = eventRejectHandler(reject); + } else { + globalDatabaseList(function (val) { + resolve(val); + return false; + }); + } + }).then(cb); + }; + + Dexie.defineClass = function (structure) { + /// + /// Create a javascript constructor based on given template for which properties to expect in the class. + /// Any property that is a constructor function will act as a type. So {name: String} will be equal to {name: new String()}. + /// + /// Helps IDE code completion by knowing the members that objects contain and not just the indexes. Also + /// know what type each member has. Example: {name: String, emailAddresses: [String], properties: {shoeSize: Number}} + + // Default constructor able to copy given properties into this object. + function Class(properties) { + /// Properties to initialize object with. + /// + properties ? extend(this, properties) : fake && applyStructure(this, structure); + } + return Class; + }; + + Dexie.applyStructure = applyStructure; + + Dexie.ignoreTransaction = function (scopeFunc) { + // In case caller is within a transaction but needs to create a separate transaction. + // Example of usage: + // + // Let's say we have a logger function in our app. Other application-logic should be unaware of the + // logger function and not need to include the 'logentries' table in all transaction it performs. + // The logging should always be done in a separate transaction and not be dependant on the current + // running transaction context. Then you could use Dexie.ignoreTransaction() to run code that starts a new transaction. + // + // Dexie.ignoreTransaction(function() { + // db.logentries.add(newLogEntry); + // }); + // + // Unless using Dexie.ignoreTransaction(), the above example would try to reuse the current transaction + // in current Promise-scope. + // + // An alternative to Dexie.ignoreTransaction() would be setImmediate() or setTimeout(). The reason we still provide an + // API for this because + // 1) The intention of writing the statement could be unclear if using setImmediate() or setTimeout(). + // 2) setTimeout() would wait unnescessary until firing. This is however not the case with setImmediate(). + // 3) setImmediate() is not supported in the ES standard. + return Promise.newPSD(function () { + Promise.PSD.trans = null; + return scopeFunc(); + }); + }; + + Dexie.vip = function (fn) { + // To be used by subscribers to the on('ready') event. + // This will let caller through to access DB even when it is blocked while the db.ready() subscribers are firing. + // This would have worked automatically if we were certain that the Provider was using Dexie.Promise for all asyncronic operations. The promise PSD + // from the provider.connect() call would then be derived all the way to when provider would call localDatabase.applyChanges(). But since + // the provider more likely is using non-promise async APIs or other thenable implementations, we cannot assume that. + // Note that this method is only useful for on('ready') subscribers that is returning a Promise from the event. If not using vip() + // the database could deadlock since it wont open until the returned Promise is resolved, and any non-VIPed operation started by + // the caller will not resolve until database is opened. + return Promise.newPSD(function () { + Promise.PSD.letThrough = true; // Make sure we are let through if still blocking db due to onready is firing. + return fn(); + }); + }; + + Dexie.async = function (generatorFn) { + return function () { + try { + var rv = awaitIterable(generatorFn.apply(this, arguments)); + if (!rv || typeof rv.then !== 'function') return Dexie.Promise.resolve(rv); + return rv; + } catch (e) { + return Dexie.Promise.reject(e); + } + }; + }; + + Dexie.spawn = function (generatorFn, args, thiz) { + try { + var rv = awaitIterable(generatorFn.apply(thiz, args || [])); + if (!rv || typeof rv.then !== 'function') return Dexie.Promise.resolve(rv); + return rv; + } catch (e) { + return Dexie.Promise.reject(e); + } + }; + + // Dexie.currentTransaction property. Only applicable for transactions entered using the new "transact()" method. + Object.defineProperty(Dexie, "currentTransaction", { + get: function () { + /// + return Promise.PSD && Promise.PSD.trans || null; + } + }); + + function safariMultiStoreFix(storeNames) { + return storeNames.length === 1 ? storeNames[0] : storeNames; + } + + // Export our Promise implementation since it can be handy as a standalone Promise implementation + Dexie.Promise = Promise; + // Export our derive/extend/override methodology + Dexie.derive = derive; + Dexie.extend = extend; + Dexie.override = override; + // Export our Events() function - can be handy as a toolkit + Dexie.Events = Dexie.events = Events; // Backward compatible lowercase version. + // Utilities + Dexie.getByKeyPath = getByKeyPath; + Dexie.setByKeyPath = setByKeyPath; + Dexie.delByKeyPath = delByKeyPath; + Dexie.shallowClone = shallowClone; + Dexie.deepClone = deepClone; + Dexie.addons = []; + Dexie.fakeAutoComplete = fakeAutoComplete; + Dexie.asap = asap; + Dexie.maxKey = maxKey; + Dexie.connections = connections; + + // Export Error classes + extend(Dexie, fullNameExceptions); // Dexie.XXXError = class XXXError {...}; + Dexie.MultiModifyError = Dexie.ModifyError; // Backward compatibility 0.9.8 + Dexie.errnames = errnames; + + // Export other static classes + Dexie.IndexSpec = IndexSpec; + Dexie.TableSchema = TableSchema; + + // + // Dependencies + // + // These will automatically work in browsers with indexedDB support, or where an indexedDB polyfill has been included. + // + // In node.js, however, these properties must be set "manually" before instansiating a new Dexie(). For node.js, you need to require indexeddb-js or similar and then set these deps. + // + var idbshim = _global.idbModules && _global.idbModules.shimIndexedDB ? _global.idbModules : {}; + Dexie.dependencies = { + // Required: + indexedDB: idbshim.shimIndexedDB || _global.indexedDB || _global.mozIndexedDB || _global.webkitIndexedDB || _global.msIndexedDB, + IDBKeyRange: idbshim.IDBKeyRange || _global.IDBKeyRange || _global.webkitIDBKeyRange + }; + miniTryCatch(function () { + // Optional dependencies + // localStorage + Dexie.dependencies.localStorage = (typeof chrome !== "undefined" && chrome !== null ? chrome.storage : void 0) != null ? null : _global.localStorage; + }); + + // API Version Number: Type Number, make sure to always set a version number that can be comparable correctly. Example: 0.9, 0.91, 0.92, 1.0, 1.01, 1.1, 1.2, 1.21, etc. + Dexie.semVer = "1.3.6-beta.1"; + Dexie.version = Dexie.semVer.split('.').map(function (n) { + return parseInt(n); + }).reduce(function (p, c, i) { + return p + c / Math.pow(10, i * 2); + }); + + function getNativeGetDatabaseNamesFn(indexedDB) { + var fn = indexedDB && (indexedDB.getDatabaseNames || indexedDB.webkitGetDatabaseNames); + return fn && fn.bind(indexedDB); + } + + // Fool IDE to improve autocomplete. Tested with Visual Studio 2013 and 2015. + doFakeAutoComplete(function () { + Dexie.fakeAutoComplete = fakeAutoComplete = doFakeAutoComplete; + Dexie.fake = fake = true; + }); + + // https://github.com/dfahlander/Dexie.js/issues/186 + // typescript compiler tsc in mode ts-->es5 & commonJS, will expect require() to return + // x.default. Workaround: Set Dexie.default = Dexie. + Dexie.default = Dexie; + + return Dexie; + +})); +//# sourceMappingURL=dexie.js.map \ No newline at end of file diff --git a/dist/dexie.js.map b/dist/dexie.js.map new file mode 100644 index 000000000..669eab0c4 --- /dev/null +++ b/dist/dexie.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dexie.js","sources":["../C:/repos/dexie-release/tools/tmp/src/utils.js","../C:/repos/dexie-release/tools/tmp/src/chaining-functions.js","../C:/repos/dexie-release/tools/tmp/src/errors.js","../C:/repos/dexie-release/tools/tmp/src/Events.js","../C:/repos/dexie-release/tools/tmp/src/Promise.js","../C:/repos/dexie-release/tools/tmp/src/Dexie.js"],"sourcesContent":["/*\r\n* Dexie.js - a minimalistic wrapper for IndexedDB\r\n* ===============================================\r\n*\r\n* By David Fahlander, david.fahlander@gmail.com\r\n*\r\n* Version {version}, {date}\r\n* www.dexie.com\r\n* Apache License Version 2.0, January 2004, http://www.apache.org/licenses/\r\n*/\nimport Promise from './Promise';\n\nexport var keys = Object.keys;\nexport var isArray = Array.isArray;\nexport var _global = typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : global;\n\nexport function extend(obj, extension) {\n if (typeof extension !== 'object') extension = extension(); // Allow to supply a function returning the extension. Useful for simplifying private scopes.\n keys(extension).forEach(function (key) {\n obj[key] = extension[key];\n });\n return obj;\n}\n\nexport function derive(Child) {\n return {\n from: function (Parent) {\n Child.prototype = Object.create(Parent.prototype);\n Child.prototype.constructor = Child;\n return {\n extend: function (extension) {\n extend(Child.prototype, typeof extension !== 'object' ? extension(Parent.prototype) : extension);\n }\n };\n }\n };\n}\n\nvar _slice = [].slice;\nexport function slice(args, start, end) {\n return _slice.call(args, start, end);\n}\n\nexport function override(origFunc, overridedFactory) {\n return overridedFactory(origFunc);\n}\n\nexport function doFakeAutoComplete(fn) {\n var to = setTimeout(fn, 1000);\n clearTimeout(to);\n}\n\nexport function assert(b) {\n if (!b) throw new exceptions.Internal(\"Assertion failed\");\n}\n\nexport function asap(fn) {\n if (_global.setImmediate) setImmediate(fn);else setTimeout(fn, 0);\n}\n\nexport function miniTryCatch(fn, onerror) {\n try {\n fn();\n } catch (ex) {\n onerror && onerror(ex);\n }\n}\n\nexport function fail(err) {\n // Get the call stack and return a rejected promise.\n try {\n throw err;\n } catch (e) {\n return Promise.reject(err);\n }\n}\n\nexport function getByKeyPath(obj, keyPath) {\n // http://www.w3.org/TR/IndexedDB/#steps-for-extracting-a-key-from-a-value-using-a-key-path\n if (obj.hasOwnProperty(keyPath)) return obj[keyPath]; // This line is moved from last to first for optimization purpose.\n if (!keyPath) return obj;\n if (typeof keyPath !== 'string') {\n var rv = [];\n for (var i = 0, l = keyPath.length; i < l; ++i) {\n var val = getByKeyPath(obj, keyPath[i]);\n rv.push(val);\n }\n return rv;\n }\n var period = keyPath.indexOf('.');\n if (period !== -1) {\n var innerObj = obj[keyPath.substr(0, period)];\n return innerObj === undefined ? undefined : getByKeyPath(innerObj, keyPath.substr(period + 1));\n }\n return undefined;\n}\n\nexport function setByKeyPath(obj, keyPath, value) {\n if (!obj || keyPath === undefined) return;\n if ('isFrozen' in Object && Object.isFrozen(obj)) return;\n if (typeof keyPath !== 'string' && 'length' in keyPath) {\n assert(typeof value !== 'string' && 'length' in value);\n for (var i = 0, l = keyPath.length; i < l; ++i) {\n setByKeyPath(obj, keyPath[i], value[i]);\n }\n } else {\n var period = keyPath.indexOf('.');\n if (period !== -1) {\n var currentKeyPath = keyPath.substr(0, period);\n var remainingKeyPath = keyPath.substr(period + 1);\n if (remainingKeyPath === \"\") {\n if (value === undefined) delete obj[currentKeyPath];else obj[currentKeyPath] = value;\n } else {\n var innerObj = obj[currentKeyPath];\n if (!innerObj) innerObj = obj[currentKeyPath] = {};\n setByKeyPath(innerObj, remainingKeyPath, value);\n }\n } else {\n if (value === undefined) delete obj[keyPath];else obj[keyPath] = value;\n }\n }\n}\n\nexport function delByKeyPath(obj, keyPath) {\n if (typeof keyPath === 'string') setByKeyPath(obj, keyPath, undefined);else if ('length' in keyPath) [].map.call(keyPath, function (kp) {\n setByKeyPath(obj, kp, undefined);\n });\n}\n\nexport function shallowClone(obj) {\n var rv = {};\n for (var m in obj) {\n if (obj.hasOwnProperty(m)) rv[m] = obj[m];\n }\n return rv;\n}\n\nexport function deepClone(any) {\n if (!any || typeof any !== 'object') return any;\n var rv;\n if (isArray(any)) {\n rv = [];\n for (var i = 0, l = any.length; i < l; ++i) {\n rv.push(deepClone(any[i]));\n }\n } else if (any instanceof Date) {\n rv = new Date();\n rv.setTime(any.getTime());\n } else {\n rv = any.constructor ? Object.create(any.constructor.prototype) : {};\n for (var prop in any) {\n if (any.hasOwnProperty(prop)) {\n rv[prop] = deepClone(any[prop]);\n }\n }\n }\n return rv;\n}\n\nexport function getObjectDiff(a, b, rv, prfx) {\n // This is a simplified version that will always return keypaths on the root level.\n // If for example a and b differs by: (a.somePropsObject.x != b.somePropsObject.x), we will return that \"somePropsObject\" is changed\n // and not \"somePropsObject.x\". This is acceptable and true but could be optimized to support nestled changes if that would give a\n // big optimization benefit.\n rv = rv || {};\n prfx = prfx || '';\n for (var prop in a) {\n if (a.hasOwnProperty(prop)) {\n if (!b.hasOwnProperty(prop)) rv[prfx + prop] = undefined; // Property removed\n else {\n var ap = a[prop],\n bp = b[prop];\n if (typeof ap === 'object' && typeof bp === 'object') getObjectDiff(ap, bp, rv, prfx + prop + \".\");else if (ap !== bp) rv[prfx + prop] = b[prop]; // Primitive value changed\n }\n }\n }for (var prop in b) {\n if (b.hasOwnProperty(prop) && !a.hasOwnProperty(prop)) {\n rv[prfx + prop] = b[prop]; // Property added\n }\n }return rv;\n}\n\nexport function idbp(idbOperation) {\n return new Promise(function (resolve, reject) {\n var req = idbOperation();\n req.onerror = reject;\n req.onsuccess = resolve;\n });\n}","import { extend } from './utils';\n\nexport function nop() {}\nexport function mirror(val) {\n return val;\n}\nexport function pureFunctionChain(f1, f2) {\n // Enables chained events that takes ONE argument and returns it to the next function in chain.\n // This pattern is used in the hook(\"reading\") event.\n if (f1 == null || f1 === mirror) return f2;\n return function (val) {\n return f2(f1(val));\n };\n}\n\nexport function callBoth(on1, on2) {\n return function () {\n on1.apply(this, arguments);\n on2.apply(this, arguments);\n };\n}\n\nexport function hookCreatingChain(f1, f2) {\n // Enables chained events that takes several arguments and may modify first argument by making a modification and then returning the same instance.\n // This pattern is used in the hook(\"creating\") event.\n if (f1 === nop) return f2;\n return function () {\n var res = f1.apply(this, arguments);\n if (res !== undefined) arguments[0] = res;\n var onsuccess = this.onsuccess,\n // In case event listener has set this.onsuccess\n onerror = this.onerror; // In case event listener has set this.onerror\n this.onsuccess = null;\n this.onerror = null;\n var res2 = f2.apply(this, arguments);\n if (onsuccess) this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;\n if (onerror) this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;\n return res2 !== undefined ? res2 : res;\n };\n}\n\nexport function hookDeletingChain(f1, f2) {\n if (f1 === nop) return f2;\n return function () {\n f1.apply(this, arguments);\n var onsuccess = this.onsuccess,\n // In case event listener has set this.onsuccess\n onerror = this.onerror; // In case event listener has set this.onerror\n this.onsuccess = this.onerror = null;\n f2.apply(this, arguments);\n if (onsuccess) this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;\n if (onerror) this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;\n };\n}\n\nexport function hookUpdatingChain(f1, f2) {\n if (f1 === nop) return f2;\n return function () {\n var res = f1.apply(this, arguments);\n if (res !== undefined) extend(arguments[0], res); // If f1 returns new modifications, extend caller's modifications with the result before calling next in chain.\n var onsuccess = this.onsuccess,\n // In case event listener has set this.onsuccess\n onerror = this.onerror; // In case event listener has set this.onerror\n this.onsuccess = null;\n this.onerror = null;\n var res2 = f2.apply(this, arguments);\n if (onsuccess) this.onsuccess = this.onsuccess ? callBoth(onsuccess, this.onsuccess) : onsuccess;\n if (onerror) this.onerror = this.onerror ? callBoth(onerror, this.onerror) : onerror;\n return res === undefined ? res2 === undefined ? undefined : res2 : res2 === undefined ? res : extend(res, res2);\n };\n}\n\nexport function stoppableEventChain(f1, f2) {\n // Enables chained events that may return false to stop the event chain.\n if (f1 === nop) return f2;\n return function () {\n if (f1.apply(this, arguments) === false) return false;\n return f2.apply(this, arguments);\n };\n}\n\nexport function reverseStoppableEventChain(f1, f2) {\n if (f1 === nop) return f2;\n return function () {\n if (f2.apply(this, arguments) === false) return false;\n return f1.apply(this, arguments);\n };\n}\n\nexport function nonStoppableEventChain(f1, f2) {\n if (f1 === nop) return f2;\n return function () {\n f1.apply(this, arguments);\n f2.apply(this, arguments);\n };\n}\n\nexport function promisableChain(f1, f2) {\n if (f1 === nop) return f2;\n return function () {\n var res = f1.apply(this, arguments);\n if (res && typeof res.then === 'function') {\n var thiz = this,\n args = arguments;\n return res.then(function () {\n return f2.apply(thiz, args);\n });\n }\n return f2.apply(this, arguments);\n };\n}","import { derive } from './utils';\n\nvar dexieErrorNames = ['Modify', 'Bulk', 'OpenFailed', 'VersionChange', 'Schema', 'Upgrade', 'InvalidTable', 'MissingAPI', 'NoSuchDatabase', 'InvalidArgument', 'SubTransaction', 'Unsupported', 'Internal', 'DatabaseClosed'];\n\nvar idbDomErrorNames = ['Unknown', 'Constraint', 'Data', 'TransactionInactive', 'ReadOnly', 'Version', 'NotFound', 'InvalidState', 'InvalidAccess', 'Abort', 'Timeout', 'QuotaExceeded', 'Syntax', 'DataClone'];\n\nvar errorList = dexieErrorNames.concat(idbDomErrorNames);\n\nvar defaultTexts = {\n VersionChanged: \"Database version changed by other database connection\",\n DatabaseClosed: \"Database has been closed\"\n};\n\n//\n// DexieError - base class of all out exceptions.\n//\nexport function DexieError(name, msg) {\n // Reason we don't use ES6 classes is because:\n // 1. It bloats transpiled code and increases size of minified code.\n // 2. It doesn't give us much in this case.\n // 3. It would require sub classes to call super(), which\n // is not needed when deriving from Error.\n this.name = name;\n this.message = msg;\n}\nderive(DexieError).from(Error);\n\nfunction getMultiErrorMessage(msg, failures) {\n return msg + \". Errors: \" + failures.map(function (f) {\n return f.toString();\n }).filter(function (v, i, s) {\n return s.indexOf(v) === i;\n }) // Only unique error strings\n .join('\\n');\n}\n//\n// ModifyError - thrown in WriteableCollection.modify()\n// Specific constructor because it contains members failures and failedKeys.\n//\nexport function ModifyError(msg, failures, successCount, failedKeys) {\n this.name = \"ModifyError\";\n this.failures = failures;\n this.failedKeys = failedKeys;\n this.successCount = successCount;\n this.message = getMultiErrorMessage(msg, failures);\n}\nderive(ModifyError).from(DexieError);\n\nexport function BulkError(msg, failures) {\n this.name = \"BulkError\";\n this.failures = failures;\n this.message = getMultiErrorMessage(msg, failures);\n}\nderive(BulkError).from(DexieError);\n\n//\n//\n// Dynamically generate error names and exception classes based\n// on the names in errorList.\n//\n//\n\n// Map of {ErrorName -> ErrorName + \"Error\"}\nexport var errnames = errorList.reduce(function (obj, name) {\n return obj[name] = name + \"Error\", obj;\n}, {});\n\n// Need an alias for DexieError because we're gonna create subclasses with the same name.\nvar BaseException = DexieError;\n// Map of {ErrorName -> exception constructor}\nexport var exceptions = errorList.reduce(function (obj, name) {\n // Let the name be \"DexieError\" because this name may\n // be shown in call stack and when debugging. DexieError is\n // the most true name because it derives from DexieError,\n // and we cannot change Function.name programatically without\n // dynamically create a Function object, which would be considered\n // 'eval-evil'.\n var fullName = name + \"Error\";\n function DexieError(msgOrInner, inner) {\n this.name = fullName;\n if (typeof msgOrInner === 'string') {\n this.message = msgOrInner;\n this.inner = inner || null;\n } else if (typeof msgOrInner === 'object') {\n this.message = msgOrInner.name + ' ' + msgOrInner.message;\n this.inner = msgOrInner;\n } else {\n this.message = defaultTexts[name];\n this.inner = null;\n }\n }\n derive(DexieError).from(BaseException);\n obj[name] = DexieError;\n return obj;\n}, {});\n\n// Use ECMASCRIPT standard exceptions where applicable:\nexceptions.Syntax = SyntaxError;\nexceptions.Type = TypeError;\nexceptions.Range = RangeError;\n\nexport var exceptionMap = idbDomErrorNames.reduce(function (obj, name) {\n obj[name + \"Error\"] = exceptions[name];\n return obj;\n}, {});\n\nexport function mapError(domError, message) {\n var rv = domError;\n if (!(domError instanceof DexieError) && domError.name && exceptionMap[domError.name]) {\n rv = new exceptionMap[domError.name](message || domError.message, domError);\n if (domError.stack) rv.stack = domError.stack;\n }\n return rv;\n}\n\nexport function stack(error) {\n if (error.stack) return error;\n try {\n throw new Error();\n } catch (e) {\n error.stack = e.stack;\n }\n return error;\n}\n\nexport var fullNameExceptions = errorList.reduce(function (obj, name) {\n if ([\"Syntax\", \"Type\", \"Range\"].indexOf(name) === -1) obj[name + \"Error\"] = exceptions[name];\n return obj;\n}, {});\n\nfullNameExceptions.ModifyError = ModifyError;\nfullNameExceptions.DexieError = DexieError;\nfullNameExceptions.BulkError = BulkError;","import { slice, keys, isArray, asap, _global } from './utils';\nimport { nop, stoppableEventChain } from './chaining-functions';\nimport { exceptions } from './errors';\n\nexport default function Events(ctx, eventNames) {\n var args = arguments;\n var evs = {};\n var rv = function (eventName, subscriber) {\n if (subscriber) {\n // Subscribe\n var args = slice(arguments, 1);\n var ev = evs[eventName];\n ev.subscribe.apply(ev, args);\n return ctx;\n } else if (typeof eventName === 'string') {\n // Return interface allowing to fire or unsubscribe from event\n return evs[eventName];\n }\n };\n rv.addEventType = add;\n\n function add(eventName, chainFunction, defaultFunction) {\n if (isArray(eventName)) return addEventGroup(eventName);\n if (typeof eventName === 'object') return addConfiguredEvents(eventName);\n if (!chainFunction) chainFunction = stoppableEventChain;\n if (!defaultFunction) defaultFunction = nop;\n\n var context = {\n subscribers: [],\n fire: defaultFunction,\n subscribe: function (cb) {\n context.subscribers.push(cb);\n context.fire = chainFunction(context.fire, cb);\n },\n unsubscribe: function (cb) {\n context.subscribers = context.subscribers.filter(function (fn) {\n return fn !== cb;\n });\n context.fire = context.subscribers.reduce(chainFunction, defaultFunction);\n }\n };\n evs[eventName] = rv[eventName] = context;\n return context;\n }\n\n function addConfiguredEvents(cfg) {\n // events(this, {reading: [functionChain, nop]});\n keys(cfg).forEach(function (eventName) {\n var args = cfg[eventName];\n if (isArray(args)) {\n add(eventName, cfg[eventName][0], cfg[eventName][1]);\n } else if (args === 'asap') {\n // Rather than approaching event subscription using a functional approach, we here do it in a for-loop where subscriber is executed in its own stack\n // enabling that any exception that occur wont disturb the initiator and also not nescessary be catched and forgotten.\n var context = add(eventName, null, function fire() {\n var args = arguments;\n context.subscribers.forEach(function (fn) {\n asap(function fireEvent() {\n fn.apply(_global, args);\n });\n });\n });\n context.subscribe = function (fn) {\n // Change how subscribe works to not replace the fire function but to just add the subscriber to subscribers\n if (context.subscribers.indexOf(fn) === -1) context.subscribers.push(fn);\n };\n context.unsubscribe = function (fn) {\n // Change how unsubscribe works for the same reason as above.\n var idxOfFn = context.subscribers.indexOf(fn);\n if (idxOfFn !== -1) context.subscribers.splice(idxOfFn, 1);\n };\n } else throw new exceptions.InvalidArgument(\"Invalid event config\");\n });\n }\n\n function addEventGroup(eventGroup) {\n // promise-based event group (i.e. we promise to call one and only one of the events in the pair, and to only call it once.\n var done = false;\n eventGroup.forEach(function (name) {\n add(name).subscribe(checkDone);\n });\n function checkDone() {\n if (done) return false;\n done = true;\n }\n }\n\n for (var i = 1, l = args.length; i < l; ++i) {\n add(args[i]);\n }\n\n return rv;\n}","import { _global, slice, isArray, doFakeAutoComplete } from './utils';\nimport { nop } from './chaining-functions';\nimport Events from './Events';\n\n//\n// Promise Class\n//\n// A variant of promise-light (https://github.com/taylorhakes/promise-light) by https://github.com/taylorhakes - an A+ and ECMASCRIPT 6 compliant Promise implementation.\n//\n// Modified by David Fahlander to be indexedDB compliant (See discussion: https://github.com/promises-aplus/promises-spec/issues/45) .\n// This implementation will not use setTimeout or setImmediate when it's not needed. The behavior is 100% Promise/A+ compliant since\n// the caller of new Promise() can be certain that the promise wont be triggered the lines after constructing the promise. We fix this by using the member variable constructing to check\n// whether the object is being constructed when reject or resolve is called. If so, the use setTimeout/setImmediate to fulfill the promise, otherwise, we know that it's not needed.\n//\n// This topic was also discussed in the following thread: https://github.com/promises-aplus/promises-spec/issues/45 and this implementation solves that issue.\n//\n// Another feature with this Promise implementation is that reject will return false in case no one catched the reject call. This is used\n// to stopPropagation() on the IDBRequest error event in case it was catched but not otherwise.\n//\n// Also, the event new Promise().onuncatched is called in case no one catches a reject call. This is used for us to manually bubble any request\n// errors to the transaction. We must not rely on IndexedDB implementation to do this, because it only does so when the source of the rejection\n// is an error event on a request, not in case an ordinary exception is thrown.\n\nvar _asap = _global.setImmediate || function (fn) {\n var args = slice(arguments, 1);\n\n // If not FF13 and earlier failed, we could use this call here instead: setTimeout.call(this, [fn, 0].concat(arguments));\n setTimeout(function () {\n fn.apply(_global, args);\n }, 0);\n};\n\ndoFakeAutoComplete(function () {\n // Simplify the job for VS Intellisense. This piece of code is one of the keys to the new marvellous intellisense support in Dexie.\n _asap = asap = enqueueImmediate = function (fn) {\n var args = arguments;setTimeout(function () {\n fn.apply(_global, slice(args, 1));\n }, 0);\n };\n});\n\nvar asap = _asap,\n isRootExecution = true;\n\nvar operationsQueue = [];\nvar tickFinalizers = [];\nfunction enqueueImmediate(fn, args) {\n operationsQueue.push([fn, slice(arguments, 1)]);\n}\n\nfunction executeOperationsQueue() {\n var queue = operationsQueue;\n operationsQueue = [];\n for (var i = 0, l = queue.length; i < l; ++i) {\n var item = queue[i];\n item[0].apply(_global, item[1]);\n }\n}\n\nexport default function Promise(fn) {\n if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new');\n if (typeof fn !== 'function') throw new TypeError('not a function');\n this._state = null; // null (=pending), false (=rejected) or true (=resolved)\n this._value = null; // error or result\n this._deferreds = [];\n this._catched = false; // for onuncatched\n //this._id = ++PromiseID;\n var self = this;\n var constructing = true;\n this._PSD = Promise.PSD;\n\n try {\n doResolve(this, fn, function (data) {\n if (constructing) asap(resolve, self, data);else resolve(self, data);\n }, function (reason) {\n if (constructing) {\n asap(reject, self, reason);\n return false;\n } else {\n return reject(self, reason);\n }\n });\n } finally {\n constructing = false;\n }\n}\n\nfunction handle(self, deferred) {\n if (self._state === null) {\n self._deferreds.push(deferred);\n return;\n }\n\n var cb = self._state ? deferred.onFulfilled : deferred.onRejected;\n if (cb === null) {\n // This Deferred doesnt have a listener for the event being triggered (onFulfilled or onReject) so lets forward the event to any eventual listeners on the Promise instance returned by then() or catch()\n return (self._state ? deferred.resolve : deferred.reject)(self._value);\n }\n var ret,\n isRootExec = isRootExecution;\n isRootExecution = false;\n asap = enqueueImmediate;\n try {\n var outerPSD = Promise.PSD;\n Promise.PSD = self._PSD;\n ret = cb(self._value);\n if (!self._state && (!ret || typeof ret.then !== 'function' || ret._state !== false)) setCatched(self); // Caller did 'return Promise.reject(err);' - don't regard it as catched!\n deferred.resolve(ret);\n } catch (e) {\n deferred.reject(e);\n } finally {\n Promise.PSD = outerPSD;\n if (isRootExec) {\n do {\n while (operationsQueue.length > 0) {\n executeOperationsQueue();\n }var finalizer = tickFinalizers.pop();\n if (finalizer) try {\n finalizer();\n } catch (e) {}\n } while (tickFinalizers.length > 0 || operationsQueue.length > 0);\n asap = _asap;\n isRootExecution = true;\n }\n }\n}\n\nfunction _rootExec(fn) {\n var isRootExec = isRootExecution;\n isRootExecution = false;\n asap = enqueueImmediate;\n try {\n return fn();\n } finally {\n if (isRootExec) {\n do {\n while (operationsQueue.length > 0) {\n executeOperationsQueue();\n }var finalizer = tickFinalizers.pop();\n if (finalizer) try {\n finalizer();\n } catch (e) {}\n } while (tickFinalizers.length > 0 || operationsQueue.length > 0);\n asap = _asap;\n isRootExecution = true;\n }\n }\n}\n\nfunction setCatched(promise) {\n promise._catched = true;\n if (promise._parent && !promise._parent._catched) setCatched(promise._parent);\n}\n\nfunction resolve(promise, newValue) {\n var outerPSD = Promise.PSD;\n Promise.PSD = promise._PSD;\n try {\n //Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure\n if (newValue === promise) throw new TypeError('A promise cannot be resolved with itself.');\n if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {\n if (typeof newValue.then === 'function') {\n if (newValue instanceof Promise && newValue._state !== null) {\n promise._state = newValue._state;\n promise._value = newValue._value;\n finale.call(promise);\n return;\n }\n doResolve(promise, function (resolve, reject) {\n //newValue instanceof Promise ? newValue._then(resolve, reject) : newValue.then(resolve, reject);\n newValue.then(resolve, reject);\n }, function (data) {\n resolve(promise, data);\n }, function (reason) {\n reject(promise, reason);\n });\n return;\n }\n }\n promise._state = true;\n promise._value = newValue;\n finale.call(promise);\n } catch (e) {\n reject(e);\n } finally {\n Promise.PSD = outerPSD;\n }\n}\n\nfunction reject(promise, newValue) {\n var outerPSD = Promise.PSD;\n Promise.PSD = promise._PSD;\n promise._state = false;\n promise._value = newValue;\n\n finale.call(promise);\n if (!promise._catched) {\n try {\n if (promise.onuncatched) promise.onuncatched(promise._value);else Promise.on.error.fire(promise._value);\n } catch (e) {}\n }\n Promise.PSD = outerPSD;\n return promise._catched;\n}\n\nfunction finale() {\n for (var i = 0, len = this._deferreds.length; i < len; i++) {\n handle(this, this._deferreds[i]);\n }\n this._deferreds = [];\n}\n\nfunction Deferred(onFulfilled, onRejected, resolve, reject) {\n this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;\n this.onRejected = typeof onRejected === 'function' ? onRejected : null;\n this.resolve = resolve;\n this.reject = reject;\n}\n\n/**\r\n * Take a potentially misbehaving resolver function and make sure\r\n * onFulfilled and onRejected are only called once.\r\n *\r\n * Makes no guarantees about asynchrony.\r\n */\nfunction doResolve(promise, fn, onFulfilled, onRejected) {\n var done = false;\n try {\n fn(function Promise_resolve(value) {\n if (done) return;\n done = true;\n onFulfilled(value);\n }, function Promise_reject(reason) {\n if (done) return promise._catched;\n done = true;\n return onRejected(reason);\n });\n } catch (ex) {\n if (done) return;\n return onRejected(ex);\n }\n}\n\nPromise.all = function () {\n var args = slice(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments);\n\n return new Promise(function (resolve, reject) {\n if (args.length === 0) return resolve([]);\n var remaining = args.length;\n function res(i, val) {\n try {\n if (val && (typeof val === 'object' || typeof val === 'function')) {\n var then = val.then;\n if (typeof then === 'function') {\n then.call(val, function (val) {\n res(i, val);\n }, reject);\n return;\n }\n }\n args[i] = val;\n if (--remaining === 0) {\n resolve(args);\n }\n } catch (ex) {\n reject(ex);\n }\n }\n for (var i = 0; i < args.length; i++) {\n res(i, args[i]);\n }\n });\n};\n\n/* Prototype Methods */\nPromise.prototype.then = function (onFulfilled, onRejected) {\n var self = this;\n var p = new Promise(function (resolve, reject) {\n if (self._state === null) handle(self, new Deferred(onFulfilled, onRejected, resolve, reject));else asap(handle, self, new Deferred(onFulfilled, onRejected, resolve, reject));\n });\n p._PSD = this._PSD;\n p.onuncatched = this.onuncatched; // Needed when exception occurs in a then() clause of a successful parent promise. Want onuncatched to be called even in callbacks of callbacks of the original promise.\n p._parent = this; // Used for recursively calling onuncatched event on self and all parents.\n return p;\n};\n\nPromise.prototype._then = function (onFulfilled, onRejected) {\n handle(this, new Deferred(onFulfilled, onRejected, nop, nop));\n};\n\nPromise.prototype['catch'] = function (onRejected) {\n if (arguments.length === 1) return this.then(null, onRejected);\n // First argument is the Error type to catch\n var type = arguments[0],\n callback = arguments[1];\n if (typeof type === 'function') return this.then(null, function (e) {\n // Catching errors by its constructor type (similar to java / c++ / c#)\n // Sample: promise.catch(TypeError, function (e) { ... });\n if (e instanceof type) return callback(e);else return Promise.reject(e);\n });else return this.then(null, function (e) {\n // Catching errors by the error.name property. Makes sense for indexedDB where error type\n // is always DOMError but where e.name tells the actual error type.\n // Sample: promise.catch('ConstraintError', function (e) { ... });\n if (e && e.name === type) return callback(e);else return Promise.reject(e);\n });\n};\n\nPromise.prototype['finally'] = function (onFinally) {\n return this.then(function (value) {\n onFinally();\n return value;\n }, function (err) {\n onFinally();\n return Promise.reject(err);\n });\n};\n\nPromise.prototype.onuncatched = null; // Optional event triggered if promise is rejected but no one listened.\n\nPromise.resolve = function (value) {\n if (value && typeof value.then === 'function') return value;\n var p = new Promise(function () {});\n p._state = true;\n p._value = value;\n return p;\n};\n\nPromise.reject = function (value) {\n var p = new Promise(function () {});\n p._state = false;\n p._value = value;\n return p;\n};\n\nPromise.race = function (values) {\n return new Promise(function (resolve, reject) {\n values.map(function (value) {\n value.then(resolve, reject);\n });\n });\n};\n\nPromise.PSD = null; // Promise Specific Data - a TLS Pattern (Thread Local Storage) for Promises. TODO: Rename Promise.PSD to Promise.data\n\nPromise.newPSD = function (fn) {\n // Create new PSD scope (Promise Specific Data)\n var outerScope = Promise.PSD;\n Promise.PSD = outerScope ? Object.create(outerScope) : {};\n try {\n return fn();\n } finally {\n Promise.PSD = outerScope;\n }\n};\n\nPromise.usePSD = function (psd, fn) {\n var outerScope = Promise.PSD;\n Promise.PSD = psd;\n try {\n return fn();\n } finally {\n Promise.PSD = outerScope;\n }\n};\n\nPromise._rootExec = _rootExec;\nPromise._tickFinalize = function (callback) {\n if (isRootExecution) throw new Error(\"Not in a virtual tick\");\n tickFinalizers.push(callback);\n};\n\nPromise.on = Events(null, { \"error\": [function (f1, f2) {\n return f2;\n }, // Only use the most recent handler (only allow one handler at a time).\n defaultErrorHandler] // Default to defaultErrorHandler\n});\n\n// By default, log uncaught errors to the console\nfunction defaultErrorHandler(e) {\n console.error('Uncaught Promise: ' + (e.stack || e));\n}","/*\r\n * Dexie.js - a minimalistic wrapper for IndexedDB\r\n * ===============================================\r\n *\r\n * By David Fahlander, david.fahlander@gmail.com\r\n *\r\n * Version {version}, {date}\r\n *\r\n * www.dexie.com\r\n *\r\n * Apache License Version 2.0, January 2004, http://www.apache.org/licenses/\r\n */\n\nimport { keys, isArray, extend, derive, slice, override, _global, doFakeAutoComplete, assert, asap, miniTryCatch, fail, getByKeyPath, setByKeyPath, delByKeyPath, shallowClone, deepClone, getObjectDiff } from './utils';\nimport { DexieError, ModifyError, BulkError, errnames, exceptions, fullNameExceptions, mapError, stack } from './errors';\nimport Promise from './Promise';\nimport Events from './Events';\nimport { nop, mirror, pureFunctionChain, callBoth, hookCreatingChain, hookUpdatingChain, hookDeletingChain, nonStoppableEventChain, promisableChain, reverseStoppableEventChain, stoppableEventChain } from './chaining-functions';\n\nvar maxString = String.fromCharCode(65535),\n\n// maxKey is an Array if indexedDB implementations supports array keys (not supported by IE,Edge or Safari at the moment)\n// Otherwise maxKey is maxString. This is handy when needing an open upper border without limit.\nmaxKey = function () {\n try {\n IDBKeyRange.only([[]]);return [[]];\n } catch (e) {\n return maxString;\n }\n}(),\n INVALID_KEY_ARGUMENT = \"Invalid key provided. Keys must be of type string, number, Date or Array.\",\n STRING_EXPECTED = \"String expected.\",\n connections = [],\n isIEOrEdge = typeof navigator !== 'undefined' && /(MSIE|Trident|Edge)/.test(navigator.userAgent),\n hasIEDeleteObjectStoreBug = isIEOrEdge,\n hangsOnDeleteLargeKeyRange = isIEOrEdge;\n\nexport default function Dexie(dbName, options) {\n /// Specify only if you wich to control which addons that should run on this instance\n var deps = Dexie.dependencies;\n var opts = extend({\n // Default Options\n addons: Dexie.addons, // Pick statically registered addons by default\n autoOpen: true, // Don't require db.open() explicitely.\n indexedDB: deps.indexedDB, // Backend IndexedDB api. Default to IDBShim or browser env.\n IDBKeyRange: deps.IDBKeyRange // Backend IDBKeyRange api. Default to IDBShim or browser env.\n }, options || {});\n var addons = opts.addons,\n autoOpen = opts.autoOpen,\n indexedDB = opts.indexedDB,\n IDBKeyRange = opts.IDBKeyRange;\n\n var globalSchema = this._dbSchema = {};\n var versions = [];\n var dbStoreNames = [];\n var allTables = {};\n var notInTransFallbackTables = {};\n ///\n var idbdb = null; // Instance of IDBDatabase\n var db_is_blocked = true;\n var dbOpenError = null;\n var isBeingOpened = false;\n var READONLY = \"readonly\",\n READWRITE = \"readwrite\";\n var db = this;\n var pausedResumeables = [];\n var autoSchema = true;\n var hasNativeGetDatabaseNames = !!getNativeGetDatabaseNamesFn(indexedDB);\n\n function init() {\n // Default subscribers to \"versionchange\" and \"blocked\".\n // Can be overridden by custom handlers. If custom handlers return false, these default\n // behaviours will be prevented.\n db.on(\"versionchange\", function (ev) {\n // Default behavior for versionchange event is to close database connection.\n // Caller can override this behavior by doing db.on(\"versionchange\", function(){ return false; });\n // Let's not block the other window from making it's delete() or open() call.\n // NOTE! This event is never fired in IE,Edge or Safari.\n if (ev.newVersion > 0) console.warn('Another connection wants to upgrade database \\'' + db.name + '\\'. Closing db now to resume the upgrade.');else console.warn('Another connection wants to delete database \\'' + db.name + '\\'. Closing db now to resume the delete request.');\n db.close();\n // In many web applications, it would be recommended to force window.reload()\n // when this event occurs. To do that, subscribe to the versionchange event\n // and call window.location.reload(true) if ev.newVersion > 0 (not a deletion)\n // The reason for this is that your current web app obviously has old schema code that needs\n // to be updated. Another window got a newer version of the app and needs to upgrade DB but\n // your window is blocking it unless we close it here.\n });\n db.on(\"blocked\", function (ev) {\n if (!ev.newVersion || ev.newVersion < ev.oldVersion) console.warn('Dexie.delete(\\'' + db.name + '\\') was blocked');else console.warn('Upgrade \\'' + db.name + '\\' blocked by other connection holding version ' + ev.oldVersion / 10);\n });\n }\n\n //\n //\n //\n // ------------------------- Versioning Framework---------------------------\n //\n //\n //\n\n this.version = function (versionNumber) {\n /// \n /// \n if (idbdb || isBeingOpened) throw new exceptions.Schema(\"Cannot add version when database is open\");\n this.verno = Math.max(this.verno, versionNumber);\n var versionInstance = versions.filter(function (v) {\n return v._cfg.version === versionNumber;\n })[0];\n if (versionInstance) return versionInstance;\n versionInstance = new Version(versionNumber);\n versions.push(versionInstance);\n versions.sort(lowerVersionFirst);\n return versionInstance;\n };\n\n function Version(versionNumber) {\n this._cfg = {\n version: versionNumber,\n storesSource: null,\n dbschema: {},\n tables: {},\n contentUpgrade: null\n };\n this.stores({}); // Derive earlier schemas by default.\n }\n\n extend(Version.prototype, {\n stores: function (stores) {\n /// \n /// Defines the schema for a particular version\n /// \n /// \n /// Example:
\n /// {users: \"id++,first,last,&username,*email\",
\n /// passwords: \"id++,&username\"}
\n ///
\n /// Syntax: {Table: \"[primaryKey][++],[&][*]index1,[&][*]index2,...\"}

\n /// Special characters:
\n /// \"&\" means unique key,
\n /// \"*\" means value is multiEntry,
\n /// \"++\" means auto-increment and only applicable for primary key
\n /// \n this._cfg.storesSource = this._cfg.storesSource ? extend(this._cfg.storesSource, stores) : stores;\n\n // Derive stores from earlier versions if they are not explicitely specified as null or a new syntax.\n var storesSpec = {};\n versions.forEach(function (version) {\n // 'versions' is always sorted by lowest version first.\n extend(storesSpec, version._cfg.storesSource);\n });\n\n var dbschema = this._cfg.dbschema = {};\n this._parseStoresSpec(storesSpec, dbschema);\n // Update the latest schema to this version\n // Update API\n globalSchema = db._dbSchema = dbschema;\n removeTablesApi([allTables, db, notInTransFallbackTables]);\n setApiOnPlace([notInTransFallbackTables], tableNotInTransaction, keys(dbschema), READWRITE, dbschema);\n setApiOnPlace([allTables, db, this._cfg.tables], db._transPromiseFactory, keys(dbschema), READWRITE, dbschema, true);\n dbStoreNames = keys(dbschema);\n return this;\n },\n upgrade: function (upgradeFunction) {\n /// Function that performs upgrading actions.\n var self = this;\n fakeAutoComplete(function () {\n upgradeFunction(db._createTransaction(READWRITE, keys(self._cfg.dbschema), self._cfg.dbschema)); // BUGBUG: No code completion for prev version's tables wont appear.\n });\n this._cfg.contentUpgrade = upgradeFunction;\n return this;\n },\n _parseStoresSpec: function (stores, outSchema) {\n keys(stores).forEach(function (tableName) {\n if (stores[tableName] !== null) {\n var instanceTemplate = {};\n var indexes = parseIndexSyntax(stores[tableName]);\n var primKey = indexes.shift();\n if (primKey.multi) throw new exceptions.Schema(\"Primary key cannot be multi-valued\");\n if (primKey.keyPath) setByKeyPath(instanceTemplate, primKey.keyPath, primKey.auto ? 0 : primKey.keyPath);\n indexes.forEach(function (idx) {\n if (idx.auto) throw new exceptions.Schema(\"Only primary key can be marked as autoIncrement (++)\");\n if (!idx.keyPath) throw new exceptions.Schema(\"Index must have a name and cannot be an empty string\");\n setByKeyPath(instanceTemplate, idx.keyPath, idx.compound ? idx.keyPath.map(function () {\n return \"\";\n }) : \"\");\n });\n outSchema[tableName] = new TableSchema(tableName, primKey, indexes, instanceTemplate);\n }\n });\n }\n });\n\n function runUpgraders(oldVersion, idbtrans, reject, openReq) {\n if (oldVersion === 0) {\n //globalSchema = versions[versions.length - 1]._cfg.dbschema;\n // Create tables:\n keys(globalSchema).forEach(function (tableName) {\n createTable(idbtrans, tableName, globalSchema[tableName].primKey, globalSchema[tableName].indexes);\n });\n // Populate data\n var t = db._createTransaction(READWRITE, dbStoreNames, globalSchema);\n t.idbtrans = idbtrans;\n t.idbtrans.onerror = eventRejectHandler(reject, [\"populating database\"]);\n t.on('error').subscribe(reject);\n Promise.newPSD(function () {\n Promise.PSD.trans = t;\n try {\n db.on(\"populate\").fire(t);\n } catch (err) {\n openReq.onerror = idbtrans.onerror = function (ev) {\n ev.preventDefault();\n }; // Prohibit AbortError fire on db.on(\"error\") in Firefox.\n try {\n idbtrans.abort();\n } catch (e) {}\n idbtrans.db.close();\n reject(err);\n }\n });\n } else {\n // Upgrade version to version, step-by-step from oldest to newest version.\n // Each transaction object will contain the table set that was current in that version (but also not-yet-deleted tables from its previous version)\n var queue = [];\n var oldVersionStruct = versions.filter(function (version) {\n return version._cfg.version === oldVersion;\n })[0];\n if (!oldVersionStruct) throw new exceptions.Upgrade(\"Dexie specification of currently installed DB version is missing\");\n globalSchema = db._dbSchema = oldVersionStruct._cfg.dbschema;\n var anyContentUpgraderHasRun = false;\n\n var versToRun = versions.filter(function (v) {\n return v._cfg.version > oldVersion;\n });\n versToRun.forEach(function (version) {\n /// \n var oldSchema = globalSchema;\n var newSchema = version._cfg.dbschema;\n adjustToExistingIndexNames(oldSchema, idbtrans);\n adjustToExistingIndexNames(newSchema, idbtrans);\n globalSchema = db._dbSchema = newSchema;\n {\n var diff = getSchemaDiff(oldSchema, newSchema);\n diff.add.forEach(function (tuple) {\n queue.push(function (idbtrans, cb) {\n createTable(idbtrans, tuple[0], tuple[1].primKey, tuple[1].indexes);\n cb();\n });\n });\n diff.change.forEach(function (change) {\n if (change.recreate) {\n throw new exceptions.Upgrade(\"Not yet support for changing primary key\");\n } else {\n queue.push(function (idbtrans, cb) {\n var store = idbtrans.objectStore(change.name);\n change.add.forEach(function (idx) {\n addIndex(store, idx);\n });\n change.change.forEach(function (idx) {\n store.deleteIndex(idx.name);\n addIndex(store, idx);\n });\n change.del.forEach(function (idxName) {\n store.deleteIndex(idxName);\n });\n cb();\n });\n }\n });\n if (version._cfg.contentUpgrade) {\n queue.push(function (idbtrans, cb) {\n anyContentUpgraderHasRun = true;\n var t = db._createTransaction(READWRITE, slice(idbtrans.db.objectStoreNames), newSchema);\n t.idbtrans = idbtrans;\n var uncompletedRequests = 0;\n t._promise = override(t._promise, function (orig_promise) {\n return function (mode, fn, writeLock) {\n ++uncompletedRequests;\n function proxy(fn) {\n return function () {\n fn.apply(this, arguments);\n if (--uncompletedRequests === 0) cb(); // A called db operation has completed without starting a new operation. The flow is finished, now run next upgrader.\n };\n }\n return orig_promise.call(this, mode, function (resolve, reject, trans) {\n arguments[0] = proxy(resolve);\n arguments[1] = proxy(reject);\n fn.apply(this, arguments);\n }, writeLock);\n };\n });\n idbtrans.onerror = eventRejectHandler(reject, [\"running upgrader function for version\", version._cfg.version]);\n t.on('error').subscribe(reject);\n version._cfg.contentUpgrade(t);\n if (uncompletedRequests === 0) cb(); // contentUpgrade() didnt call any db operations at all.\n });\n }\n if (!anyContentUpgraderHasRun || hasIEDeleteObjectStoreBug) {\n // Dont delete old tables if ieBug is present and a content upgrader has run. Let tables be left in DB so far. This needs to be taken care of.\n queue.push(function (idbtrans, cb) {\n // Delete old tables\n deleteRemovedTables(newSchema, idbtrans);\n cb();\n });\n }\n }\n });\n\n // Now, create a queue execution engine\n var runNextQueuedFunction = function () {\n try {\n if (queue.length) queue.shift()(idbtrans, runNextQueuedFunction);else createMissingTables(globalSchema, idbtrans); // At last, make sure to create any missing tables. (Needed by addons that add stores to DB without specifying version)\n } catch (err) {\n openReq.onerror = idbtrans.onerror = function (ev) {\n ev.preventDefault();\n }; // Prohibit AbortError fire on db.on(\"error\") in Firefox.\n try {\n idbtrans.abort();\n } catch (e) {}\n idbtrans.db.close();\n reject(err);\n }\n };\n runNextQueuedFunction();\n }\n }\n\n function getSchemaDiff(oldSchema, newSchema) {\n var diff = {\n del: [], // Array of table names\n add: [], // Array of [tableName, newDefinition]\n change: [] // Array of {name: tableName, recreate: newDefinition, del: delIndexNames, add: newIndexDefs, change: changedIndexDefs}\n };\n for (var table in oldSchema) {\n if (!newSchema[table]) diff.del.push(table);\n }\n for (var table in newSchema) {\n var oldDef = oldSchema[table],\n newDef = newSchema[table];\n if (!oldDef) diff.add.push([table, newDef]);else {\n var change = {\n name: table,\n def: newSchema[table],\n recreate: false,\n del: [],\n add: [],\n change: []\n };\n if (oldDef.primKey.src !== newDef.primKey.src) {\n // Primary key has changed. Remove and re-add table.\n change.recreate = true;\n diff.change.push(change);\n } else {\n var oldIndexes = oldDef.indexes.reduce(function (prev, current) {\n prev[current.name] = current;return prev;\n }, {});\n var newIndexes = newDef.indexes.reduce(function (prev, current) {\n prev[current.name] = current;return prev;\n }, {});\n for (var idxName in oldIndexes) {\n if (!newIndexes[idxName]) change.del.push(idxName);\n }\n for (var idxName in newIndexes) {\n var oldIdx = oldIndexes[idxName],\n newIdx = newIndexes[idxName];\n if (!oldIdx) change.add.push(newIdx);else if (oldIdx.src !== newIdx.src) change.change.push(newIdx);\n }\n if (change.recreate || change.del.length > 0 || change.add.length > 0 || change.change.length > 0) {\n diff.change.push(change);\n }\n }\n }\n }\n return diff;\n }\n\n function createTable(idbtrans, tableName, primKey, indexes) {\n /// \n var store = idbtrans.db.createObjectStore(tableName, primKey.keyPath ? { keyPath: primKey.keyPath, autoIncrement: primKey.auto } : { autoIncrement: primKey.auto });\n indexes.forEach(function (idx) {\n addIndex(store, idx);\n });\n return store;\n }\n\n function createMissingTables(newSchema, idbtrans) {\n keys(newSchema).forEach(function (tableName) {\n if (!idbtrans.db.objectStoreNames.contains(tableName)) {\n createTable(idbtrans, tableName, newSchema[tableName].primKey, newSchema[tableName].indexes);\n }\n });\n }\n\n function deleteRemovedTables(newSchema, idbtrans) {\n for (var i = 0; i < idbtrans.db.objectStoreNames.length; ++i) {\n var storeName = idbtrans.db.objectStoreNames[i];\n if (newSchema[storeName] === null || newSchema[storeName] === undefined) {\n idbtrans.db.deleteObjectStore(storeName);\n }\n }\n }\n\n function addIndex(store, idx) {\n store.createIndex(idx.name, idx.keyPath, { unique: idx.unique, multiEntry: idx.multi });\n }\n\n function executePausedResumeables() {\n pausedResumeables.forEach(function (resumable) {\n // Resume all stalled operations. They will fail once they wake up.\n resumable.resume();\n });\n }\n\n //\n //\n // Dexie Protected API\n //\n //\n\n this._allTables = allTables;\n\n this._tableFactory = function createTable(mode, tableSchema, transactionPromiseFactory) {\n /// \n if (mode === READONLY) return new Table(tableSchema.name, transactionPromiseFactory, tableSchema, Collection);else return new WriteableTable(tableSchema.name, transactionPromiseFactory, tableSchema);\n };\n\n this._createTransaction = function (mode, storeNames, dbschema, parentTransaction) {\n return new Transaction(mode, storeNames, dbschema, parentTransaction);\n };\n\n function tableNotInTransaction(mode, storeNames) {\n throw new exceptions.InvalidTable(\"Table \" + storeNames[0] + \" not part of transaction. Original Scope Function Source: \" + Dexie.Promise.PSD.trans.scopeFunc.toString());\n }\n\n this._transPromiseFactory = function transactionPromiseFactory(mode, storeNames, fn) {\n // Last argument is \"writeLocked\". But this doesnt apply to oneshot direct db operations, so we ignore it.\n if (db_is_blocked && (!Promise.PSD || !Promise.PSD.letThrough)) {\n // Database is paused. Wait til resumed.\n if (!isBeingOpened && !autoOpen) {\n return fail(new exceptions.DatabaseClosed());\n }\n var blockedPromise = new Promise(function (resolve, reject) {\n pausedResumeables.push({\n resume: function () {\n var p = db._transPromiseFactory(mode, storeNames, fn);\n blockedPromise.onuncatched = p.onuncatched;\n p.then(resolve, reject);\n }\n });\n });\n if (autoOpen && !isBeingOpened) {\n db.open().catch(nop); // catching to get rid of error logging of uncaught Promise. dbOpenError will be returned again as a rejected Promise.\n }\n return blockedPromise;\n } else {\n var trans = db._createTransaction(mode, storeNames, globalSchema);\n return trans._promise(mode, function (resolve, reject) {\n // An uncatched operation will bubble to this anonymous transaction. Make sure\n // to continue bubbling it up to db.on('error'):\n trans.error(function (err) {\n db.on('error').fire(err);\n });\n Promise.newPSD(function () {\n Promise.PSD.trans = trans;\n fn(function (value) {\n // Instead of resolving value directly, wait with resolving it until transaction has completed.\n // Otherwise the data would not be in the DB if requesting it in the then() operation.\n // Specifically, to ensure that the following expression will work:\n //\n // db.friends.put({name: \"Arne\"}).then(function () {\n // db.friends.where(\"name\").equals(\"Arne\").count(function(count) {\n // assert (count === 1);\n // });\n // });\n //\n trans.complete(function () {\n resolve(value);\n });\n }, reject, trans);\n });\n });\n }\n };\n\n this._whenReady = function (fn) {\n if (!fake && db_is_blocked && (!Promise.PSD || !Promise.PSD.letThrough)) {\n if (!isBeingOpened) {\n if (autoOpen) {\n db.open().catch(nop); // catching to get rid of error logging of uncaught Promise. dbOpenError will be returned again as a rejected Promise.\n } else {\n return fail(new exceptions.DatabaseClosed());\n }\n }\n return new Promise(function (resolve, reject) {\n pausedResumeables.push({\n resume: function () {\n fn(resolve, reject);\n }\n });\n });\n }\n return new Promise(fn);\n };\n\n //\n //\n //\n //\n // Dexie API\n //\n //\n //\n\n this.verno = 0;\n\n this.open = function () {\n if (idbdb) return Promise.resolve(db);\n if (isBeingOpened) return new Promise(function (resolve, reject) {\n return db._whenReady(function () {\n resolve(db);\n }, function (e) {\n reject(e);\n });\n });\n dbOpenError = null;\n isBeingOpened = true;\n db_is_blocked = true;\n return new Promise(function (resolve, reject) {\n if (fake) resolve();\n var req,\n dbWasCreated = false;\n function openError(err) {\n try {\n req.transaction.abort();\n } catch (e) {}\n if (idbdb) try {\n idbdb.close();\n } catch (e) {}\n idbdb = null;\n isBeingOpened = false;\n dbOpenError = mapError(err);\n db_is_blocked = false;\n reject(dbOpenError);\n executePausedResumeables();\n }\n try {\n // Make sure caller has specified at least one version\n if (versions.length > 0) autoSchema = false;\n\n // Multiply db.verno with 10 will be needed to workaround upgrading bug in IE:\n // IE fails when deleting objectStore after reading from it.\n // A future version of Dexie.js will stopover an intermediate version to workaround this.\n // At that point, we want to be backward compatible. Could have been multiplied with 2, but by using 10, it is easier to map the number to the real version number.\n if (!indexedDB) throw new exceptions.MissingAPI(\"indexedDB API not found. If using IE10+, make sure to run your code on a server URL \" + \"(not locally). If using Safari, make sure to include indexedDB polyfill.\");\n req = autoSchema ? indexedDB.open(dbName) : indexedDB.open(dbName, Math.round(db.verno * 10));\n if (!req) throw new exceptions.MissingAPI(\"IndexedDB API not available\"); // May happen in Safari private mode, see https://github.com/dfahlander/Dexie.js/issues/134\n req.onerror = eventRejectHandler(openError, [\"opening database\", dbName]);\n req.onblocked = fireOnBlocked;\n req.onupgradeneeded = trycatch(function (e) {\n if (autoSchema && !db._allowEmptyDB) {\n // Unless an addon has specified db._allowEmptyDB, lets make the call fail.\n // Caller did not specify a version or schema. Doing that is only acceptable for opening alread existing databases.\n // If onupgradeneeded is called it means database did not exist. Reject the open() promise and make sure that we\n // do not create a new database by accident here.\n req.onerror = function (event) {\n event.preventDefault();\n }; // Prohibit onabort error from firing before we're done!\n req.transaction.abort(); // Abort transaction (would hope that this would make DB disappear but it doesnt.)\n // Close database and delete it.\n req.result.close();\n var delreq = indexedDB.deleteDatabase(dbName); // The upgrade transaction is atomic, and javascript is single threaded - meaning that there is no risk that we delete someone elses database here!\n delreq.onsuccess = delreq.onerror = function () {\n openError(new exceptions.NoSuchDatabase('Database ' + dbName + ' doesnt exist'));\n };\n } else {\n if (e.oldVersion === 0) dbWasCreated = true;\n req.transaction.onerror = eventRejectHandler(openError);\n var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion; // Safari 8 fix.\n runUpgraders(oldVer / 10, req.transaction, openError, req);\n }\n }, openError);\n req.onsuccess = trycatch(function (e) {\n isBeingOpened = false;\n idbdb = req.result;\n if (autoSchema) readGlobalSchema();else if (idbdb.objectStoreNames.length > 0) {\n try {\n adjustToExistingIndexNames(globalSchema, idbdb.transaction(safariMultiStoreFix(idbdb.objectStoreNames), READONLY));\n } catch (e) {\n // Safari may bail out if > 1 store names. However, this shouldnt be a showstopper. Issue #120.\n }\n }\n\n idbdb.onversionchange = function (ev) {\n db._vcFired = true; // detect implementations that not support versionchange (IE/Edge/Safari)\n db.on(\"versionchange\").fire(ev);\n };\n if (!hasNativeGetDatabaseNames) {\n // Update localStorage with list of database names\n globalDatabaseList(function (databaseNames) {\n if (databaseNames.indexOf(dbName) === -1) return databaseNames.push(dbName);\n });\n }\n // Now, let any subscribers to the on(\"ready\") fire BEFORE any other db operations resume!\n // If an the on(\"ready\") subscriber returns a Promise, we will wait til promise completes or rejects before\n Promise.newPSD(function () {\n Promise.PSD.letThrough = true; // Set a Promise-Specific Data property informing that onready is firing. This will make db._whenReady() let the subscribers use the DB but block all others (!). Quite cool ha?\n try {\n var res = db.on.ready.fire();\n if (res && typeof res.then === 'function') {\n // If on('ready') returns a promise, wait for it to complete and then resume any pending operations.\n res.then(resume, function (err) {\n idbdb.close();\n idbdb = null;\n openError(err);\n });\n } else {\n asap(resume); // Cannot call resume directly because then the pauseResumables would inherit from our PSD scope.\n }\n } catch (e) {\n openError(e);\n }\n\n function resume() {\n db_is_blocked = false;\n executePausedResumeables();\n resolve();\n }\n });\n }, openError);\n } catch (err) {\n openError(err);\n }\n }).then(function () {\n connections.push(db);\n return db;\n });\n };\n\n this.close = function () {\n var idx = connections.indexOf(db);\n if (idx >= 0) connections.splice(idx, 1);\n if (idbdb) {\n idbdb.close();\n idbdb = null;\n autoOpen = false;\n if (db_is_blocked) {\n executePausedResumeables();\n }\n db_is_blocked = false;\n dbOpenError = new exceptions.DatabaseClosed();\n } else if (isBeingOpened) {\n db.on('ready', function () {\n return Promise.reject(new exceptions.DatabaseClosed());\n });\n }\n };\n\n this.delete = function () {\n var args = arguments;\n return new Promise(function (resolve, reject) {\n if (args.length > 0) throw new exceptions.InvalidArgument(\"Arguments not allowed in db.delete()\");\n function doDelete() {\n db.close();\n var req = indexedDB.deleteDatabase(dbName);\n req.onsuccess = function () {\n if (!hasNativeGetDatabaseNames) {\n globalDatabaseList(function (databaseNames) {\n var pos = databaseNames.indexOf(dbName);\n if (pos >= 0) return databaseNames.splice(pos, 1);\n });\n }\n resolve();\n };\n req.onerror = eventRejectHandler(reject, [\"deleting\", dbName]);\n req.onblocked = fireOnBlocked;\n }\n if (isBeingOpened) {\n pausedResumeables.push({ resume: doDelete });\n } else {\n doDelete();\n }\n });\n };\n\n this.backendDB = function () {\n return idbdb;\n };\n\n this.isOpen = function () {\n return idbdb !== null;\n };\n this.hasFailed = function () {\n return dbOpenError !== null;\n };\n this.dynamicallyOpened = function () {\n return autoSchema;\n };\n\n //\n // Properties\n //\n this.name = dbName;\n\n // db.tables - an array of all Table instances.\n // TODO: Change so that tables is a simple member and make sure to update it whenever allTables changes.\n Object.defineProperty(this, \"tables\", {\n get: function () {\n /// \n return keys(allTables).map(function (name) {\n return allTables[name];\n });\n }\n });\n\n //\n // Events\n //\n this.on = Events(this, \"error\", \"populate\", { blocked: [reverseStoppableEventChain, nop], \"ready\": [promisableChain, nop], \"versionchange\": [reverseStoppableEventChain, nop] });\n\n // Handle on('ready') specifically: If DB is already open, trigger the event immediately. Also, default to unsubscribe immediately after being triggered.\n this.on.ready.subscribe = override(this.on.ready.subscribe, function (origSubscribe) {\n return function (subscriber, bSticky) {\n function proxy() {\n if (!bSticky) db.on.ready.unsubscribe(proxy);\n return subscriber.apply(this, arguments);\n }\n origSubscribe.call(this, proxy);\n if (db.isOpen()) {\n if (db_is_blocked) {\n pausedResumeables.push({ resume: proxy });\n } else {\n proxy();\n }\n }\n };\n });\n\n fakeAutoComplete(function () {\n db.on(\"populate\").fire(db._createTransaction(READWRITE, dbStoreNames, globalSchema));\n db.on(\"error\").fire(new Error());\n });\n\n this.transaction = function (mode, tableInstances, scopeFunc) {\n /// \n ///\n /// \n /// \"r\" for readonly, or \"rw\" for readwrite\n /// Table instance, Array of Table instances, String or String Array of object stores to include in the transaction\n /// Function to execute with transaction\n\n // Let table arguments be all arguments between mode and last argument.\n tableInstances = slice(arguments, 1, arguments.length - 1);\n // Let scopeFunc be the last argument\n scopeFunc = arguments[arguments.length - 1];\n var parentTransaction = Promise.PSD && Promise.PSD.trans;\n // Check if parent transactions is bound to this db instance, and if caller wants to reuse it\n if (!parentTransaction || parentTransaction.db !== db || mode.indexOf('!') !== -1) parentTransaction = null;\n var onlyIfCompatible = mode.indexOf('?') !== -1;\n mode = mode.replace('!', '').replace('?', '');\n //\n // Get storeNames from arguments. Either through given table instances, or through given table names.\n //\n var tables = isArray(tableInstances[0]) ? tableInstances.reduce(function (a, b) {\n return a.concat(b);\n }) : tableInstances;\n var error = null;\n var storeNames = tables.map(function (tableInstance) {\n if (typeof tableInstance === \"string\") {\n return tableInstance;\n } else {\n if (!(tableInstance instanceof Table)) error = error || new TypeError(\"Invalid type. Arguments following mode must be instances of Table or String\");\n return tableInstance.name;\n }\n });\n\n //\n // Resolve mode. Allow shortcuts \"r\" and \"rw\".\n //\n if (mode == \"r\" || mode == READONLY) mode = READONLY;else if (mode == \"rw\" || mode == READWRITE) mode = READWRITE;else error = new exceptions.InvalidArgument(\"Invalid transaction mode: \" + mode);\n\n if (parentTransaction) {\n // Basic checks\n if (!error) {\n if (parentTransaction && parentTransaction.mode === READONLY && mode === READWRITE) {\n if (onlyIfCompatible) parentTransaction = null; // Spawn new transaction instead.\n else error = error || new exceptions.SubTransaction(\"Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY\");\n }\n if (parentTransaction) {\n storeNames.forEach(function (storeName) {\n if (!parentTransaction.tables.hasOwnProperty(storeName)) {\n if (onlyIfCompatible) parentTransaction = null; // Spawn new transaction instead.\n else error = error || new exceptions.SubTransaction(\"Table \" + storeName + \" not included in parent transaction. Parent Transaction function: \" + parentTransaction.scopeFunc.toString());\n }\n });\n }\n }\n }\n if (parentTransaction) {\n // If this is a sub-transaction, lock the parent and then launch the sub-transaction.\n return parentTransaction._promise(mode, enterTransactionScope, \"lock\");\n } else {\n // If this is a root-level transaction, wait til database is ready and then launch the transaction.\n return db._whenReady(enterTransactionScope);\n }\n\n function enterTransactionScope(resolve, reject) {\n // Our transaction. To be set later.\n var trans = null;\n var isConstructing = true;\n\n try {\n // Throw any error if any of the above checks failed.\n // Real error defined some lines up. We throw it here from within a Promise to reject Promise\n // rather than make caller need to both use try..catch and promise catching. The reason we still\n // throw here rather than do Promise.reject(error) is that we like to have the stack attached to the\n // error. Also because there is a catch() clause bound to this try() that will bubble the error\n // to the parent transaction.\n if (error) throw error;\n\n //\n // Create Transaction instance\n //\n trans = db._createTransaction(mode, storeNames, globalSchema, parentTransaction);\n\n // Provide arguments to the scope function (for backward compatibility)\n var tableArgs = storeNames.map(function (name) {\n return trans.tables[name];\n });\n tableArgs.push(trans);\n\n // If transaction completes, resolve the Promise with the return value of scopeFunc.\n var returnValue;\n var uncompletedRequests = 0;\n\n // Create a new PSD frame to hold Promise.PSD.trans. Must not be bound to the current PSD frame since we want\n // it to pop before then() callback is called of our returned Promise.\n Promise.newPSD(function () {\n // Let the transaction instance be part of a Promise-specific data (PSD) value.\n Promise.PSD.trans = trans;\n trans.scopeFunc = scopeFunc; // For Error (\"Table \" + storeNames[0] + \" not part of transaction\") when it happens. This may help localizing the code that started a transaction used on another place.\n\n if (parentTransaction) {\n // Emulate transaction commit awareness for inner transaction (must 'commit' when the inner transaction has no more operations ongoing)\n trans.idbtrans = parentTransaction.idbtrans;\n trans._promise = override(trans._promise, function (orig) {\n return function (mode, fn, writeLock) {\n ++uncompletedRequests;\n function proxy(fn2) {\n return function (val) {\n var retval;\n // _rootExec needed so that we do not loose any IDBTransaction in a setTimeout() call.\n Promise._rootExec(function () {\n retval = fn2(val);\n // _tickFinalize makes sure to support lazy micro tasks executed in Promise._rootExec().\n // We certainly do not want to copy the bad pattern from IndexedDB but instead allow\n // execution of Promise.then() callbacks until the're all done.\n Promise._tickFinalize(function () {\n if (--uncompletedRequests === 0 && trans.active) {\n trans.active = false;\n trans.on.complete.fire(); // A called db operation has completed without starting a new operation. The flow is finished\n }\n });\n });\n return retval;\n };\n }\n return orig.call(this, mode, function (resolve2, reject2, trans) {\n return fn(proxy(resolve2), proxy(reject2), trans);\n }, writeLock);\n };\n });\n }\n trans.complete(function () {\n resolve(returnValue);\n });\n // If transaction fails, reject the Promise and bubble to db if noone catched this rejection.\n trans.error(function (e) {\n if (trans.idbtrans) trans.idbtrans.onerror = preventDefault; // Prohibit AbortError from firing.\n try {\n trans.abort();\n } catch (e2) {}\n if (parentTransaction) {\n parentTransaction.active = false;\n parentTransaction.on.error.fire(e); // Bubble to parent transaction\n }\n\n if (isConstructing) asap(doReject);else doReject();\n function doReject() {\n var catched = reject(e);\n if (!parentTransaction && !catched) {\n db.on.error.fire(e); // If not catched, bubble error to db.on(\"error\").\n }\n }\n });\n\n // Finally, call the scope function with our table and transaction arguments.\n Promise._rootExec(function () {\n returnValue = scopeFunc.apply(trans, tableArgs); // NOTE: returnValue is used in trans.on.complete() not as a returnValue to this func.\n if (returnValue && typeof returnValue.next === 'function' && typeof returnValue.throw === 'function') {\n // scopeFunc returned an iterable. Handle yield as await.\n returnValue = awaitIterable(returnValue);\n }\n });\n });\n if (!trans.idbtrans || parentTransaction && uncompletedRequests === 0) {\n trans._nop(); // Make sure transaction is being used so that it will resolve.\n }\n } catch (e) {\n // If exception occur, abort the transaction and reject Promise.\n if (trans && trans.idbtrans) trans.idbtrans.onerror = preventDefault; // Prohibit AbortError from firing.\n if (trans) trans.abort();\n if (parentTransaction) parentTransaction.on.error.fire(e);\n asap(function () {\n // Need to use asap(=setImmediate/setTimeout) before calling reject because we are in the Promise constructor and reject() will always return false if so.\n if (!reject(e)) db.on(\"error\").fire(e); // If not catched, bubble exception to db.on(\"error\");\n });\n }\n isConstructing = false;\n }\n };\n\n this.table = function (tableName) {\n /// \n if (fake && autoSchema) return new WriteableTable(tableName);\n if (!allTables.hasOwnProperty(tableName)) {\n throw new exceptions.InvalidTable('Table ' + tableName + ' does not exist');\n }\n return allTables[tableName];\n };\n\n //\n //\n //\n // Table Class\n //\n //\n //\n function Table(name, transactionPromiseFactory, tableSchema, collClass) {\n /// \n this.name = name;\n this.schema = tableSchema;\n this.hook = allTables[name] ? allTables[name].hook : Events(null, {\n \"creating\": [hookCreatingChain, nop],\n \"reading\": [pureFunctionChain, mirror],\n \"updating\": [hookUpdatingChain, nop],\n \"deleting\": [hookDeletingChain, nop]\n });\n this._tpf = transactionPromiseFactory;\n this._collClass = collClass || Collection;\n }\n\n extend(Table.prototype, function () {\n function failReadonly() {\n // It's ok to throw here because this can only happen within a transaction,\n // and will always be caught by the transaction scope and returned as a\n // failed promise.\n throw new exceptions.ReadOnly(\"Current Transaction is READONLY\");\n }\n return {\n //\n // Table Protected Methods\n //\n\n _trans: function getTransaction(mode, fn, writeLocked) {\n return this._tpf(mode, [this.name], fn, writeLocked);\n },\n _idbstore: function getIDBObjectStore(mode, fn, writeLocked) {\n if (fake) return new Promise(fn); // Simplify the work for Intellisense/Code completion.\n var self = this;\n return this._tpf(mode, [this.name], function (resolve, reject, trans) {\n fn(resolve, reject, trans.idbtrans.objectStore(self.name), trans);\n }, writeLocked);\n },\n\n //\n // Table Public Methods\n //\n get: function (key, cb) {\n var self = this;\n return this._idbstore(READONLY, function (resolve, reject, idbstore) {\n fake && resolve(self.schema.instanceTemplate);\n var req = idbstore.get(key);\n req.onerror = eventRejectHandler(reject, [\"getting\", key, \"from\", self.name]);\n req.onsuccess = function () {\n resolve(self.hook.reading.fire(req.result));\n };\n }).then(cb);\n },\n where: function (indexName) {\n return new WhereClause(this, indexName);\n },\n count: function (cb) {\n return this.toCollection().count(cb);\n },\n offset: function (offset) {\n return this.toCollection().offset(offset);\n },\n limit: function (numRows) {\n return this.toCollection().limit(numRows);\n },\n reverse: function () {\n return this.toCollection().reverse();\n },\n filter: function (filterFunction) {\n return this.toCollection().and(filterFunction);\n },\n each: function (fn) {\n return this.toCollection().each(fn);\n },\n toArray: function (cb) {\n return this.toCollection().toArray(cb);\n },\n orderBy: function (index) {\n return new this._collClass(new WhereClause(this, index));\n },\n\n toCollection: function () {\n return new this._collClass(new WhereClause(this));\n },\n\n mapToClass: function (constructor, structure) {\n /// \n /// Map table to a javascript constructor function. Objects returned from the database will be instances of this class, making\n /// it possible to the instanceOf operator as well as extending the class using constructor.prototype.method = function(){...}.\n /// \n /// Constructor function representing the class.\n /// Helps IDE code completion by knowing the members that objects contain and not just the indexes. Also\n /// know what type each member has. Example: {name: String, emailAddresses: [String], password}\n this.schema.mappedClass = constructor;\n var instanceTemplate = Object.create(constructor.prototype);\n if (structure) {\n // structure and instanceTemplate is for IDE code competion only while constructor.prototype is for actual inheritance.\n applyStructure(instanceTemplate, structure);\n }\n this.schema.instanceTemplate = instanceTemplate;\n\n // Now, subscribe to the when(\"reading\") event to make all objects that come out from this table inherit from given class\n // no matter which method to use for reading (Table.get() or Table.where(...)... )\n var readHook = function (obj) {\n if (!obj) return obj; // No valid object. (Value is null). Return as is.\n // Create a new object that derives from constructor:\n var res = Object.create(constructor.prototype);\n // Clone members:\n for (var m in obj) {\n if (obj.hasOwnProperty(m)) res[m] = obj[m];\n }return res;\n };\n\n if (this.schema.readHook) {\n this.hook.reading.unsubscribe(this.schema.readHook);\n }\n this.schema.readHook = readHook;\n this.hook(\"reading\", readHook);\n return constructor;\n },\n defineClass: function (structure) {\n /// \n /// Define all members of the class that represents the table. This will help code completion of when objects are read from the database\n /// as well as making it possible to extend the prototype of the returned constructor function.\n /// \n /// Helps IDE code completion by knowing the members that objects contain and not just the indexes. Also\n /// know what type each member has. Example: {name: String, emailAddresses: [String], properties: {shoeSize: Number}}\n return this.mapToClass(Dexie.defineClass(structure), structure);\n },\n add: failReadonly,\n put: failReadonly,\n 'delete': failReadonly,\n clear: failReadonly,\n update: failReadonly\n };\n });\n\n //\n //\n //\n // WriteableTable Class (extends Table)\n //\n //\n //\n function WriteableTable(name, transactionPromiseFactory, tableSchema, collClass) {\n Table.call(this, name, transactionPromiseFactory, tableSchema, collClass || WriteableCollection);\n }\n\n function BulkErrorHandlerCatchAll(errorList, done) {\n var psd = Promise.PSD;\n return function (ev) {\n try {\n if (ev.stopPropagation) ev.stopPropagation();\n if (ev.preventDefault) ev.preventDefault();\n var err = ev.target.error;\n errorList.push(err);\n if (ev.target._err) {\n Promise.usePSD(psd, ev.target._err.bind(null, err));\n }\n } finally {\n if (done) done();\n }\n };\n }\n\n function BulkErrorHandler(done) {\n var psd = Promise.PSD;\n return function (ev) {\n var err = void 0;\n try {\n err = ev.target.error;\n if (ev.target._err) {\n Promise.usePSD(psd, ev.target._err.bind(null, err));\n }\n } finally {\n done(err);\n }\n };\n }\n\n function BulkSuccessHandler(done, hookListener) {\n var psd = Promise.PSD;\n return hookListener ? function (ev) {\n var res = void 0;\n try {\n res = ev.target.result;\n ev.target._suc && Promise.usePSD(psd, ev.target._suc.bind(null, res));\n } finally {\n if (done) done(res);\n }\n } : function (ev) {\n done(ev.target.result);\n };\n }\n\n function bulkDelete(idbstore, trans, keysOrTuples, hasDeleteHook, deletingHook) {\n // If hasDeleteHook, keysOrTuples must be an array of tuples: [[key1, value2],[key2,value2],...],\n // else keysOrTuples must be just an array of keys: [key1, key2, ...].\n return new Promise(function (resolve, reject) {\n var len = keysOrTuples.length,\n lastItem = len - 1;\n if (len === 0) return resolve();\n if (!hasDeleteHook) {\n for (var i = 0; i < len; ++i) {\n var req = idbstore.delete(keysOrTuples[i]);\n req.onerror = function (ev) {\n return reject(mapError(ev.target.error));\n };\n if (i === lastItem) req.onsuccess = function () {\n return resolve();\n };\n }\n } else {\n (function () {\n var hookCtx = { onsuccess: null, onerror: null },\n errorHandler = BulkErrorHandler(function (e) {\n return reject(mapError(e));\n }),\n successHandler = BulkSuccessHandler(null, true);\n miniTryCatch(function () {\n for (var i = 0; i < len; ++i) {\n var tuple = keysOrTuples[i];\n deletingHook.call(hookCtx, tuple[0], tuple[1], trans);\n var req = idbstore.delete(tuple[0]);\n if (hookCtx.onerror) req._err = hookCtx.onerror;\n if (hookCtx.onsuccess) req._suc = hookCtx.onsuccess;\n req.onerror = errorHandler;\n if (i === lastItem) req.onsuccess = BulkSuccessHandler(resolve, true);else req.onsuccess = successHandler;\n hookCtx.onsuccess = null;\n hookCtx.onerror = null;\n }\n }, function (err) {\n hookCtx.onerror && hookCtx.onerror(err);\n throw err;\n });\n })();\n }\n });\n }\n\n derive(WriteableTable).from(Table).extend(function () {\n\n return {\n bulkDelete: function (keys) {\n if (this.hook.deleting.fire === nop) {\n return this._idbstore(READWRITE, function (resolve, reject, idbstore, trans) {\n resolve(bulkDelete(idbstore, trans, keys, false, nop));\n });\n } else {\n return this.where(':id').anyOf(keys).delete().then(function () {}); // Resolve with undefined.\n }\n },\n bulkPut: function (objects, keys) {\n var _this = this;\n\n return this._idbstore(READWRITE, function (resolve, reject, idbstore, trans) {\n if (!idbstore.keyPath && !_this.schema.primKey.auto && !keys) throw new exceptions.InvalidArgument(\"bulkPut() with non-inbound keys requires keys array in second argument\");\n if (idbstore.keyPath && keys) throw new exceptions.InvalidArgument(\"bulkPut(): keys argument invalid on tables with inbound keys\");\n if (keys && keys.length !== objects.length) throw new exceptions.InvalidArgument(\"Arguments objects and keys must have the same length\");\n if (objects.length === 0) return resolve(); // Caller provided empty list.\n var done = function (result) {\n if (errorList.length === 0) resolve(result);else reject(new BulkError(_this.name + '.bulkPut(): ' + errorList.length + ' of ' + numObjs + ' operations failed', errorList));\n };\n var req,\n errorList = [],\n errorHandler,\n successHandler,\n numObjs = objects.length,\n table = trans.tables[_this.name]; // Enable us to do stuff in several steps with same transaction.\n if (_this.hook.creating.fire === nop && _this.hook.updating.fire === nop) {\n //\n // Standard Bulk (no 'creating' or 'updating' hooks to care about)\n //\n errorHandler = BulkErrorHandlerCatchAll(errorList);\n for (var i = 0, l = objects.length; i < l; ++i) {\n req = keys ? idbstore.put(objects[i], keys[i]) : idbstore.put(objects[i]);\n req.onerror = errorHandler;\n }\n // Only need to catch success or error on the last operation\n // according to the IDB spec.\n req.onerror = BulkErrorHandlerCatchAll(errorList, done);\n req.onsuccess = BulkSuccessHandler(done);\n } else {\n (function () {\n var effectiveKeys = keys || idbstore.keyPath && objects.map(function (o) {\n return getByKeyPath(o, idbstore.keyPath);\n });\n var objectLookup = effectiveKeys && effectiveKeys.reduce(function (res, key, i) {\n if (key != null) res[key] = objects[i];\n return res;\n }, {}); // Generates map of {[key]: object}\n\n var promise = !effectiveKeys ?\n\n // Auto-incremented key-less objects only without any keys argument.\n table.bulkAdd(objects) :\n\n // Keys provided. Either as inbound in provided objects, or as a keys argument.\n // Begin with updating those that exists in DB:\n table.where(':id').anyOf(Object.keys(objectLookup)).modify(function () {\n this.value = objectLookup[this.primKey];\n objectLookup[this.primKey] = null; // Mark as \"don't add this\"\n }).then(function () {\n // Now, let's examine which items didnt exist so we can add them:\n var objsToAdd = [],\n keysToAdd = keys && [];\n effectiveKeys.forEach(function (key, i) {\n if (key == null || objectLookup[key]) {\n objsToAdd.push(objects[i]);\n keys && keysToAdd.push(key);\n }\n });\n return table.bulkAdd(objsToAdd, keysToAdd);\n }).then(function (lastAddedKey) {\n // Resolve with key of the last object in given arguments to bulkPut():\n var lastEffectiveKey = effectiveKeys[effectiveKeys.length - 1]; // Key was provided.\n return lastEffectiveKey != null ? lastEffectiveKey : lastAddedKey;\n });\n\n promise.then(resolve).catch(ModifyError, function (e) {\n // Map ModifyError to BulkError\n reject(new BulkError(e.msg, e.failures));\n }).catch(reject);\n })();\n }\n }, \"locked\"); // If called from transaction scope, lock transaction til all steps are done.\n },\n bulkAdd: function (objects, keys) {\n var self = this,\n creatingHook = this.hook.creating.fire;\n return this._idbstore(READWRITE, function (resolve, reject, idbstore, trans) {\n if (!idbstore.keyPath && !self.schema.primKey.auto && !keys) throw new exceptions.InvalidArgument(\"bulkAdd() with non-inbound keys requires keys array in second argument\");\n if (idbstore.keyPath && keys) throw new exceptions.InvalidArgument(\"bulkAdd(): keys argument invalid on tables with inbound keys\");\n if (keys && keys.length !== objects.length) throw new exceptions.InvalidArgument(\"Arguments objects and keys must have the same length\");\n if (objects.length === 0) return resolve(); // Caller provided empty list.\n function done(result) {\n if (errorList.length === 0) resolve(result);else reject(new BulkError(self.name + '.bulkAdd(): ' + errorList.length + ' of ' + numObjs + ' operations failed', errorList));\n }\n var req,\n errorList = [],\n errorHandler,\n successHandler,\n numObjs = objects.length;\n if (creatingHook !== nop) {\n //\n // There are subscribers to hook('creating')\n // Must behave as documented.\n //\n var keyPath = idbstore.keyPath,\n hookCtx = { onerror: null, onsuccess: null };\n errorHandler = BulkErrorHandlerCatchAll(errorList, null);\n successHandler = BulkSuccessHandler(null, true);\n\n miniTryCatch(function () {\n for (var i = 0, l = objects.length; i < l; ++i) {\n var key = keys && keys[i];\n var obj = objects[i],\n effectiveKey = keys ? key : keyPath ? getByKeyPath(obj, keyPath) : undefined,\n keyToUse = creatingHook.call(hookCtx, effectiveKey, obj, trans);\n if (effectiveKey == null && keyToUse != null) {\n if (keyPath) {\n obj = deepClone(obj);\n setByKeyPath(obj, keyPath, keyToUse);\n } else {\n key = keyToUse;\n }\n }\n req = key != null ? idbstore.add(obj, key) : idbstore.add(obj);\n if (hookCtx.onerror) req._err = hookCtx.onerror;\n if (hookCtx.onsuccess) req._suc = hookCtx.onsuccess;\n if (i < l - 1) {\n req.onerror = errorHandler;\n if (hookCtx.onsuccess) req.onsuccess = successHandler;\n // Reset event listeners for next iteration.\n hookCtx.onerror = null;\n hookCtx.onsuccess = null;\n }\n }\n }, function (err) {\n hookCtx.onerror && hookCtx.onerror(err);\n throw err;\n });\n\n req.onerror = BulkErrorHandlerCatchAll(errorList, done);\n req.onsuccess = BulkSuccessHandler(done, true);\n } else {\n //\n // Standard Bulk (no 'creating' hook to care about)\n //\n errorHandler = BulkErrorHandlerCatchAll(errorList);\n for (var i = 0, l = objects.length; i < l; ++i) {\n req = keys ? idbstore.add(objects[i], keys[i]) : idbstore.add(objects[i]);\n req.onerror = errorHandler;\n }\n // Only need to catch success or error on the last operation\n // according to the IDB spec.\n req.onerror = BulkErrorHandlerCatchAll(errorList, done);\n req.onsuccess = BulkSuccessHandler(done);\n }\n });\n },\n add: function (obj, key) {\n /// \n /// Add an object to the database. In case an object with same primary key already exists, the object will not be added.\n /// \n /// A javascript object to insert\n /// Primary key\n var self = this,\n creatingHook = this.hook.creating.fire;\n return this._idbstore(READWRITE, function (resolve, reject, idbstore, trans) {\n var thisCtx = { onsuccess: null, onerror: null };\n if (creatingHook !== nop) {\n var effectiveKey = key != null ? key : idbstore.keyPath ? getByKeyPath(obj, idbstore.keyPath) : undefined;\n var keyToUse = creatingHook.call(thisCtx, effectiveKey, obj, trans); // Allow subscribers to when(\"creating\") to generate the key.\n if (effectiveKey == null && keyToUse != null) {\n // Using \"==\" and \"!=\" to check for either null or undefined!\n if (idbstore.keyPath) setByKeyPath(obj, idbstore.keyPath, keyToUse);else key = keyToUse;\n }\n }\n try {\n var req = key != null ? idbstore.add(obj, key) : idbstore.add(obj),\n psd = Promise.PSD;\n req.onerror = eventRejectHandler(function (e) {\n if (thisCtx.onerror) Promise.usePSD(psd, thisCtx.onerror.bind(thisCtx, e));\n return reject(e);\n }, [\"adding\", obj, \"into\", self.name]);\n req.onsuccess = function (ev) {\n var keyPath = idbstore.keyPath;\n if (keyPath) setByKeyPath(obj, keyPath, ev.target.result);\n if (thisCtx.onsuccess) Promise.usePSD(psd, thisCtx.onsuccess.bind(thisCtx, ev.target.result));\n resolve(req.result);\n };\n } catch (e) {\n if (thisCtx.onerror) thisCtx.onerror(e);\n throw e;\n }\n });\n },\n\n put: function (obj, key) {\n /// \n /// Add an object to the database but in case an object with same primary key alread exists, the existing one will get updated.\n /// \n /// A javascript object to insert or update\n /// Primary key\n var self = this,\n creatingHook = this.hook.creating.fire,\n updatingHook = this.hook.updating.fire;\n if (creatingHook !== nop || updatingHook !== nop) {\n //\n // People listens to when(\"creating\") or when(\"updating\") events!\n // We must know whether the put operation results in an CREATE or UPDATE.\n //\n return this._trans(READWRITE, function (resolve, reject, trans) {\n // Since key is optional, make sure we get it from obj if not provided\n var effectiveKey = key !== undefined ? key : self.schema.primKey.keyPath && getByKeyPath(obj, self.schema.primKey.keyPath);\n if (effectiveKey == null) {\n // \"== null\" means checking for either null or undefined.\n // No primary key. Must use add().\n trans.tables[self.name].add(obj).then(resolve, reject);\n } else {\n // Primary key exist. Lock transaction and try modifying existing. If nothing modified, call add().\n trans._lock(); // Needed because operation is splitted into modify() and add().\n // clone obj before this async call. If caller modifies obj the line after put(), the IDB spec requires that it should not affect operation.\n obj = deepClone(obj);\n trans.tables[self.name].where(\":id\").equals(effectiveKey).modify(function (value) {\n // Replace extisting value with our object\n // CRUD event firing handled in WriteableCollection.modify()\n this.value = obj;\n }).then(function (count) {\n if (count === 0) {\n // Object's key was not found. Add the object instead.\n // CRUD event firing will be done in add()\n return trans.tables[self.name].add(obj, key); // Resolving with another Promise. Returned Promise will then resolve with the new key.\n } else {\n return effectiveKey; // Resolve with the provided key.\n }\n }).finally(function () {\n trans._unlock();\n }).then(resolve, reject);\n }\n });\n } else {\n // Use the standard IDB put() method.\n return this._idbstore(READWRITE, function (resolve, reject, idbstore) {\n var req = key !== undefined ? idbstore.put(obj, key) : idbstore.put(obj);\n req.onerror = eventRejectHandler(reject, [\"putting\", obj, \"into\", self.name]);\n req.onsuccess = function (ev) {\n var keyPath = idbstore.keyPath;\n if (keyPath) setByKeyPath(obj, keyPath, ev.target.result);\n resolve(req.result);\n };\n });\n }\n },\n\n 'delete': function (key) {\n /// Primary key of the object to delete\n if (this.hook.deleting.subscribers.length) {\n // People listens to when(\"deleting\") event. Must implement delete using WriteableCollection.delete() that will\n // call the CRUD event. Only WriteableCollection.delete() will know whether an object was actually deleted.\n return this.where(\":id\").equals(key).delete();\n } else {\n // No one listens. Use standard IDB delete() method.\n return this._idbstore(READWRITE, function (resolve, reject, idbstore) {\n var req = idbstore.delete(key);\n req.onerror = eventRejectHandler(reject, [\"deleting\", key, \"from\", idbstore.name]);\n req.onsuccess = function (ev) {\n resolve(req.result);\n };\n });\n }\n },\n\n clear: function () {\n if (this.hook.deleting.subscribers.length) {\n // People listens to when(\"deleting\") event. Must implement delete using WriteableCollection.delete() that will\n // call the CRUD event. Only WriteableCollection.delete() will knows which objects that are actually deleted.\n return this.toCollection().delete();\n } else {\n return this._idbstore(READWRITE, function (resolve, reject, idbstore) {\n var req = idbstore.clear();\n req.onerror = eventRejectHandler(reject, [\"clearing\", idbstore.name]);\n req.onsuccess = function (ev) {\n resolve(req.result);\n };\n });\n }\n },\n\n update: function (keyOrObject, modifications) {\n if (typeof modifications !== 'object' || isArray(modifications)) throw new exceptions.InvalidArgument(\"db.update(keyOrObject, modifications). modifications must be an object.\");\n if (typeof keyOrObject === 'object' && !isArray(keyOrObject)) {\n // object to modify. Also modify given object with the modifications:\n keys(modifications).forEach(function (keyPath) {\n setByKeyPath(keyOrObject, keyPath, modifications[keyPath]);\n });\n var key = getByKeyPath(keyOrObject, this.schema.primKey.keyPath);\n if (key === undefined) Promise.reject(new exceptions.InvalidArgument(\"Given object does not contain its primary key\"));\n return this.where(\":id\").equals(key).modify(modifications);\n } else {\n // key to modify\n return this.where(\":id\").equals(keyOrObject).modify(modifications);\n }\n }\n };\n });\n\n //\n //\n //\n // Transaction Class\n //\n //\n //\n function Transaction(mode, storeNames, dbschema, parent) {\n /// \n /// Transaction class. Represents a database transaction. All operations on db goes through a Transaction.\n /// \n /// Any of \"readwrite\" or \"readonly\"\n /// Array of table names to operate on\n var self = this;\n this.db = db;\n this.mode = mode;\n this.storeNames = storeNames;\n this.idbtrans = null;\n this.on = Events(this, [\"complete\", \"error\"], \"abort\");\n this._reculock = 0;\n this._blockedFuncs = [];\n this._psd = null;\n this.active = true;\n this._dbschema = dbschema;\n if (parent) this.parent = parent;\n this._tpf = transactionPromiseFactory;\n this.tables = Object.create(notInTransFallbackTables); // ...so that all non-included tables exists as instances (possible to call table.name for example) but will fail as soon as trying to execute a query on it.\n\n function transactionPromiseFactory(mode, storeNames, fn, writeLocked) {\n // Creates a Promise instance and calls fn (resolve, reject, trans) where trans is the instance of this transaction object.\n // Support for write-locking the transaction during the promise life time from creation to success/failure.\n // This is actually not needed when just using single operations on IDB, since IDB implements this internally.\n // However, when implementing a write operation as a series of operations on top of IDB(collection.delete() and collection.modify() for example),\n // lock is indeed needed if Dexie APIshould behave in a consistent manner for the API user.\n // Another example of this is if we want to support create/update/delete events,\n // we need to implement put() using a series of other IDB operations but still need to lock the transaction all the way.\n return self._promise(mode, fn, writeLocked);\n }\n\n for (var i = storeNames.length - 1; i !== -1; --i) {\n var name = storeNames[i];\n var table = db._tableFactory(mode, dbschema[name], transactionPromiseFactory);\n this.tables[name] = table;\n if (!this[name]) this[name] = table;\n }\n }\n\n extend(Transaction.prototype, {\n //\n // Transaction Protected Methods (not required by API users, but needed internally and eventually by dexie extensions)\n //\n\n _lock: function () {\n // Temporary set all requests into a pending queue if they are called before database is ready.\n ++this._reculock; // Recursive read/write lock pattern using PSD (Promise Specific Data) instead of TLS (Thread Local Storage)\n if (this._reculock === 1 && Promise.PSD) Promise.PSD.lockOwnerFor = this;\n return this;\n },\n _unlock: function () {\n if (--this._reculock === 0) {\n if (Promise.PSD) Promise.PSD.lockOwnerFor = null;\n while (this._blockedFuncs.length > 0 && !this._locked()) {\n var fn = this._blockedFuncs.shift();\n try {\n fn();\n } catch (e) {}\n }\n }\n return this;\n },\n _locked: function () {\n // Checks if any write-lock is applied on this transaction.\n // To simplify the Dexie API for extension implementations, we support recursive locks.\n // This is accomplished by using \"Promise Specific Data\" (PSD).\n // PSD data is bound to a Promise and any child Promise emitted through then() or resolve( new Promise() ).\n // Promise.PSD is local to code executing on top of the call stacks of any of any code executed by Promise():\n // * callback given to the Promise() constructor (function (resolve, reject){...})\n // * callbacks given to then()/catch()/finally() methods (function (value){...})\n // If creating a new independant Promise instance from within a Promise call stack, the new Promise will derive the PSD from the call stack of the parent Promise.\n // Derivation is done so that the inner PSD __proto__ points to the outer PSD.\n // Promise.PSD.lockOwnerFor will point to current transaction object if the currently executing PSD scope owns the lock.\n return this._reculock && (!Promise.PSD || Promise.PSD.lockOwnerFor !== this);\n },\n _nop: function (cb) {\n // An asyncronic no-operation that may call given callback when done doing nothing. An alternative to asap() if we must not lose the transaction.\n this.tables[this.storeNames[0]].get(0).then(cb);\n },\n _promise: function (mode, fn, bWriteLock) {\n var self = this;\n return Promise.newPSD(function () {\n var p;\n // Read lock always\n if (!self._locked()) {\n p = self.active ? new Promise(function (resolve, reject) {\n if (!self.idbtrans && mode) {\n if (!idbdb) throw !dbOpenError || [\"DatabaseClosedError\", \"MissingAPIError\"].indexOf(dbOpenError.name) >= 0 ? dbOpenError : // Errors where it is no difference whether it was caused by the user operation or an earlier call to db.open()\n new exceptions.OpenFailed(dbOpenError); // Make it clear that the user operation was not what caused the error - the error had occurred earlier on db.open()!\n\n var idbtrans = self.idbtrans = idbdb.transaction(safariMultiStoreFix(self.storeNames), self.mode);\n idbtrans.onerror = function (e) {\n self.on(\"error\").fire(e && e.target.error);\n e.preventDefault(); // Prohibit default bubbling to window.error\n self.abort(); // Make sure transaction is aborted since we preventDefault.\n };\n idbtrans.onabort = function (e) {\n // Workaround for issue #78 - low disk space on chrome.\n // onabort is called but never onerror. Call onerror explicitely.\n // Do this in a future tick so we allow default onerror to execute before doing the fallback.\n asap(function () {\n self.on('error').fire(new exceptions.Abort(\"Transaction aborted for unknown reason\"));\n });\n\n self.active = false;\n self.on(\"abort\").fire(e);\n };\n idbtrans.oncomplete = function (e) {\n self.active = false;\n self.on(\"complete\").fire(e);\n };\n }\n if (bWriteLock) self._lock(); // Write lock if write operation is requested\n try {\n fn(resolve, reject, self);\n } catch (e) {\n (function () {\n // Direct exception happened when doing operation.\n // We must immediately fire the error and abort the transaction.\n // When this happens we are still constructing the Promise so we don't yet know\n // whether the caller is about to catch() the error or not. Have to make\n // transaction fail. Catching such an error wont stop transaction from failing.\n // This is a limitation we have to live with.\n var e2 = stack(mapError(e));\n Dexie.ignoreTransaction(function () {\n self.on('error').fire(e2);\n });\n self.abort();\n reject(e2);\n })();\n }\n }) : Promise.reject(stack(new exceptions.TransactionInactive(\"Transaction is inactive. Original Scope Function Source: \" + self.scopeFunc.toString())));\n if (self.active && bWriteLock) p.finally(function () {\n self._unlock();\n });\n } else {\n // Transaction is write-locked. Wait for mutex.\n p = new Promise(function (resolve, reject) {\n self._blockedFuncs.push(function () {\n self._promise(mode, fn, bWriteLock).then(resolve, reject);\n });\n });\n }\n p.onuncatched = function (e) {\n // Bubble to transaction. Even though IDB does this internally, it would just do it for error events and not for caught exceptions.\n Dexie.ignoreTransaction(function () {\n self.on(\"error\").fire(e);\n });\n self.abort();\n };\n return p;\n });\n },\n\n //\n // Transaction Public Methods\n //\n\n complete: function (cb) {\n return this.on(\"complete\", cb);\n },\n error: function (cb) {\n return this.on(\"error\", cb);\n },\n abort: function () {\n if (this.idbtrans && this.active) try {\n // TODO: if !this.idbtrans, enqueue an abort() operation.\n this.active = false;\n this.idbtrans.abort();\n this.on.error.fire(new exceptions.Abort(\"Transaction Aborted\"));\n } catch (e) {}\n },\n table: function (name) {\n if (!this.tables.hasOwnProperty(name)) {\n throw new exceptions.InvalidTable(\"Table \" + name + \" not in transaction\");\n }\n return this.tables[name];\n }\n });\n\n //\n //\n //\n // WhereClause\n //\n //\n //\n function WhereClause(table, index, orCollection) {\n /// \n /// \n /// \n this._ctx = {\n table: table,\n index: index === \":id\" ? null : index,\n collClass: table._collClass,\n or: orCollection\n };\n }\n\n extend(WhereClause.prototype, function () {\n\n // WhereClause private methods\n\n function fail(c, err, T) {\n var collection = c instanceof WhereClause ? new c._ctx.collClass(c) : c;\n try {\n throw T ? new T(err) : new TypeError(err);\n } catch (e) {\n collection._ctx.error = e;\n }\n return collection;\n }\n\n function emptyCollection(whereClause) {\n return new whereClause._ctx.collClass(whereClause, function () {\n return IDBKeyRange.only(\"\");\n }).limit(0);\n }\n\n function getSetArgs(args) {\n return slice(args.length === 1 && isArray(args[0]) ? args[0] : args);\n }\n\n function upperFactory(dir) {\n return dir === \"next\" ? function (s) {\n return s.toUpperCase();\n } : function (s) {\n return s.toLowerCase();\n };\n }\n function lowerFactory(dir) {\n return dir === \"next\" ? function (s) {\n return s.toLowerCase();\n } : function (s) {\n return s.toUpperCase();\n };\n }\n function nextCasing(key, lowerKey, upperNeedle, lowerNeedle, cmp, dir) {\n var length = Math.min(key.length, lowerNeedle.length);\n var llp = -1;\n for (var i = 0; i < length; ++i) {\n var lwrKeyChar = lowerKey[i];\n if (lwrKeyChar !== lowerNeedle[i]) {\n if (cmp(key[i], upperNeedle[i]) < 0) return key.substr(0, i) + upperNeedle[i] + upperNeedle.substr(i + 1);\n if (cmp(key[i], lowerNeedle[i]) < 0) return key.substr(0, i) + lowerNeedle[i] + upperNeedle.substr(i + 1);\n if (llp >= 0) return key.substr(0, llp) + lowerKey[llp] + upperNeedle.substr(llp + 1);\n return null;\n }\n if (cmp(key[i], lwrKeyChar) < 0) llp = i;\n }\n if (length < lowerNeedle.length && dir === \"next\") return key + upperNeedle.substr(key.length);\n if (length < key.length && dir === \"prev\") return key.substr(0, upperNeedle.length);\n return llp < 0 ? null : key.substr(0, llp) + lowerNeedle[llp] + upperNeedle.substr(llp + 1);\n }\n\n function addIgnoreCaseAlgorithm(whereClause, match, needles, suffix) {\n /// \n var upper,\n lower,\n compare,\n upperNeedles,\n lowerNeedles,\n direction,\n nextKeySuffix,\n needlesLen = needles.length;\n function initDirection(dir) {\n upper = upperFactory(dir);\n lower = lowerFactory(dir);\n compare = dir === \"next\" ? simpleCompare : simpleCompareReverse;\n var needleBounds = needles.map(function (needle) {\n return { lower: lower(needle), upper: upper(needle) };\n }).sort(function (a, b) {\n return compare(a.lower, b.lower);\n });\n upperNeedles = needleBounds.map(function (nb) {\n return nb.upper;\n });\n lowerNeedles = needleBounds.map(function (nb) {\n return nb.lower;\n });\n direction = dir;\n nextKeySuffix = dir === \"next\" ? \"\" : suffix;\n }\n initDirection(\"next\");\n\n var c = new whereClause._ctx.collClass(whereClause, function () {\n return IDBKeyRange.bound(upperNeedles[0], lowerNeedles[needlesLen - 1] + suffix);\n });\n\n c._ondirectionchange = function (direction) {\n // This event onlys occur before filter is called the first time.\n initDirection(direction);\n };\n\n var firstPossibleNeedle = 0;\n\n c._addAlgorithm(function (cursor, advance, resolve) {\n /// \n /// \n /// \n var key = cursor.key;\n if (typeof key !== 'string') return false;\n var lowerKey = lower(key);\n if (match(lowerKey, lowerNeedles, firstPossibleNeedle)) {\n return true;\n } else {\n var lowestPossibleCasing = null;\n for (var i = firstPossibleNeedle; i < needlesLen; ++i) {\n var casing = nextCasing(key, lowerKey, upperNeedles[i], lowerNeedles[i], compare, direction);\n if (casing === null && lowestPossibleCasing === null) firstPossibleNeedle = i + 1;else if (lowestPossibleCasing === null || compare(lowestPossibleCasing, casing) > 0) {\n lowestPossibleCasing = casing;\n }\n }\n if (lowestPossibleCasing !== null) {\n advance(function () {\n cursor.continue(lowestPossibleCasing + nextKeySuffix);\n });\n } else {\n advance(resolve);\n }\n return false;\n }\n });\n return c;\n }\n\n //\n // WhereClause public methods\n //\n return {\n between: function (lower, upper, includeLower, includeUpper) {\n /// \n /// Filter out records whose where-field lays between given lower and upper values. Applies to Strings, Numbers and Dates.\n /// \n /// \n /// \n /// Whether items that equals lower should be included. Default true.\n /// Whether items that equals upper should be included. Default false.\n /// \n includeLower = includeLower !== false; // Default to true\n includeUpper = includeUpper === true; // Default to false\n try {\n if (cmp(lower, upper) > 0 || cmp(lower, upper) === 0 && (includeLower || includeUpper) && !(includeLower && includeUpper)) return emptyCollection(this); // Workaround for idiotic W3C Specification that DataError must be thrown if lower > upper. The natural result would be to return an empty collection.\n return new this._ctx.collClass(this, function () {\n return IDBKeyRange.bound(lower, upper, !includeLower, !includeUpper);\n });\n } catch (e) {\n return fail(this, INVALID_KEY_ARGUMENT);\n }\n },\n equals: function (value) {\n return new this._ctx.collClass(this, function () {\n return IDBKeyRange.only(value);\n });\n },\n above: function (value) {\n return new this._ctx.collClass(this, function () {\n return IDBKeyRange.lowerBound(value, true);\n });\n },\n aboveOrEqual: function (value) {\n return new this._ctx.collClass(this, function () {\n return IDBKeyRange.lowerBound(value);\n });\n },\n below: function (value) {\n return new this._ctx.collClass(this, function () {\n return IDBKeyRange.upperBound(value, true);\n });\n },\n belowOrEqual: function (value) {\n return new this._ctx.collClass(this, function () {\n return IDBKeyRange.upperBound(value);\n });\n },\n startsWith: function (str) {\n /// \n if (typeof str !== 'string') return fail(this, STRING_EXPECTED);\n return this.between(str, str + maxString, true, true);\n },\n startsWithIgnoreCase: function (str) {\n /// \n if (typeof str !== 'string') return fail(this, STRING_EXPECTED);\n if (str === \"\") return this.startsWith(str);\n return addIgnoreCaseAlgorithm(this, function (x, a) {\n return x.indexOf(a[0]) === 0;\n }, [str], maxString);\n },\n equalsIgnoreCase: function (str) {\n /// \n if (typeof str !== 'string') return fail(this, STRING_EXPECTED);\n return addIgnoreCaseAlgorithm(this, function (x, a) {\n return x === a[0];\n }, [str], \"\");\n },\n anyOfIgnoreCase: function (stringsToFind) {\n var set = getSetArgs(arguments);\n if (set.length === 0) return emptyCollection(this);\n if (!set.every(function (s) {\n return typeof s === 'string';\n })) {\n return fail(this, \"anyOfIgnoreCase() only works with strings\");\n }\n return addIgnoreCaseAlgorithm(this, function (x, a) {\n return a.indexOf(x) !== -1;\n }, set, \"\");\n },\n startsWithAnyOfIgnoreCase: function (stringsToFind) {\n var set = getSetArgs(arguments);\n if (set.length === 0) return emptyCollection(this);\n if (!set.every(function (s) {\n return typeof s === 'string';\n })) {\n return fail(this, \"startsWithAnyOfIgnoreCase() only works with strings\");\n }\n return addIgnoreCaseAlgorithm(this, function (x, a) {\n return a.some(function (n) {\n return x.indexOf(n) === 0;\n });\n }, set, maxString);\n },\n anyOf: function (valueArray) {\n var set = getSetArgs(arguments);\n var compare = ascending;\n try {\n set.sort(compare);\n } catch (e) {\n return fail(this, INVALID_KEY_ARGUMENT);\n }\n if (set.length === 0) return emptyCollection(this);\n var c = new this._ctx.collClass(this, function () {\n return IDBKeyRange.bound(set[0], set[set.length - 1]);\n });\n\n c._ondirectionchange = function (direction) {\n compare = direction === \"next\" ? ascending : descending;\n set.sort(compare);\n };\n var i = 0;\n c._addAlgorithm(function (cursor, advance, resolve) {\n var key = cursor.key;\n while (compare(key, set[i]) > 0) {\n // The cursor has passed beyond this key. Check next.\n ++i;\n if (i === set.length) {\n // There is no next. Stop searching.\n advance(resolve);\n return false;\n }\n }\n if (compare(key, set[i]) === 0) {\n // The current cursor value should be included and we should continue a single step in case next item has the same key or possibly our next key in set.\n return true;\n } else {\n // cursor.key not yet at set[i]. Forward cursor to the next key to hunt for.\n advance(function () {\n cursor.continue(set[i]);\n });\n return false;\n }\n });\n return c;\n },\n\n notEqual: function (value) {\n return this.inAnyRange([[-Infinity, value], [value, maxKey]], { includeLowers: false, includeUppers: false });\n },\n\n noneOf: function (valueArray) {\n var set = getSetArgs(arguments);\n if (set.length === 0) return new this._ctx.collClass(this); // Return entire collection.\n try {\n set.sort(ascending);\n } catch (e) {\n return fail(this, INVALID_KEY_ARGUMENT);\n }\n // Transform [\"a\",\"b\",\"c\"] to a set of ranges for between/above/below: [[-Infinity,\"a\"], [\"a\",\"b\"], [\"b\",\"c\"], [\"c\",maxKey]]\n var ranges = set.reduce(function (res, val) {\n return res ? res.concat([[res[res.length - 1][1], val]]) : [[-Infinity, val]];\n }, null);\n ranges.push([set[set.length - 1], maxKey]);\n return this.inAnyRange(ranges, { includeLowers: false, includeUppers: false });\n },\n\n /** Filter out values withing given set of ranges.\r\n * Example, give children and elders a rebate of 50%:\r\n *\r\n * db.friends.where('age').inAnyRange([[0,18],[65,Infinity]]).modify({Rebate: 1/2});\r\n *\r\n * @param {(string|number|Date|Array)[][]} ranges\r\n * @param {{includeLowers: boolean, includeUppers: boolean}} options\r\n */\n inAnyRange: function (ranges, options) {\n var ctx = this._ctx;\n if (ranges.length === 0) return emptyCollection(this);\n if (!ranges.every(function (range) {\n return range[0] !== undefined && range[1] !== undefined && ascending(range[0], range[1]) <= 0;\n })) {\n return fail(this, \"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower\", exceptions.InvalidArgument);\n }\n var includeLowers = !options || options.includeLowers !== false; // Default to true\n var includeUppers = options && options.includeUppers === true; // Default to false\n\n function addRange(ranges, newRange) {\n for (var i = 0, l = ranges.length; i < l; ++i) {\n var range = ranges[i];\n if (cmp(newRange[0], range[1]) < 0 && cmp(newRange[1], range[0]) > 0) {\n range[0] = min(range[0], newRange[0]);\n range[1] = max(range[1], newRange[1]);\n break;\n }\n }\n if (i === l) ranges.push(newRange);\n return ranges;\n }\n\n var sortDirection = ascending;\n function rangeSorter(a, b) {\n return sortDirection(a[0], b[0]);\n }\n\n // Join overlapping ranges\n var set;\n try {\n set = ranges.reduce(addRange, []);\n set.sort(rangeSorter);\n } catch (ex) {\n return fail(this, INVALID_KEY_ARGUMENT);\n }\n\n var i = 0;\n var keyIsBeyondCurrentEntry = includeUppers ? function (key) {\n return ascending(key, set[i][1]) > 0;\n } : function (key) {\n return ascending(key, set[i][1]) >= 0;\n };\n\n var keyIsBeforeCurrentEntry = includeLowers ? function (key) {\n return descending(key, set[i][0]) > 0;\n } : function (key) {\n return descending(key, set[i][0]) >= 0;\n };\n\n function keyWithinCurrentRange(key) {\n return !keyIsBeyondCurrentEntry(key) && !keyIsBeforeCurrentEntry(key);\n }\n\n var checkKey = keyIsBeyondCurrentEntry;\n\n var c = new ctx.collClass(this, function () {\n return IDBKeyRange.bound(set[0][0], set[set.length - 1][1], !includeLowers, !includeUppers);\n });\n\n c._ondirectionchange = function (direction) {\n if (direction === \"next\") {\n checkKey = keyIsBeyondCurrentEntry;\n sortDirection = ascending;\n } else {\n checkKey = keyIsBeforeCurrentEntry;\n sortDirection = descending;\n }\n set.sort(rangeSorter);\n };\n\n c._addAlgorithm(function (cursor, advance, resolve) {\n var key = cursor.key;\n while (checkKey(key)) {\n // The cursor has passed beyond this key. Check next.\n ++i;\n if (i === set.length) {\n // There is no next. Stop searching.\n advance(resolve);\n return false;\n }\n }\n if (keyWithinCurrentRange(key)) {\n // The current cursor value should be included and we should continue a single step in case next item has the same key or possibly our next key in set.\n return true;\n } else if (cmp(key, set[i][1]) === 0 || cmp(key, set[i][0]) === 0) {\n // includeUpper or includeLower is false so keyWithinCurrentRange() returns false even though we are at range border.\n // Continue to next key but don't include this one.\n return false;\n } else {\n // cursor.key not yet at set[i]. Forward cursor to the next key to hunt for.\n advance(function () {\n if (sortDirection === ascending) cursor.continue(set[i][0]);else cursor.continue(set[i][1]);\n });\n return false;\n }\n });\n return c;\n },\n startsWithAnyOf: function (valueArray) {\n var set = getSetArgs(arguments);\n\n if (!set.every(function (s) {\n return typeof s === 'string';\n })) {\n return fail(this, \"startsWithAnyOf() only works with strings\");\n }\n if (set.length === 0) return emptyCollection(this);\n\n return this.inAnyRange(set.map(function (str) {\n return [str, str + maxString];\n }));\n }\n };\n });\n\n //\n //\n //\n // Collection Class\n //\n //\n //\n function Collection(whereClause, keyRangeGenerator) {\n /// \n ///\n /// \n /// Where clause instance\n /// \n var keyRange = null,\n error = null;\n if (keyRangeGenerator) try {\n keyRange = keyRangeGenerator();\n } catch (ex) {\n error = stack(mapError(ex));\n }\n\n var whereCtx = whereClause._ctx,\n table = whereCtx.table;\n this._ctx = {\n table: table,\n index: whereCtx.index,\n isPrimKey: !whereCtx.index || table.schema.primKey.keyPath && whereCtx.index === table.schema.primKey.name,\n range: keyRange,\n keysOnly: false,\n dir: \"next\",\n unique: \"\",\n algorithm: null,\n filter: null,\n replayFilter: null,\n isMatch: null,\n offset: 0,\n limit: Infinity,\n error: error, // If set, any promise must be rejected with this error\n or: whereCtx.or,\n valueFilter: table.hook.reading.fire\n };\n }\n\n extend(Collection.prototype, function () {\n\n //\n // Collection Private Functions\n //\n\n function addFilter(ctx, fn) {\n ctx.filter = combine(ctx.filter, fn);\n }\n\n function addReplayFilter(ctx, factory) {\n var curr = ctx.replayFilter;\n ctx.replayFilter = curr ? function () {\n return combine(curr(), factory());\n } : factory;\n }\n\n function addMatchFilter(ctx, fn) {\n ctx.isMatch = combine(ctx.isMatch, fn);\n }\n\n function getIndexOrStore(ctx, store) {\n if (ctx.isPrimKey) return store;\n var indexSpec = ctx.table.schema.idxByName[ctx.index];\n if (!indexSpec) throw new exceptions.Schema(\"KeyPath \" + ctx.index + \" on object store \" + store.name + \" is not indexed\");\n return store.index(indexSpec.name);\n }\n\n function openCursor(ctx, store) {\n var idxOrStore = getIndexOrStore(ctx, store);\n return ctx.keysOnly && 'openKeyCursor' in idxOrStore ? idxOrStore.openKeyCursor(ctx.range || null, ctx.dir + ctx.unique) : idxOrStore.openCursor(ctx.range || null, ctx.dir + ctx.unique);\n }\n\n function iter(ctx, fn, resolve, reject, idbstore) {\n var filter = ctx.replayFilter ? combine(ctx.filter, ctx.replayFilter()) : ctx.filter;\n if (!ctx.or) {\n iterate(openCursor(ctx, idbstore), combine(ctx.algorithm, filter), fn, resolve, reject, !ctx.keysOnly && ctx.valueFilter);\n } else {\n (function () {\n var set = {};\n var resolved = 0;\n\n function resolveboth() {\n if (++resolved === 2) resolve(); // Seems like we just support or btwn max 2 expressions, but there are no limit because we do recursion.\n }\n\n function union(item, cursor, advance) {\n if (!filter || filter(cursor, advance, resolveboth, reject)) {\n var key = cursor.primaryKey.toString(); // Converts any Date to String, String to String, Number to String and Array to comma-separated string\n if (!set.hasOwnProperty(key)) {\n set[key] = true;\n fn(item, cursor, advance);\n }\n }\n }\n\n ctx.or._iterate(union, resolveboth, reject, idbstore);\n iterate(openCursor(ctx, idbstore), ctx.algorithm, union, resolveboth, reject, !ctx.keysOnly && ctx.valueFilter);\n })();\n }\n }\n function getInstanceTemplate(ctx) {\n return ctx.table.schema.instanceTemplate;\n }\n\n return {\n\n //\n // Collection Protected Functions\n //\n\n _read: function (fn, cb) {\n var ctx = this._ctx;\n if (ctx.error) return ctx.table._trans(null, function rejector(resolve, reject) {\n reject(ctx.error);\n });else return ctx.table._idbstore(READONLY, fn).then(cb);\n },\n _write: function (fn) {\n var ctx = this._ctx;\n if (ctx.error) return ctx.table._trans(null, function rejector(resolve, reject) {\n reject(ctx.error);\n });else return ctx.table._idbstore(READWRITE, fn, \"locked\"); // When doing write operations on collections, always lock the operation so that upcoming operations gets queued.\n },\n _addAlgorithm: function (fn) {\n var ctx = this._ctx;\n ctx.algorithm = combine(ctx.algorithm, fn);\n },\n\n _iterate: function (fn, resolve, reject, idbstore) {\n return iter(this._ctx, fn, resolve, reject, idbstore);\n },\n\n clone: function (props) {\n var rv = Object.create(this.constructor.prototype),\n ctx = Object.create(this._ctx);\n if (props) extend(ctx, props);\n rv._ctx = ctx;\n return rv;\n },\n\n raw: function () {\n this._ctx.valueFilter = null;\n return this;\n },\n\n //\n // Collection Public methods\n //\n\n each: function (fn) {\n var ctx = this._ctx;\n\n fake && fn(getInstanceTemplate(ctx));\n\n return this._read(function (resolve, reject, idbstore) {\n iter(ctx, fn, resolve, reject, idbstore);\n });\n },\n\n count: function (cb) {\n if (fake) return Promise.resolve(0).then(cb);\n var self = this,\n ctx = this._ctx;\n\n if (ctx.filter || ctx.algorithm || ctx.or || ctx.replayFilter) {\n // When filters are applied or 'ored' collections are used, we must count manually\n var count = 0;\n return this._read(function (resolve, reject, idbstore) {\n iter(ctx, function () {\n ++count;return false;\n }, function () {\n resolve(count);\n }, reject, idbstore);\n }, cb);\n } else {\n // Otherwise, we can use the count() method if the index.\n return this._read(function (resolve, reject, idbstore) {\n var idx = getIndexOrStore(ctx, idbstore);\n var req = ctx.range ? idx.count(ctx.range) : idx.count();\n req.onerror = eventRejectHandler(reject, [\"calling\", \"count()\", \"on\", self.name]);\n req.onsuccess = function (e) {\n resolve(e.target.result);\n };\n }, cb);\n }\n },\n\n sortBy: function (keyPath, cb) {\n /// \n var parts = keyPath.split('.').reverse(),\n lastPart = parts[0],\n lastIndex = parts.length - 1;\n function getval(obj, i) {\n if (i) return getval(obj[parts[i]], i - 1);\n return obj[lastPart];\n }\n var order = this._ctx.dir === \"next\" ? 1 : -1;\n\n function sorter(a, b) {\n var aVal = getval(a, lastIndex),\n bVal = getval(b, lastIndex);\n return aVal < bVal ? -order : aVal > bVal ? order : 0;\n }\n return this.toArray(function (a) {\n return a.sort(sorter);\n }).then(cb);\n },\n\n toArray: function (cb) {\n var ctx = this._ctx;\n return this._read(function (resolve, reject, idbstore) {\n fake && resolve([getInstanceTemplate(ctx)]);\n var a = [];\n iter(ctx, function (item) {\n a.push(item);\n }, function arrayComplete() {\n resolve(a);\n }, reject, idbstore);\n }, cb);\n },\n\n offset: function (offset) {\n var ctx = this._ctx;\n if (offset <= 0) return this;\n ctx.offset += offset; // For count()\n if (!ctx.or && !ctx.algorithm && !ctx.filter && !ctx.replayFilter) {\n addReplayFilter(ctx, function () {\n var offsetLeft = offset;\n return function offsetFilter(cursor, advance, resolve) {\n if (offsetLeft === 0) return true;\n if (offsetLeft === 1) {\n --offsetLeft;return false;\n }\n advance(function () {\n cursor.advance(offsetLeft);offsetLeft = 0;\n });\n return false;\n };\n });\n } else {\n addReplayFilter(ctx, function () {\n var offsetLeft = offset;\n return function () {\n return --offsetLeft < 0;\n };\n });\n }\n return this;\n },\n\n limit: function (numRows) {\n this._ctx.limit = Math.min(this._ctx.limit, numRows); // For count()\n addReplayFilter(this._ctx, function () {\n var rowsLeft = numRows;\n return function (cursor, advance, resolve) {\n if (--rowsLeft <= 0) advance(resolve); // Stop after this item has been included\n return rowsLeft >= 0; // If numRows is already below 0, return false because then 0 was passed to numRows initially. Otherwise we wouldnt come here.\n };\n });\n return this;\n },\n\n until: function (filterFunction, bIncludeStopEntry) {\n var ctx = this._ctx;\n fake && filterFunction(getInstanceTemplate(ctx));\n addFilter(this._ctx, function (cursor, advance, resolve) {\n if (filterFunction(cursor.value)) {\n advance(resolve);\n return bIncludeStopEntry;\n } else {\n return true;\n }\n });\n return this;\n },\n\n first: function (cb) {\n return this.limit(1).toArray(function (a) {\n return a[0];\n }).then(cb);\n },\n\n last: function (cb) {\n return this.reverse().first(cb);\n },\n\n and: function (filterFunction) {\n /// function(val){return true/false}\n fake && filterFunction(getInstanceTemplate(this._ctx));\n addFilter(this._ctx, function (cursor) {\n return filterFunction(cursor.value);\n });\n addMatchFilter(this._ctx, filterFunction); // match filters not used in Dexie.js but can be used by 3rd part libraries to test a collection for a match without querying DB. Used by Dexie.Observable.\n return this;\n },\n\n or: function (indexName) {\n return new WhereClause(this._ctx.table, indexName, this);\n },\n\n reverse: function () {\n this._ctx.dir = this._ctx.dir === \"prev\" ? \"next\" : \"prev\";\n if (this._ondirectionchange) this._ondirectionchange(this._ctx.dir);\n return this;\n },\n\n desc: function () {\n return this.reverse();\n },\n\n eachKey: function (cb) {\n var ctx = this._ctx;\n fake && cb(getByKeyPath(getInstanceTemplate(this._ctx), this._ctx.index ? this._ctx.table.schema.idxByName[this._ctx.index].keyPath : this._ctx.table.schema.primKey.keyPath));\n ctx.keysOnly = true;\n return this.each(function (val, cursor) {\n cb(cursor.key, cursor);\n });\n },\n\n eachUniqueKey: function (cb) {\n this._ctx.unique = \"unique\";\n return this.eachKey(cb);\n },\n\n keys: function (cb) {\n var ctx = this._ctx;\n ctx.keysOnly = true;\n var a = [];\n if (fake) return new Promise(this.eachKey.bind(this)).then(function (x) {\n return [x];\n }).then(cb);\n return this.each(function (item, cursor) {\n a.push(cursor.key);\n }).then(function () {\n return a;\n }).then(cb);\n },\n\n uniqueKeys: function (cb) {\n this._ctx.unique = \"unique\";\n return this.keys(cb);\n },\n\n firstKey: function (cb) {\n return this.limit(1).keys(function (a) {\n return a[0];\n }).then(cb);\n },\n\n lastKey: function (cb) {\n return this.reverse().firstKey(cb);\n },\n\n distinct: function () {\n var ctx = this._ctx,\n idx = ctx.index && ctx.table.schema.idxByName[ctx.index];\n if (!idx || !idx.multi) return this; // distinct() only makes differencies on multiEntry indexes.\n var set = {};\n addFilter(this._ctx, function (cursor) {\n var strKey = cursor.primaryKey.toString(); // Converts any Date to String, String to String, Number to String and Array to comma-separated string\n var found = set.hasOwnProperty(strKey);\n set[strKey] = true;\n return !found;\n });\n return this;\n }\n };\n });\n\n //\n //\n // WriteableCollection Class\n //\n //\n function WriteableCollection() {\n Collection.apply(this, arguments);\n }\n\n derive(WriteableCollection).from(Collection).extend({\n\n //\n // WriteableCollection Public Methods\n //\n\n modify: function (changes) {\n var self = this,\n ctx = this._ctx,\n hook = ctx.table.hook,\n updatingHook = hook.updating.fire,\n deletingHook = hook.deleting.fire;\n\n fake && typeof changes === 'function' && changes.call({ value: ctx.table.schema.instanceTemplate }, ctx.table.schema.instanceTemplate);\n\n return this._write(function (resolve, reject, idbstore, trans) {\n var modifyer;\n if (typeof changes === 'function') {\n // Changes is a function that may update, add or delete propterties or even require a deletion the object itself (delete this.item)\n if (updatingHook === nop && deletingHook === nop) {\n // Noone cares about what is being changed. Just let the modifier function be the given argument as is.\n modifyer = changes;\n } else {\n // People want to know exactly what is being modified or deleted.\n // Let modifyer be a proxy function that finds out what changes the caller is actually doing\n // and call the hooks accordingly!\n modifyer = function (item) {\n var origItem = deepClone(item); // Clone the item first so we can compare laters.\n if (changes.call(this, item, this) === false) return false; // Call the real modifyer function (If it returns false explicitely, it means it dont want to modify anyting on this object)\n if (!this.hasOwnProperty(\"value\")) {\n // The real modifyer function requests a deletion of the object. Inform the deletingHook that a deletion is taking place.\n deletingHook.call(this, this.primKey, item, trans);\n } else {\n // No deletion. Check what was changed\n var objectDiff = getObjectDiff(origItem, this.value);\n var additionalChanges = updatingHook.call(this, objectDiff, this.primKey, origItem, trans);\n if (additionalChanges) {\n // Hook want to apply additional modifications. Make sure to fullfill the will of the hook.\n item = this.value;\n keys(additionalChanges).forEach(function (keyPath) {\n setByKeyPath(item, keyPath, additionalChanges[keyPath]); // Adding {keyPath: undefined} means that the keyPath should be deleted. Handled by setByKeyPath\n });\n }\n }\n };\n }\n } else if (updatingHook === nop) {\n // changes is a set of {keyPath: value} and no one is listening to the updating hook.\n var keyPaths = keys(changes);\n var numKeys = keyPaths.length;\n modifyer = function (item) {\n var anythingModified = false;\n for (var i = 0; i < numKeys; ++i) {\n var keyPath = keyPaths[i],\n val = changes[keyPath];\n if (getByKeyPath(item, keyPath) !== val) {\n setByKeyPath(item, keyPath, val); // Adding {keyPath: undefined} means that the keyPath should be deleted. Handled by setByKeyPath\n anythingModified = true;\n }\n }\n return anythingModified;\n };\n } else {\n // changes is a set of {keyPath: value} and people are listening to the updating hook so we need to call it and\n // allow it to add additional modifications to make.\n var origChanges = changes;\n changes = shallowClone(origChanges); // Let's work with a clone of the changes keyPath/value set so that we can restore it in case a hook extends it.\n modifyer = function (item) {\n var anythingModified = false;\n var additionalChanges = updatingHook.call(this, changes, this.primKey, deepClone(item), trans);\n if (additionalChanges) extend(changes, additionalChanges);\n keys(changes).forEach(function (keyPath) {\n var val = changes[keyPath];\n if (getByKeyPath(item, keyPath) !== val) {\n setByKeyPath(item, keyPath, val);\n anythingModified = true;\n }\n });\n if (additionalChanges) changes = shallowClone(origChanges); // Restore original changes for next iteration\n return anythingModified;\n };\n }\n\n var count = 0;\n var successCount = 0;\n var iterationComplete = false;\n var failures = [];\n var failKeys = [];\n var currentKey = null;\n\n function modifyItem(item, cursor, advance) {\n currentKey = cursor.primaryKey;\n var thisContext = {\n primKey: cursor.primaryKey,\n value: item,\n onsuccess: null,\n onerror: null\n };\n\n function onerror(e) {\n failures.push(e);\n failKeys.push(thisContext.primKey);\n if (thisContext.onerror) Promise.newPSD(function () {\n Promise.PSD.trans = trans;\n thisContext.onerror(e);\n });\n checkFinished();\n return true; // Catch these errors and let a final rejection decide whether or not to abort entire transaction\n }\n\n if (modifyer.call(thisContext, item, thisContext) !== false) {\n // If a callback explicitely returns false, do not perform the update!\n var bDelete = !thisContext.hasOwnProperty(\"value\");\n ++count;\n miniTryCatch(function () {\n var req = bDelete ? cursor.delete() : cursor.update(thisContext.value);\n req.onerror = eventRejectHandler(onerror, bDelete ? [\"deleting\", item, \"from\", ctx.table.name] : [\"modifying\", item, \"on\", ctx.table.name]);\n req.onsuccess = function (ev) {\n if (thisContext.onsuccess) Promise.newPSD(function () {\n Promise.PSD.trans = trans;\n thisContext.onsuccess(thisContext.value);\n });\n ++successCount;\n checkFinished();\n };\n }, onerror);\n } else if (thisContext.onsuccess) {\n // Hook will expect either onerror or onsuccess to always be called!\n thisContext.onsuccess(thisContext.value);\n }\n }\n\n function doReject(e) {\n if (e) {\n failures.push(e);\n failKeys.push(currentKey);\n }\n return reject(new ModifyError(\"Error modifying one or more objects\", failures, successCount, failKeys));\n }\n\n function checkFinished() {\n if (iterationComplete && successCount + failures.length === count) {\n if (failures.length > 0) doReject();else resolve(successCount);\n }\n }\n self.clone().raw()._iterate(modifyItem, function () {\n iterationComplete = true;\n checkFinished();\n }, doReject, idbstore);\n });\n },\n\n 'delete': function () {\n var _this2 = this;\n\n var ctx = this._ctx,\n range = ctx.range,\n deletingHook = ctx.table.hook.deleting.fire,\n hasDeleteHook = deletingHook !== nop;\n if (!hasDeleteHook && !ctx.or && !ctx.algorithm && !ctx.filter && !ctx.replayFilter && (ctx.isPrimKey && !hangsOnDeleteLargeKeyRange || !range)) // if no range, we'll use clear().\n {\n // May use IDBObjectStore.delete(IDBKeyRange) in this case (Issue #208)\n // For chromium, this is the way most optimized version.\n // For IE/Edge, this could hang the indexedDB engine and make operating system instable\n // (https://gist.github.com/dfahlander/5a39328f029de18222cf2125d56c38f7)\n return this._write(function (resolve, reject, idbstore) {\n // Our API contract is to return a count of deleted items, so we have to count() before delete().\n var onerror = eventRejectHandler(reject, [\"deleting range from\", ctx.table.name]);\n var countReq = range ? idbstore.count(range) : idbstore.count();\n countReq.onerror = onerror;\n countReq.onsuccess = function () {\n var count = countReq.result;\n miniTryCatch(function () {\n var delReq = range ? idbstore.delete(range) : idbstore.clear();\n delReq.onerror = onerror;\n delReq.onsuccess = function () {\n return resolve(count);\n };\n }, function (err) {\n return reject(mapError(err));\n });\n };\n });\n }\n\n // Default version to use when collection is not a vanilla IDBKeyRange on the primary key.\n // Divide into chunks to not starve RAM.\n // If has delete hook, we will have to collect not just keys but also objects, so it will use\n // more memory and need lower chunk size.\n var CHUNKSIZE = hasDeleteHook ? 2000 : 10000;\n\n return this._write(function (resolve, reject, idbstore, trans) {\n var totalCount = 0;\n // Clone table and change the way transaction promises are generated.\n // This is to be able to call other Collection methods within the same\n // transaction even if the caller calls us without a transaction.\n var table = Object.create(ctx.table);\n table._tpf = trans._tpf; // Enable us to keep same transaction even if called without transaction.\n // Clone collection and change its table and set a limit of CHUNKSIZE on the cloned Collection instance.\n var collection = _this2.clone({\n table: table, // Execute in same transaction\n keysOnly: !hasDeleteHook }) // load just keys (unless deleteHook has subscribers)\n .distinct() // In case multiEntry is used, never delete same key twice because resulting count\n // would become larger than actual delete count.\n .limit(CHUNKSIZE).raw(); // Don't filter through reading-hooks (like mapped classes etc)\n\n var keysOrTuples = [];\n\n // We're gonna do things on as many chunks that are needed.\n // Use recursion of nextChunk function:\n var nextChunk = function () {\n return collection.each(hasDeleteHook ? function (val, cursor) {\n // Somebody subscribes to hook('deleting'). Collect all primary keys and their values,\n // so that the hook can be called with its values in bulkDelete().\n keysOrTuples.push([cursor.primaryKey, cursor.value]);\n } : function (val, cursor) {\n // No one subscribes to hook('deleting'). Collect only primary keys:\n keysOrTuples.push(cursor.primaryKey);\n }).then(function () {\n // Chromium deletes faster when doing it in sort order.\n hasDeleteHook ? keysOrTuples.sort(function (a, b) {\n return ascending(a[0], b[0]);\n }) : keysOrTuples.sort(ascending);\n return bulkDelete(idbstore, trans, keysOrTuples, hasDeleteHook, deletingHook);\n }).then(function () {\n var count = keysOrTuples.length;\n totalCount += count;\n keysOrTuples = [];\n return count < CHUNKSIZE ? totalCount : nextChunk();\n });\n };\n\n resolve(nextChunk());\n });\n }\n });\n\n //\n //\n //\n // ------------------------- Help functions ---------------------------\n //\n //\n //\n\n function lowerVersionFirst(a, b) {\n return a._cfg.version - b._cfg.version;\n }\n\n function setApiOnPlace(objs, transactionPromiseFactory, tableNames, mode, dbschema, enableProhibitedDB) {\n tableNames.forEach(function (tableName) {\n var tableInstance = db._tableFactory(mode, dbschema[tableName], transactionPromiseFactory);\n objs.forEach(function (obj) {\n if (!obj[tableName]) {\n if (enableProhibitedDB) {\n Object.defineProperty(obj, tableName, {\n configurable: true,\n enumerable: true,\n get: function () {\n var currentTrans = Promise.PSD && Promise.PSD.trans;\n if (currentTrans && currentTrans.db === db) {\n return currentTrans.tables[tableName];\n }\n return tableInstance;\n }\n });\n } else {\n obj[tableName] = tableInstance;\n }\n }\n });\n });\n }\n\n function removeTablesApi(objs) {\n objs.forEach(function (obj) {\n for (var key in obj) {\n if (obj[key] instanceof Table) delete obj[key];\n }\n });\n }\n\n function iterate(req, filter, fn, resolve, reject, valueFilter) {\n valueFilter = valueFilter || mirror;\n if (!req.onerror) req.onerror = eventRejectHandler(reject);\n if (filter) {\n req.onsuccess = trycatch(function filter_record(e) {\n var cursor = req.result;\n if (cursor) {\n var c = function () {\n cursor.continue();\n };\n if (filter(cursor, function (advancer) {\n c = advancer;\n }, resolve, reject)) fn(valueFilter(cursor.value), cursor, function (advancer) {\n c = advancer;\n });\n c();\n } else {\n resolve();\n }\n }, reject);\n } else {\n req.onsuccess = trycatch(function filter_record(e) {\n var cursor = req.result;\n if (cursor) {\n var c = function () {\n cursor.continue();\n };\n fn(valueFilter(cursor.value), cursor, function (advancer) {\n c = advancer;\n });\n c();\n } else {\n resolve();\n }\n }, reject);\n }\n }\n\n function parseIndexSyntax(indexes) {\n /// \n /// \n var rv = [];\n indexes.split(',').forEach(function (index) {\n index = index.trim();\n var name = index.replace(\"&\", \"\").replace(\"++\", \"\").replace(\"*\", \"\");\n var keyPath = name.indexOf('[') !== 0 ? name : index.substring(index.indexOf('[') + 1, index.indexOf(']')).split('+');\n\n rv.push(new IndexSpec(name, keyPath || null, index.indexOf('&') !== -1, index.indexOf('*') !== -1, index.indexOf(\"++\") !== -1, isArray(keyPath), keyPath.indexOf('.') !== -1));\n });\n return rv;\n }\n\n function cmp(key1, key2) {\n return indexedDB.cmp(key1, key2);\n }\n\n function min(a, b) {\n return cmp(a, b) < 0 ? a : b;\n }\n\n function max(a, b) {\n return cmp(a, b) > 0 ? a : b;\n }\n\n function ascending(a, b) {\n return indexedDB.cmp(a, b);\n }\n\n function descending(a, b) {\n return indexedDB.cmp(b, a);\n }\n\n function simpleCompare(a, b) {\n return a < b ? -1 : a === b ? 0 : 1;\n }\n\n function simpleCompareReverse(a, b) {\n return a > b ? -1 : a === b ? 0 : 1;\n }\n\n function combine(filter1, filter2) {\n return filter1 ? filter2 ? function () {\n return filter1.apply(this, arguments) && filter2.apply(this, arguments);\n } : filter1 : filter2;\n }\n\n function readGlobalSchema() {\n db.verno = idbdb.version / 10;\n db._dbSchema = globalSchema = {};\n dbStoreNames = slice(idbdb.objectStoreNames, 0);\n if (dbStoreNames.length === 0) return; // Database contains no stores.\n var trans = idbdb.transaction(safariMultiStoreFix(dbStoreNames), 'readonly');\n dbStoreNames.forEach(function (storeName) {\n var store = trans.objectStore(storeName),\n keyPath = store.keyPath,\n dotted = keyPath && typeof keyPath === 'string' && keyPath.indexOf('.') !== -1;\n var primKey = new IndexSpec(keyPath, keyPath || \"\", false, false, !!store.autoIncrement, keyPath && typeof keyPath !== 'string', dotted);\n var indexes = [];\n for (var j = 0; j < store.indexNames.length; ++j) {\n var idbindex = store.index(store.indexNames[j]);\n keyPath = idbindex.keyPath;\n dotted = keyPath && typeof keyPath === 'string' && keyPath.indexOf('.') !== -1;\n var index = new IndexSpec(idbindex.name, keyPath, !!idbindex.unique, !!idbindex.multiEntry, false, keyPath && typeof keyPath !== 'string', dotted);\n indexes.push(index);\n }\n globalSchema[storeName] = new TableSchema(storeName, primKey, indexes, {});\n });\n setApiOnPlace([allTables], db._transPromiseFactory, keys(globalSchema), READWRITE, globalSchema);\n }\n\n function adjustToExistingIndexNames(schema, idbtrans) {\n /// \n /// Issue #30 Problem with existing db - adjust to existing index names when migrating from non-dexie db\n /// \n /// Map between name and TableSchema\n /// \n var storeNames = idbtrans.db.objectStoreNames;\n for (var i = 0; i < storeNames.length; ++i) {\n var storeName = storeNames[i];\n var store = idbtrans.objectStore(storeName);\n for (var j = 0; j < store.indexNames.length; ++j) {\n var indexName = store.indexNames[j];\n var keyPath = store.index(indexName).keyPath;\n var dexieName = typeof keyPath === 'string' ? keyPath : \"[\" + slice(keyPath).join('+') + \"]\";\n if (schema[storeName]) {\n var indexSpec = schema[storeName].idxByName[dexieName];\n if (indexSpec) indexSpec.name = indexName;\n }\n }\n }\n }\n\n function fireOnBlocked(ev) {\n db.on(\"blocked\").fire(ev);\n // Workaround (not fully*) for missing \"versionchange\" event in IE,Edge and Safari:\n connections.filter(function (c) {\n return c.name === db.name && c !== db && !c._vcFired;\n }).map(function (c) {\n return c.on(\"versionchange\").fire(ev);\n });\n }\n\n extend(this, {\n Collection: Collection,\n Table: Table,\n Transaction: Transaction,\n Version: Version,\n WhereClause: WhereClause,\n WriteableCollection: WriteableCollection,\n WriteableTable: WriteableTable\n });\n\n init();\n\n addons.forEach(function (fn) {\n fn(db);\n });\n}\n\nvar fakeAutoComplete = function () {}; // Will never be changed. We just fake for the IDE that we change it (see doFakeAutoComplete())\nvar fake = false; // Will never be changed. We just fake for the IDE that we change it (see doFakeAutoComplete())\n\nfunction trycatch(fn, reject) {\n var psd = Promise.PSD;\n return function () {\n var outerPSD = Promise.PSD; // Support Promise-specific data (PSD) in callback calls\n Promise.PSD = psd;\n try {\n fn.apply(this, arguments);\n } catch (e) {\n reject(e);\n } finally {\n Promise.PSD = outerPSD;\n }\n };\n}\n\nfunction parseType(type) {\n if (typeof type === 'function') {\n return new type();\n } else if (isArray(type)) {\n return [parseType(type[0])];\n } else if (type && typeof type === 'object') {\n var rv = {};\n applyStructure(rv, type);\n return rv;\n } else {\n return type;\n }\n}\n\nfunction applyStructure(obj, structure) {\n keys(structure).forEach(function (member) {\n var value = parseType(structure[member]);\n obj[member] = value;\n });\n return obj;\n}\n\nfunction eventRejectHandler(reject, sentance) {\n return function (event) {\n var errObj = event && event.target.error || new Error(\"\");\n if (sentance) {\n var occurredWhen = \" occurred when \" + sentance.map(function (word) {\n switch (typeof word) {\n case 'function':\n return word();\n case 'string':\n return word;\n default:\n return JSON.stringify(word);\n }\n }).join(\" \");\n if (errObj.message && errObj.message != errObj.name) occurredWhen += \". \" + errObj.message;\n if (errObj.name) {\n errObj = mapError(errObj, errObj.name + occurredWhen);\n } else {\n // Non-standard exceptions from IndexedDBPolyfill\n errObj = errObj + occurredWhen;\n }\n };\n reject(errObj);\n\n if (event) {\n // Old versions of IndexedDBShim doesnt provide an error event\n // Stop error from propagating to IDBTransaction. Let us handle that manually instead.\n if (event.stopPropagation) // IndexedDBShim doesnt support this\n event.stopPropagation();\n if (event.preventDefault) // IndexedDBShim doesnt support this\n event.preventDefault();\n }\n\n return false;\n };\n}\n\nfunction preventDefault(e) {\n e.preventDefault();\n}\n\nfunction globalDatabaseList(cb) {\n var val,\n localStorage = Dexie.dependencies.localStorage;\n if (!localStorage) return cb([]); // Envs without localStorage support\n try {\n val = JSON.parse(localStorage.getItem('Dexie.DatabaseNames') || \"[]\");\n } catch (e) {\n val = [];\n }\n if (cb(val)) {\n localStorage.setItem('Dexie.DatabaseNames', JSON.stringify(val));\n }\n}\n\nfunction awaitIterable(iterable) {\n var callNext = function (result) {\n return iterable.next(result);\n },\n doThrow = function (error) {\n return iterable.throw(error);\n },\n onSuccess = step(callNext),\n onError = step(doThrow);\n\n function step(getNext) {\n return function (val) {\n var next = getNext(val),\n value = next.value;\n\n return next.done ? value : !value || typeof value.then !== 'function' ? Array.isArray(value) ? awaitAll(value, 0) : onSuccess(value) : value.then(onSuccess, onError);\n };\n }\n\n function awaitAll(values, i) {\n if (i === values.length) return onSuccess(values);\n var value = values[i];\n return value.constructor && typeof value.constructor.all == 'function' ? value.constructor.all(values).then(onSuccess, onError) : awaitAll(values, i + 1);\n }\n\n return step(callNext)();\n}\n\n//\n// IndexSpec struct\n//\nfunction IndexSpec(name, keyPath, unique, multi, auto, compound, dotted) {\n /// \n /// \n /// \n /// \n /// \n /// \n /// \n this.name = name;\n this.keyPath = keyPath;\n this.unique = unique;\n this.multi = multi;\n this.auto = auto;\n this.compound = compound;\n this.dotted = dotted;\n var keyPathSrc = typeof keyPath === 'string' ? keyPath : keyPath && '[' + [].join.call(keyPath, '+') + ']';\n this.src = (unique ? '&' : '') + (multi ? '*' : '') + (auto ? \"++\" : \"\") + keyPathSrc;\n}\n\n//\n// TableSchema struct\n//\nfunction TableSchema(name, primKey, indexes, instanceTemplate) {\n /// \n /// \n /// \n /// \n this.name = name;\n this.primKey = primKey || new IndexSpec();\n this.indexes = indexes || [new IndexSpec()];\n this.instanceTemplate = instanceTemplate;\n this.mappedClass = null;\n this.idxByName = indexes.reduce(function (hashSet, index) {\n hashSet[index.name] = index;\n return hashSet;\n }, {});\n}\n\n//\n// Static delete() method.\n//\nDexie.delete = function (databaseName) {\n var db = new Dexie(databaseName),\n promise = db.delete();\n promise.onblocked = function (fn) {\n db.on(\"blocked\", fn);\n return this;\n };\n return promise;\n};\n\n//\n// Static exists() method.\n//\nDexie.exists = function (name) {\n return new Dexie(name).open().then(function (db) {\n db.close();\n return true;\n }).catch(Dexie.NoSuchDatabaseError, function () {\n return false;\n });\n};\n\n//\n// Static method for retrieving a list of all existing databases at current host.\n//\nDexie.getDatabaseNames = function (cb) {\n return new Promise(function (resolve, reject) {\n var getDatabaseNames = getNativeGetDatabaseNamesFn(indexedDB);\n if (getDatabaseNames) {\n // In case getDatabaseNames() becomes standard, let's prepare to support it:\n var req = getDatabaseNames();\n req.onsuccess = function (event) {\n resolve(slice(event.target.result, 0)); // Converst DOMStringList to Array\n };\n req.onerror = eventRejectHandler(reject);\n } else {\n globalDatabaseList(function (val) {\n resolve(val);\n return false;\n });\n }\n }).then(cb);\n};\n\nDexie.defineClass = function (structure) {\n /// \n /// Create a javascript constructor based on given template for which properties to expect in the class.\n /// Any property that is a constructor function will act as a type. So {name: String} will be equal to {name: new String()}.\n /// \n /// Helps IDE code completion by knowing the members that objects contain and not just the indexes. Also\n /// know what type each member has. Example: {name: String, emailAddresses: [String], properties: {shoeSize: Number}}\n\n // Default constructor able to copy given properties into this object.\n function Class(properties) {\n /// Properties to initialize object with.\n /// \n properties ? extend(this, properties) : fake && applyStructure(this, structure);\n }\n return Class;\n};\n\nDexie.applyStructure = applyStructure;\n\nDexie.ignoreTransaction = function (scopeFunc) {\n // In case caller is within a transaction but needs to create a separate transaction.\n // Example of usage:\n //\n // Let's say we have a logger function in our app. Other application-logic should be unaware of the\n // logger function and not need to include the 'logentries' table in all transaction it performs.\n // The logging should always be done in a separate transaction and not be dependant on the current\n // running transaction context. Then you could use Dexie.ignoreTransaction() to run code that starts a new transaction.\n //\n // Dexie.ignoreTransaction(function() {\n // db.logentries.add(newLogEntry);\n // });\n //\n // Unless using Dexie.ignoreTransaction(), the above example would try to reuse the current transaction\n // in current Promise-scope.\n //\n // An alternative to Dexie.ignoreTransaction() would be setImmediate() or setTimeout(). The reason we still provide an\n // API for this because\n // 1) The intention of writing the statement could be unclear if using setImmediate() or setTimeout().\n // 2) setTimeout() would wait unnescessary until firing. This is however not the case with setImmediate().\n // 3) setImmediate() is not supported in the ES standard.\n return Promise.newPSD(function () {\n Promise.PSD.trans = null;\n return scopeFunc();\n });\n};\n\nDexie.vip = function (fn) {\n // To be used by subscribers to the on('ready') event.\n // This will let caller through to access DB even when it is blocked while the db.ready() subscribers are firing.\n // This would have worked automatically if we were certain that the Provider was using Dexie.Promise for all asyncronic operations. The promise PSD\n // from the provider.connect() call would then be derived all the way to when provider would call localDatabase.applyChanges(). But since\n // the provider more likely is using non-promise async APIs or other thenable implementations, we cannot assume that.\n // Note that this method is only useful for on('ready') subscribers that is returning a Promise from the event. If not using vip()\n // the database could deadlock since it wont open until the returned Promise is resolved, and any non-VIPed operation started by\n // the caller will not resolve until database is opened.\n return Promise.newPSD(function () {\n Promise.PSD.letThrough = true; // Make sure we are let through if still blocking db due to onready is firing.\n return fn();\n });\n};\n\nDexie.async = function (generatorFn) {\n return function () {\n try {\n var rv = awaitIterable(generatorFn.apply(this, arguments));\n if (!rv || typeof rv.then !== 'function') return Dexie.Promise.resolve(rv);\n return rv;\n } catch (e) {\n return Dexie.Promise.reject(e);\n }\n };\n};\n\nDexie.spawn = function (generatorFn, args, thiz) {\n try {\n var rv = awaitIterable(generatorFn.apply(thiz, args || []));\n if (!rv || typeof rv.then !== 'function') return Dexie.Promise.resolve(rv);\n return rv;\n } catch (e) {\n return Dexie.Promise.reject(e);\n }\n};\n\n// Dexie.currentTransaction property. Only applicable for transactions entered using the new \"transact()\" method.\nObject.defineProperty(Dexie, \"currentTransaction\", {\n get: function () {\n /// \n return Promise.PSD && Promise.PSD.trans || null;\n }\n});\n\nfunction safariMultiStoreFix(storeNames) {\n return storeNames.length === 1 ? storeNames[0] : storeNames;\n}\n\n// Export our Promise implementation since it can be handy as a standalone Promise implementation\nDexie.Promise = Promise;\n// Export our derive/extend/override methodology\nDexie.derive = derive;\nDexie.extend = extend;\nDexie.override = override;\n// Export our Events() function - can be handy as a toolkit\nDexie.Events = Dexie.events = Events; // Backward compatible lowercase version.\n// Utilities\nDexie.getByKeyPath = getByKeyPath;\nDexie.setByKeyPath = setByKeyPath;\nDexie.delByKeyPath = delByKeyPath;\nDexie.shallowClone = shallowClone;\nDexie.deepClone = deepClone;\nDexie.addons = [];\nDexie.fakeAutoComplete = fakeAutoComplete;\nDexie.asap = asap;\nDexie.maxKey = maxKey;\nDexie.connections = connections;\n\n// Export Error classes\nextend(Dexie, fullNameExceptions); // Dexie.XXXError = class XXXError {...};\nDexie.MultiModifyError = Dexie.ModifyError; // Backward compatibility 0.9.8\nDexie.errnames = errnames;\n\n// Export other static classes\nDexie.IndexSpec = IndexSpec;\nDexie.TableSchema = TableSchema;\n\n//\n// Dependencies\n//\n// These will automatically work in browsers with indexedDB support, or where an indexedDB polyfill has been included.\n//\n// In node.js, however, these properties must be set \"manually\" before instansiating a new Dexie(). For node.js, you need to require indexeddb-js or similar and then set these deps.\n//\nvar idbshim = _global.idbModules && _global.idbModules.shimIndexedDB ? _global.idbModules : {};\nDexie.dependencies = {\n // Required:\n indexedDB: idbshim.shimIndexedDB || _global.indexedDB || _global.mozIndexedDB || _global.webkitIndexedDB || _global.msIndexedDB,\n IDBKeyRange: idbshim.IDBKeyRange || _global.IDBKeyRange || _global.webkitIDBKeyRange\n};\nminiTryCatch(function () {\n // Optional dependencies\n // localStorage\n Dexie.dependencies.localStorage = (typeof chrome !== \"undefined\" && chrome !== null ? chrome.storage : void 0) != null ? null : _global.localStorage;\n});\n\n// API Version Number: Type Number, make sure to always set a version number that can be comparable correctly. Example: 0.9, 0.91, 0.92, 1.0, 1.01, 1.1, 1.2, 1.21, etc.\nDexie.semVer = \"{version}\";\nDexie.version = Dexie.semVer.split('.').map(function (n) {\n return parseInt(n);\n}).reduce(function (p, c, i) {\n return p + c / Math.pow(10, i * 2);\n});\n\nfunction getNativeGetDatabaseNamesFn(indexedDB) {\n var fn = indexedDB && (indexedDB.getDatabaseNames || indexedDB.webkitGetDatabaseNames);\n return fn && fn.bind(indexedDB);\n}\n\n// Fool IDE to improve autocomplete. Tested with Visual Studio 2013 and 2015.\ndoFakeAutoComplete(function () {\n Dexie.fakeAutoComplete = fakeAutoComplete = doFakeAutoComplete;\n Dexie.fake = fake = true;\n});\n\n// https://github.com/dfahlander/Dexie.js/issues/186\n// typescript compiler tsc in mode ts-->es5 & commonJS, will expect require() to return\n// x.default. Workaround: Set Dexie.default = Dexie.\nDexie.default = Dexie;"],"names":["exceptions","asap"],"mappings":";;;;;;IAYO,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI;IACtB,IAAI,OAAO,GAAG,KAAK,CAAC,OAAO;IAC3B,IAAI,OAAO,GAAG,OAAO,IAAI,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,MAAM,KAAK,WAAW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AAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;KACrC,CAAC;;IAEF,SAAS,2BAA2B,CAAC,SAAS,EAAE;QAC5C,IAAI,EAAE,GAAG,SAAS,IAAI,CAAC,SAAS,CAAC,gBAAgB,IAAI,SAAS,CAAC,sBAAsB,CAAC;QACtF,OAAO,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;;;;IAInC,kBAAkB,CAAC,YAAY;QAC3B,KAAK,CAAC,gBAAgB,GAAG,gBAAgB,GAAG,kBAAkB;QAC9D,KAAK,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI;KAC3B,CAAC;;;;;IAKF,KAAK,CAAC,OAAO,GAAG,KAAK,;;,;;"} \ No newline at end of file diff --git a/dist/dexie.min.js b/dist/dexie.min.js new file mode 100644 index 000000000..574558de0 --- /dev/null +++ b/dist/dexie.min.js @@ -0,0 +1,3 @@ +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.Dexie=t()}(this,function(){"use strict";function n(n,t){return"object"!=typeof t&&(t=t()),en(t).forEach(function(e){n[e]=t[e]}),n}function t(t){return{from:function(e){return t.prototype=Object.create(e.prototype),t.prototype.constructor=t,{extend:function(r){n(t.prototype,"object"!=typeof r?r(e.prototype):r)}}}}}function e(n,t,e){return un.call(n,t,e)}function r(n,t){return t(n)}function o(n){var t=setTimeout(n,1e3);clearTimeout(t)}function i(n){if(!n)throw new exceptions.Internal("Assertion failed")}function u(n){on.setImmediate?setImmediate(n):setTimeout(n,0)}function c(n,t){try{n()}catch(e){t&&t(e)}}function a(n){try{throw n}catch(t){return K.reject(n)}}function s(n,t){if(n.hasOwnProperty(t))return n[t];if(!t)return n;if("string"!=typeof t){for(var e=[],r=0,o=t.length;o>r;++r){var i=s(n,t[r]);e.push(i)}return e}var u=t.indexOf(".");if(-1!==u){var c=n[t.substr(0,u)];return void 0===c?void 0:s(c,t.substr(u+1))}}function f(n,t,e){if(n&&void 0!==t&&!("isFrozen"in Object&&Object.isFrozen(n)))if("string"!=typeof t&&"length"in t){i("string"!=typeof e&&"length"in e);for(var r=0,o=t.length;o>r;++r)f(n,t[r],e[r])}else{var u=t.indexOf(".");if(-1!==u){var c=t.substr(0,u),a=t.substr(u+1);if(""===a)void 0===e?delete n[c]:n[c]=e;else{var s=n[c];s||(s=n[c]={}),f(s,a,e)}}else void 0===e?delete n[t]:n[t]=e}}function l(n,t){"string"==typeof t?f(n,t,void 0):"length"in t&&[].map.call(t,function(t){f(n,t,void 0)})}function h(n){var t={};for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e]);return t}function d(n){if(!n||"object"!=typeof n)return n;var t;if(rn(n)){t=[];for(var e=0,r=n.length;r>e;++e)t.push(d(n[e]))}else if(n instanceof Date)t=new Date,t.setTime(n.getTime());else{t=n.constructor?Object.create(n.constructor.prototype):{};for(var o in n)n.hasOwnProperty(o)&&(t[o]=d(n[o]))}return t}function p(n,t,e,r){e=e||{},r=r||"";for(var o in n)if(n.hasOwnProperty(o))if(t.hasOwnProperty(o)){var i=n[o],u=t[o];"object"==typeof i&&"object"==typeof u?p(i,u,e,r+o+"."):i!==u&&(e[r+o]=t[o])}else e[r+o]=void 0;for(var o in t)t.hasOwnProperty(o)&&!n.hasOwnProperty(o)&&(e[r+o]=t[o]);return e}function v(){}function y(n){return n}function m(n,t){return null==n||n===y?t:function(e){return t(n(e))}}function g(n,t){return function(){n.apply(this,arguments),t.apply(this,arguments)}}function b(n,t){return n===v?t:function(){var e=n.apply(this,arguments);void 0!==e&&(arguments[0]=e);var r=this.onsuccess,o=this.onerror;this.onsuccess=null,this.onerror=null;var i=t.apply(this,arguments);return r&&(this.onsuccess=this.onsuccess?g(r,this.onsuccess):r),o&&(this.onerror=this.onerror?g(o,this.onerror):o),void 0!==i?i:e}}function w(n,t){return n===v?t:function(){n.apply(this,arguments);var e=this.onsuccess,r=this.onerror;this.onsuccess=this.onerror=null,t.apply(this,arguments),e&&(this.onsuccess=this.onsuccess?g(e,this.onsuccess):e),r&&(this.onerror=this.onerror?g(r,this.onerror):r)}}function _(t,e){return t===v?e:function(){var r=t.apply(this,arguments);void 0!==r&&n(arguments[0],r);var o=this.onsuccess,i=this.onerror;this.onsuccess=null,this.onerror=null;var u=e.apply(this,arguments);return o&&(this.onsuccess=this.onsuccess?g(o,this.onsuccess):o),i&&(this.onerror=this.onerror?g(i,this.onerror):i),void 0===r?void 0===u?void 0:u:void 0===u?r:n(r,u)}}function x(n,t){return n===v?t:function(){return n.apply(this,arguments)===!1?!1:t.apply(this,arguments)}}function k(n,t){return n===v?t:function(){return t.apply(this,arguments)===!1?!1:n.apply(this,arguments)}}function P(n,t){return n===v?t:function(){var e=n.apply(this,arguments);if(e&&"function"==typeof e.then){var r=this,o=arguments;return e.then(function(){return t.apply(r,o)})}return t.apply(this,arguments)}}function D(n,t){this.name=n,this.message=t}function S(n,t){return n+". Errors: "+t.map(function(n){return n.toString()}).filter(function(n,t,e){return e.indexOf(n)===t}).join("\n")}function O(n,t,e,r){this.name="ModifyError",this.failures=t,this.failedKeys=r,this.successCount=e,this.message=S(n,t)}function E(n,t){this.name="BulkError",this.failures=t,this.message=S(n,t)}function I(n,t){var e=n;return n instanceof D||!n.name||!pn[n.name]||(e=new pn[n.name](t||n.message,n),n.stack&&(e.stack=n.stack)),e}function C(n){if(n.stack)return n;try{throw new Error}catch(t){n.stack=t.stack}return n}function j(n,t){function r(n,t,e){if(rn(n))return i(n);if("object"==typeof n)return o(n);t||(t=x),e||(e=v);var r={subscribers:[],fire:e,subscribe:function(n){r.subscribers.push(n),r.fire=t(r.fire,n)},unsubscribe:function(n){r.subscribers=r.subscribers.filter(function(t){return t!==n}),r.fire=r.subscribers.reduce(t,e)}};return a[n]=s[n]=r,r}function o(n){en(n).forEach(function(t){var e=n[t];if(rn(e))r(t,n[t][0],n[t][1]);else{if("asap"!==e)throw new dn.InvalidArgument("Invalid event config");var o=r(t,null,function(){var n=arguments;o.subscribers.forEach(function(t){u(function(){t.apply(on,n)})})});o.subscribe=function(n){-1===o.subscribers.indexOf(n)&&o.subscribers.push(n)},o.unsubscribe=function(n){var t=o.subscribers.indexOf(n);-1!==t&&o.subscribers.splice(t,1)}}})}function i(n){function t(){return e?!1:void(e=!0)}var e=!1;n.forEach(function(n){r(n).subscribe(t)})}var c=arguments,a={},s=function(t,r){if(r){var o=e(arguments,1),i=a[t];return i.subscribe.apply(i,o),n}return"string"==typeof t?a[t]:void 0};s.addEventType=r;for(var f=1,l=c.length;l>f;++f)r(c[f]);return s}function A(n,t){bn.push([n,e(arguments,1)])}function T(){var n=bn;bn=[];for(var t=0,e=n.length;e>t;++t){var r=n[t];r[0].apply(on,r[1])}}function K(n){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof n)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],this._catched=!1;var t=this,e=!0;this._PSD=K.PSD;try{V(this,n,function(n){e?mn(R,t,n):R(t,n)},function(n){return e?(mn(q,t,n),!1):q(t,n)})}finally{e=!1}}function F(n,t){if(null===n._state)return void n._deferreds.push(t);var e=n._state?t.onFulfilled:t.onRejected;if(null===e)return(n._state?t.resolve:t.reject)(n._value);var r,o=gn;gn=!1,mn=A;try{var i=K.PSD;K.PSD=n._PSD,r=e(n._value),n._state||r&&"function"==typeof r.then&&r._state===!1||N(n),t.resolve(r)}catch(u){t.reject(u)}finally{if(K.PSD=i,o){do{for(;bn.length>0;)T();var c=wn.pop();if(c)try{c()}catch(u){}}while(wn.length>0||bn.length>0);mn=yn,gn=!0}}}function B(n){var t=gn;gn=!1,mn=A;try{return n()}finally{if(t){do{for(;bn.length>0;)T();var e=wn.pop();if(e)try{e()}catch(r){}}while(wn.length>0||bn.length>0);mn=yn,gn=!0}}}function N(n){n._catched=!0,n._parent&&!n._parent._catched&&N(n._parent)}function R(n,t){var e=K.PSD;K.PSD=n._PSD;try{if(t===n)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then)return t instanceof K&&null!==t._state?(n._state=t._state,n._value=t._value,void M.call(n)):void V(n,function(n,e){t.then(n,e)},function(t){R(n,t)},function(t){q(n,t)});n._state=!0,n._value=t,M.call(n)}catch(r){q(r)}finally{K.PSD=e}}function q(n,t){var e=K.PSD;if(K.PSD=n._PSD,n._state=!1,n._value=t,M.call(n),!n._catched)try{n.onuncatched?n.onuncatched(n._value):K.on.error.fire(n._value)}catch(r){}return K.PSD=e,n._catched}function M(){for(var n=0,t=this._deferreds.length;t>n;n++)F(this,this._deferreds[n]);this._deferreds=[]}function U(n,t,e,r){this.onFulfilled="function"==typeof n?n:null,this.onRejected="function"==typeof t?t:null,this.resolve=e,this.reject=r}function V(n,t,e,r){var o=!1;try{t(function(n){o||(o=!0,e(n))},function(t){return o?n._catched:(o=!0,r(t))})}catch(i){if(o)return;return r(i)}}function W(n){console.error("Uncaught Promise: "+(n.stack||n))}function L(o,i){function l(){Xn.on("versionchange",function(n){n.newVersion>0?console.warn("Another connection wants to upgrade database '"+Xn.name+"'. Closing db now to resume the upgrade."):console.warn("Another connection wants to delete database '"+Xn.name+"'. Closing db now to resume the delete request."),Xn.close()}),Xn.on("blocked",function(n){!n.newVersion||n.newVersionn});f.forEach(function(n){var i=Mn,u=n._cfg.dbschema;An(i,t),An(u,t),Mn=Xn._dbSchema=u;var a=D(i,u);a.add.forEach(function(n){c.push(function(t,e){S(t,n[0],n[1].primKey,n[1].indexes),e()})}),a.change.forEach(function(n){if(n.recreate)throw new dn.Upgrade("Not yet support for changing primary key");c.push(function(t,e){var r=t.objectStore(n.name);n.add.forEach(function(n){F(r,n)}),n.change.forEach(function(n){r.deleteIndex(n.name),F(r,n)}),n.del.forEach(function(n){r.deleteIndex(n)}),e()})}),n._cfg.contentUpgrade&&c.push(function(t,i){s=!0;var c=Xn._createTransaction(Qn,e(t.db.objectStoreNames),u);c.idbtrans=t;var a=0;c._promise=r(c._promise,function(n){return function(t,e,r){function o(n){return function(){n.apply(this,arguments),0===--a&&i()}}return++a,n.call(this,t,function(n,t,r){arguments[0]=o(n),arguments[1]=o(t),e.apply(this,arguments)},r)}}),t.onerror=G(o,["running upgrader function for version",n._cfg.version]),c.on("error").subscribe(o),n._cfg.contentUpgrade(c),0===a&&i()}),s&&!On||c.push(function(n,t){T(u,n),t()})});var l=function(){try{c.length?c.shift()(t,l):A(Mn,t)}catch(n){i.onerror=t.onerror=function(n){n.preventDefault()};try{t.abort()}catch(e){}t.db.close(),o(n)}};l()}}function D(n,t){var e={del:[],add:[],change:[]};for(var r in n)t[r]||e.del.push(r);for(var r in t){var o=n[r],i=t[r];if(o){var u={name:r,def:t[r],recreate:!1,del:[],add:[],change:[]};if(o.primKey.src!==i.primKey.src)u.recreate=!0,e.change.push(u);else{var c=o.indexes.reduce(function(n,t){return n[t.name]=t,n},{}),a=i.indexes.reduce(function(n,t){return n[t.name]=t,n},{});for(var s in c)a[s]||u.del.push(s);for(var s in a){var f=c[s],l=a[s];f?f.src!==l.src&&u.change.push(l):u.add.push(l)}(u.recreate||u.del.length>0||u.add.length>0||u.change.length>0)&&e.change.push(u)}}else e.add.push([r,i])}return e}function S(n,t,e,r){var o=n.db.createObjectStore(t,e.keyPath?{keyPath:e.keyPath,autoIncrement:e.auto}:{autoIncrement:e.auto});return r.forEach(function(n){F(o,n)}),o}function A(n,t){en(n).forEach(function(e){t.db.objectStoreNames.contains(e)||S(t,e,n[e].primKey,n[e].indexes)})}function T(n,t){for(var e=0;eu;++u){var c=e[u];o.call(r,c[0],c[1],t);var h=n["delete"](c[0]);r.onerror&&(h._err=r.onerror),r.onsuccess&&(h._suc=r.onsuccess),h.onerror=f,u===s?h.onsuccess=V(i,!0):h.onsuccess=l,r.onsuccess=null,r.onerror=null}},function(n){throw r.onerror&&r.onerror(n),n})}();else for(var f=0;a>f;++f){var l=n["delete"](e[f]);l.onerror=function(n){return u(I(n.target.error))},f===s&&(l.onsuccess=function(){return i()})}})}function H(n,t,e,r){function o(n,t,e,r){return i._promise(n,e,r)}var i=this;this.db=Xn,this.mode=n,this.storeNames=t,this.idbtrans=null,this.on=j(this,["complete","error"],"abort"),this._reculock=0,this._blockedFuncs=[],this._psd=null,this.active=!0,this._dbschema=e,r&&(this.parent=r),this._tpf=o,this.tables=Object.create(Ln);for(var u=t.length-1;-1!==u;--u){var c=t[u],a=Xn._tableFactory(n,e[c],o);this.tables[c]=a,this[c]||(this[c]=a)}}function on(n,t,e){this._ctx={table:n,index:":id"===t?null:t,collClass:n._collClass,or:e}}function un(n,t){var e=null,r=null;if(t)try{e=t()}catch(o){r=C(I(o))}var i=n._ctx,u=i.table;this._ctx={table:u,index:i.index,isPrimKey:!i.index||u.schema.primKey.keyPath&&i.index===u.schema.primKey.name,range:e,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,isMatch:null,offset:0,limit:1/0,error:r,or:i.or,valueFilter:u.hook.reading.fire}}function cn(){un.apply(this,arguments)}function an(n,t){return n._cfg.version-t._cfg.version}function sn(n,t,e,r,o,i){e.forEach(function(e){var u=Xn._tableFactory(r,o[e],t);n.forEach(function(n){n[e]||(i?Object.defineProperty(n,e,{configurable:!0,enumerable:!0,get:function(){var n=K.PSD&&K.PSD.trans;return n&&n.db===Xn?n.tables[e]:u}}):n[e]=u)})})}function fn(n){n.forEach(function(n){for(var t in n)n[t]instanceof R&&delete n[t]})}function ln(n,t,e,r,o,i){i=i||y,n.onerror||(n.onerror=G(o)),t?n.onsuccess=z(function(u){var c=n.result;if(c){var a=function(){c["continue"]()};t(c,function(n){a=n},r,o)&&e(i(c.value),c,function(n){a=n}),a()}else r()},o):n.onsuccess=z(function(t){var o=n.result;if(o){var u=function(){o["continue"]()};e(i(o.value),o,function(n){u=n}),u()}else r()},o)}function hn(n){var t=[];return n.split(",").forEach(function(n){n=n.trim();var e=n.replace("&","").replace("++","").replace("*",""),r=0!==e.indexOf("[")?e:n.substring(n.indexOf("[")+1,n.indexOf("]")).split("+");t.push(new Z(e,r||null,-1!==n.indexOf("&"),-1!==n.indexOf("*"),-1!==n.indexOf("++"),rn(r),-1!==r.indexOf(".")))}),t}function pn(n,t){return Rn.cmp(n,t)}function vn(n,t){return pn(n,t)<0?n:t}function yn(n,t){return pn(n,t)>0?n:t}function mn(n,t){return Rn.cmp(n,t)}function gn(n,t){return Rn.cmp(t,n)}function bn(n,t){return t>n?-1:n===t?0:1}function wn(n,t){return n>t?-1:n===t?0:1}function Sn(n,t){return n?t?function(){return n.apply(this,arguments)&&t.apply(this,arguments)}:n:t}function jn(){if(Xn.verno=zn.version/10,Xn._dbSchema=Mn={},Vn=e(zn.objectStoreNames,0),0!==Vn.length){var n=zn.transaction(nn(Vn),"readonly");Vn.forEach(function(t){for(var e=n.objectStore(t),r=e.keyPath,o=r&&"string"==typeof r&&-1!==r.indexOf("."),i=new Z(r,r||"",!1,!1,!!e.autoIncrement,r&&"string"!=typeof r,o),u=[],c=0;c0&&($n=!1),!Rn)throw new dn.MissingAPI("indexedDB API not found. If using IE10+, make sure to run your code on a server URL (not locally). If using Safari, make sure to include indexedDB polyfill.");if(r=$n?Rn.open(o):Rn.open(o,Math.round(10*Xn.verno)),!r)throw new dn.MissingAPI("IndexedDB API not available");r.onerror=G(e,["opening database",o]),r.onblocked=Tn,r.onupgradeneeded=z(function(n){if($n&&!Xn._allowEmptyDB){r.onerror=function(n){n.preventDefault()},r.transaction.abort(),r.result.close();var t=Rn.deleteDatabase(o);t.onsuccess=t.onerror=function(){e(new dn.NoSuchDatabase("Database "+o+" doesnt exist"))}}else{0===n.oldVersion&&(i=!0),r.transaction.onerror=G(e);var u=n.oldVersion>Math.pow(2,62)?0:n.oldVersion;x(u/10,r.transaction,e,r)}},e),r.onsuccess=z(function(t){if(Gn=!1,zn=r.result,$n)jn();else if(zn.objectStoreNames.length>0)try{An(Mn,zn.transaction(nn(zn.objectStoreNames),Yn))}catch(t){}zn.onversionchange=function(n){Xn._vcFired=!0,Xn.on("versionchange").fire(n)},nt||Q(function(n){return-1===n.indexOf(o)?n.push(o):void 0}),K.newPSD(function(){function t(){Hn=!1,B(),n()}K.PSD.letThrough=!0;try{var r=Xn.on.ready.fire();r&&"function"==typeof r.then?r.then(t,function(n){zn.close(),zn=null,e(n)}):u(t)}catch(o){e(o)}})},e)}catch(c){e(c)}}).then(function(){return Dn.push(Xn),Xn}))},this.close=function(){var n=Dn.indexOf(Xn);n>=0&&Dn.splice(n,1),zn?(zn.close(),zn=null,Nn=!1,Hn&&B(),Hn=!1,Jn=new dn.DatabaseClosed):Gn&&Xn.on("ready",function(){return K.reject(new dn.DatabaseClosed)})},this["delete"]=function(){var n=arguments;return new K(function(t,e){function r(){Xn.close();var n=Rn.deleteDatabase(o);n.onsuccess=function(){nt||Q(function(n){var t=n.indexOf(o);return t>=0?n.splice(t,1):void 0}),t()},n.onerror=G(e,["deleting",o]),n.onblocked=Tn}if(n.length>0)throw new dn.InvalidArgument("Arguments not allowed in db.delete()");Gn?Zn.push({resume:r}):r()})},this.backendDB=function(){return zn},this.isOpen=function(){return null!==zn},this.hasFailed=function(){return null!==Jn},this.dynamicallyOpened=function(){return $n},this.name=o,Object.defineProperty(this,"tables",{get:function(){return en(Wn).map(function(n){return Wn[n]})}}),this.on=j(this,"error","populate",{blocked:[k,v],ready:[P,v],versionchange:[k,v]}),this.on.ready.subscribe=r(this.on.ready.subscribe,function(n){return function(t,e){function r(){return e||Xn.on.ready.unsubscribe(r),t.apply(this,arguments)}n.call(this,r),Xn.isOpen()&&(Hn?Zn.push({resume:r}):r())}}),In(function(){Xn.on("populate").fire(Xn._createTransaction(Qn,Vn,Mn)),Xn.on("error").fire(new Error)}),this.transaction=function(n,t,o){function i(t,e){var i=null,a=!0;try{if(f)throw f;i=Xn._createTransaction(n,l,Mn,c);var s=l.map(function(n){return i.tables[n]});s.push(i);var h,d=0;K.newPSD(function(){K.PSD.trans=i,i.scopeFunc=o,c&&(i.idbtrans=c.idbtrans,i._promise=r(i._promise,function(n){return function(t,e,r){function o(n){return function(t){var e;return K._rootExec(function(){e=n(t),K._tickFinalize(function(){0===--d&&i.active&&(i.active=!1,i.on.complete.fire())})}),e}}return++d,n.call(this,t,function(n,t,r){return e(o(n),o(t),r)},r)}})),i.complete(function(){t(h)}),i.error(function(n){function t(){var t=e(n);c||t||Xn.on.error.fire(n)}i.idbtrans&&(i.idbtrans.onerror=Y);try{i.abort()}catch(r){}c&&(c.active=!1,c.on.error.fire(n)),a?u(t):t()}),K._rootExec(function(){h=o.apply(i,s),h&&"function"==typeof h.next&&"function"==typeof h["throw"]&&(h=X(h))})}),(!i.idbtrans||c&&0===d)&&i._nop()}catch(p){i&&i.idbtrans&&(i.idbtrans.onerror=Y),i&&i.abort(),c&&c.on.error.fire(p),u(function(){e(p)||Xn.on("error").fire(p)})}a=!1}t=e(arguments,1,arguments.length-1),o=arguments[arguments.length-1];var c=K.PSD&&K.PSD.trans;c&&c.db===Xn&&-1===n.indexOf("!")||(c=null);var a=-1!==n.indexOf("?");n=n.replace("!","").replace("?","");var s=rn(t[0])?t.reduce(function(n,t){return n.concat(t)}):t,f=null,l=s.map(function(n){return"string"==typeof n?n:(n instanceof R||(f=f||new TypeError("Invalid type. Arguments following mode must be instances of Table or String")),n.name)});return"r"==n||n==Yn?n=Yn:"rw"==n||n==Qn?n=Qn:f=new dn.InvalidArgument("Invalid transaction mode: "+n),c&&(f||(c&&c.mode===Yn&&n===Qn&&(a?c=null:f=f||new dn.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY")),c&&l.forEach(function(n){c.tables.hasOwnProperty(n)||(a?c=null:f=f||new dn.SubTransaction("Table "+n+" not included in parent transaction. Parent Transaction function: "+c.scopeFunc.toString()))}))),c?c._promise(n,i,"lock"):Xn._whenReady(i)},this.table=function(n){if(Cn&&$n)return new q(n);if(!Wn.hasOwnProperty(n))throw new dn.InvalidTable("Table "+n+" does not exist");return Wn[n]},n(R.prototype,function(){function n(){throw new dn.ReadOnly("Current Transaction is READONLY")}return{_trans:function(n,t,e){return this._tpf(n,[this.name],t,e)},_idbstore:function(n,t,e){if(Cn)return new K(t);var r=this;return this._tpf(n,[this.name],function(n,e,o){t(n,e,o.idbtrans.objectStore(r.name),o)},e)},get:function(n,t){var e=this;return this._idbstore(Yn,function(t,r,o){Cn&&t(e.schema.instanceTemplate);var i=o.get(n);i.onerror=G(r,["getting",n,"from",e.name]),i.onsuccess=function(){t(e.hook.reading.fire(i.result))}}).then(t)},where:function(n){return new on(this,n)},count:function(n){return this.toCollection().count(n)},offset:function(n){return this.toCollection().offset(n)},limit:function(n){return this.toCollection().limit(n)},reverse:function(){return this.toCollection().reverse()},filter:function(n){return this.toCollection().and(n)},each:function(n){return this.toCollection().each(n)},toArray:function(n){return this.toCollection().toArray(n)},orderBy:function(n){return new this._collClass(new on(this,n))},toCollection:function(){return new this._collClass(new on(this))},mapToClass:function(n,t){this.schema.mappedClass=n;var e=Object.create(n.prototype);t&&J(e,t),this.schema.instanceTemplate=e;var r=function(t){if(!t)return t;var e=Object.create(n.prototype);for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e};return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=r,this.hook("reading",r),n},defineClass:function(n){return this.mapToClass(L.defineClass(n),n)},add:n,put:n,"delete":n,clear:n,update:n}}),t(q).from(R).extend(function(){return{bulkDelete:function(n){return this.hook.deleting.fire===v?this._idbstore(Qn,function(t,e,r,o){t(W(r,o,n,!1,v))}):this.where(":id").anyOf(n)["delete"]().then(function(){})},bulkPut:function(n,t){var e=this;return this._idbstore(Qn,function(r,o,i,u){if(!i.keyPath&&!e.schema.primKey.auto&&!t)throw new dn.InvalidArgument("bulkPut() with non-inbound keys requires keys array in second argument");if(i.keyPath&&t)throw new dn.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(t&&t.length!==n.length)throw new dn.InvalidArgument("Arguments objects and keys must have the same length");if(0===n.length)return r();var c,a,f=function(n){0===l.length?r(n):o(new E(e.name+".bulkPut(): "+l.length+" of "+h+" operations failed",l))},l=[],h=n.length,d=u.tables[e.name];if(e.hook.creating.fire===v&&e.hook.updating.fire===v){a=M(l);for(var p=0,y=n.length;y>p;++p)c=t?i.put(n[p],t[p]):i.put(n[p]),c.onerror=a;c.onerror=M(l,f),c.onsuccess=V(f)}else!function(){var e=t||i.keyPath&&n.map(function(n){return s(n,i.keyPath)}),u=e&&e.reduce(function(t,e,r){return null!=e&&(t[e]=n[r]),t},{}),c=e?d.where(":id").anyOf(Object.keys(u)).modify(function(){this.value=u[this.primKey],u[this.primKey]=null}).then(function(){var r=[],o=t&&[];return e.forEach(function(e,i){(null==e||u[e])&&(r.push(n[i]),t&&o.push(e))}),d.bulkAdd(r,o)}).then(function(n){var t=e[e.length-1];return null!=t?t:n}):d.bulkAdd(n);c.then(r)["catch"](O,function(n){o(new E(n.msg,n.failures))})["catch"](o)}()},"locked")},bulkAdd:function(n,t){var e=this,r=this.hook.creating.fire;return this._idbstore(Qn,function(o,i,u,a){function l(n){0===m.length?o(n):i(new E(e.name+".bulkAdd(): "+m.length+" of "+g+" operations failed",m))}if(!u.keyPath&&!e.schema.primKey.auto&&!t)throw new dn.InvalidArgument("bulkAdd() with non-inbound keys requires keys array in second argument");if(u.keyPath&&t)throw new dn.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(t&&t.length!==n.length)throw new dn.InvalidArgument("Arguments objects and keys must have the same length");if(0===n.length)return o();var h,p,y,m=[],g=n.length;if(r!==v){var b=u.keyPath,w={onerror:null,onsuccess:null};p=M(m,null),y=V(null,!0),c(function(){for(var e=0,o=n.length;o>e;++e){var i=t&&t[e],c=n[e],l=t?i:b?s(c,b):void 0,v=r.call(w,l,c,a);null==l&&null!=v&&(b?(c=d(c),f(c,b,v)):i=v),h=null!=i?u.add(c,i):u.add(c),w.onerror&&(h._err=w.onerror),w.onsuccess&&(h._suc=w.onsuccess),o-1>e&&(h.onerror=p,w.onsuccess&&(h.onsuccess=y),w.onerror=null,w.onsuccess=null)}},function(n){throw w.onerror&&w.onerror(n),n}),h.onerror=M(m,l),h.onsuccess=V(l,!0)}else{p=M(m);for(var _=0,x=n.length;x>_;++_)h=t?u.add(n[_],t[_]):u.add(n[_]),h.onerror=p;h.onerror=M(m,l),h.onsuccess=V(l)}})},add:function(n,t){var e=this,r=this.hook.creating.fire;return this._idbstore(Qn,function(o,i,u,c){var a={onsuccess:null,onerror:null};if(r!==v){var l=null!=t?t:u.keyPath?s(n,u.keyPath):void 0,h=r.call(a,l,n,c);null==l&&null!=h&&(u.keyPath?f(n,u.keyPath,h):t=h)}try{var d=null!=t?u.add(n,t):u.add(n),p=K.PSD;d.onerror=G(function(n){return a.onerror&&K.usePSD(p,a.onerror.bind(a,n)),i(n)},["adding",n,"into",e.name]),d.onsuccess=function(t){var e=u.keyPath;e&&f(n,e,t.target.result),a.onsuccess&&K.usePSD(p,a.onsuccess.bind(a,t.target.result)),o(d.result)}}catch(y){throw a.onerror&&a.onerror(y),y}})},put:function(n,t){var e=this,r=this.hook.creating.fire,o=this.hook.updating.fire;return r!==v||o!==v?this._trans(Qn,function(r,o,i){var u=void 0!==t?t:e.schema.primKey.keyPath&&s(n,e.schema.primKey.keyPath);null==u?i.tables[e.name].add(n).then(r,o):(i._lock(),n=d(n),i.tables[e.name].where(":id").equals(u).modify(function(t){this.value=n}).then(function(r){return 0===r?i.tables[e.name].add(n,t):u})["finally"](function(){i._unlock()}).then(r,o))}):this._idbstore(Qn,function(r,o,i){var u=void 0!==t?i.put(n,t):i.put(n);u.onerror=G(o,["putting",n,"into",e.name]),u.onsuccess=function(t){var e=i.keyPath;e&&f(n,e,t.target.result),r(u.result)}})},"delete":function(n){return this.hook.deleting.subscribers.length?this.where(":id").equals(n)["delete"]():this._idbstore(Qn,function(t,e,r){var o=r["delete"](n);o.onerror=G(e,["deleting",n,"from",r.name]),o.onsuccess=function(n){t(o.result)}})},clear:function(){return this.hook.deleting.subscribers.length?this.toCollection()["delete"]():this._idbstore(Qn,function(n,t,e){var r=e.clear();r.onerror=G(t,["clearing",e.name]),r.onsuccess=function(t){n(r.result)}})},update:function(n,t){if("object"!=typeof t||rn(t))throw new dn.InvalidArgument("db.update(keyOrObject, modifications). modifications must be an object.");if("object"!=typeof n||rn(n))return this.where(":id").equals(n).modify(t);en(t).forEach(function(e){f(n,e,t[e])});var e=s(n,this.schema.primKey.keyPath);return void 0===e&&K.reject(new dn.InvalidArgument("Given object does not contain its primary key")),this.where(":id").equals(e).modify(t)}}}),n(H.prototype,{_lock:function(){return++this._reculock,1===this._reculock&&K.PSD&&(K.PSD.lockOwnerFor=this),this},_unlock:function(){if(0===--this._reculock)for(K.PSD&&(K.PSD.lockOwnerFor=null);this._blockedFuncs.length>0&&!this._locked();){var n=this._blockedFuncs.shift();try{n()}catch(t){}}return this},_locked:function(){return this._reculock&&(!K.PSD||K.PSD.lockOwnerFor!==this)},_nop:function(n){this.tables[this.storeNames[0]].get(0).then(n)},_promise:function(n,t,e){var r=this;return K.newPSD(function(){var o;return r._locked()?o=new K(function(o,i){r._blockedFuncs.push(function(){r._promise(n,t,e).then(o,i)})}):(o=r.active?new K(function(o,i){if(!r.idbtrans&&n){if(!zn)throw!Jn||["DatabaseClosedError","MissingAPIError"].indexOf(Jn.name)>=0?Jn:new dn.OpenFailed(Jn);var c=r.idbtrans=zn.transaction(nn(r.storeNames),r.mode);c.onerror=function(n){r.on("error").fire(n&&n.target.error),n.preventDefault(),r.abort()},c.onabort=function(n){u(function(){r.on("error").fire(new dn.Abort("Transaction aborted for unknown reason"))}),r.active=!1,r.on("abort").fire(n)},c.oncomplete=function(n){r.active=!1,r.on("complete").fire(n)}}e&&r._lock();try{t(o,i,r)}catch(a){!function(){var n=C(I(a));L.ignoreTransaction(function(){r.on("error").fire(n)}),r.abort(),i(n)}()}}):K.reject(C(new dn.TransactionInactive("Transaction is inactive. Original Scope Function Source: "+r.scopeFunc.toString()))),r.active&&e&&o["finally"](function(){r._unlock()})),o.onuncatched=function(n){L.ignoreTransaction(function(){r.on("error").fire(n)}),r.abort(); +},o})},complete:function(n){return this.on("complete",n)},error:function(n){return this.on("error",n)},abort:function(){if(this.idbtrans&&this.active)try{this.active=!1,this.idbtrans.abort(),this.on.error.fire(new dn.Abort("Transaction Aborted"))}catch(n){}},table:function(n){if(!this.tables.hasOwnProperty(n))throw new dn.InvalidTable("Table "+n+" not in transaction");return this.tables[n]}}),n(on.prototype,function(){function n(n,t,e){var r=n instanceof on?new n._ctx.collClass(n):n;try{throw e?new e(t):new TypeError(t)}catch(o){r._ctx.error=o}return r}function t(n){return new n._ctx.collClass(n,function(){return qn.only("")}).limit(0)}function r(n){return e(1===n.length&&rn(n[0])?n[0]:n)}function o(n){return"next"===n?function(n){return n.toUpperCase()}:function(n){return n.toLowerCase()}}function i(n){return"next"===n?function(n){return n.toLowerCase()}:function(n){return n.toUpperCase()}}function u(n,t,e,r,o,i){for(var u=Math.min(n.length,r.length),c=-1,a=0;u>a;++a){var s=t[a];if(s!==r[a])return o(n[a],e[a])<0?n.substr(0,a)+e[a]+e.substr(a+1):o(n[a],r[a])<0?n.substr(0,a)+r[a]+e.substr(a+1):c>=0?n.substr(0,c)+t[c]+e.substr(c+1):null;o(n[a],s)<0&&(c=a)}return uc?null:n.substr(0,c)+r[c]+e.substr(c+1)}function c(n,t,e,r){function c(n){a=o(n),s=i(n),f="next"===n?bn:wn;var t=e.map(function(n){return{lower:s(n),upper:a(n)}}).sort(function(n,t){return f(n.lower,t.lower)});l=t.map(function(n){return n.upper}),h=t.map(function(n){return n.lower}),d=n,p="next"===n?"":r}var a,s,f,l,h,d,p,v=e.length;c("next");var y=new n._ctx.collClass(n,function(){return qn.bound(l[0],h[v-1]+r)});y._ondirectionchange=function(n){c(n)};var m=0;return y._addAlgorithm(function(n,e,r){var o=n.key;if("string"!=typeof o)return!1;var i=s(o);if(t(i,h,m))return!0;for(var c=null,a=m;v>a;++a){var y=u(o,i,l[a],h[a],f,d);null===y&&null===c?m=a+1:(null===c||f(c,y)>0)&&(c=y)}return e(null!==c?function(){n["continue"](c+p)}:r),!1}),y}return{between:function(e,r,o,i){o=o!==!1,i=i===!0;try{return pn(e,r)>0||0===pn(e,r)&&(o||i)&&(!o||!i)?t(this):new this._ctx.collClass(this,function(){return qn.bound(e,r,!o,!i)})}catch(u){return n(this,kn)}},equals:function(n){return new this._ctx.collClass(this,function(){return qn.only(n)})},above:function(n){return new this._ctx.collClass(this,function(){return qn.lowerBound(n,!0)})},aboveOrEqual:function(n){return new this._ctx.collClass(this,function(){return qn.lowerBound(n)})},below:function(n){return new this._ctx.collClass(this,function(){return qn.upperBound(n,!0)})},belowOrEqual:function(n){return new this._ctx.collClass(this,function(){return qn.upperBound(n)})},startsWith:function(t){return"string"!=typeof t?n(this,Pn):this.between(t,t+_n,!0,!0)},startsWithIgnoreCase:function(t){return"string"!=typeof t?n(this,Pn):""===t?this.startsWith(t):c(this,function(n,t){return 0===n.indexOf(t[0])},[t],_n)},equalsIgnoreCase:function(t){return"string"!=typeof t?n(this,Pn):c(this,function(n,t){return n===t[0]},[t],"")},anyOfIgnoreCase:function(e){var o=r(arguments);return 0===o.length?t(this):o.every(function(n){return"string"==typeof n})?c(this,function(n,t){return-1!==t.indexOf(n)},o,""):n(this,"anyOfIgnoreCase() only works with strings")},startsWithAnyOfIgnoreCase:function(e){var o=r(arguments);return 0===o.length?t(this):o.every(function(n){return"string"==typeof n})?c(this,function(n,t){return t.some(function(t){return 0===n.indexOf(t)})},o,_n):n(this,"startsWithAnyOfIgnoreCase() only works with strings")},anyOf:function(e){var o=r(arguments),i=mn;try{o.sort(i)}catch(u){return n(this,kn)}if(0===o.length)return t(this);var c=new this._ctx.collClass(this,function(){return qn.bound(o[0],o[o.length-1])});c._ondirectionchange=function(n){i="next"===n?mn:gn,o.sort(i)};var a=0;return c._addAlgorithm(function(n,t,e){for(var r=n.key;i(r,o[a])>0;)if(++a,a===o.length)return t(e),!1;return 0===i(r,o[a])?!0:(t(function(){n["continue"](o[a])}),!1)}),c},notEqual:function(n){return this.inAnyRange([[-(1/0),n],[n,xn]],{includeLowers:!1,includeUppers:!1})},noneOf:function(t){var e=r(arguments);if(0===e.length)return new this._ctx.collClass(this);try{e.sort(mn)}catch(o){return n(this,kn)}var i=e.reduce(function(n,t){return n?n.concat([[n[n.length-1][1],t]]):[[-(1/0),t]]},null);return i.push([e[e.length-1],xn]),this.inAnyRange(i,{includeLowers:!1,includeUppers:!1})},inAnyRange:function(e,r){function o(n,t){for(var e=0,r=n.length;r>e;++e){var o=n[e];if(pn(t[0],o[1])<0&&pn(t[1],o[0])>0){o[0]=vn(o[0],t[0]),o[1]=yn(o[1],t[1]);break}}return e===r&&n.push(t),n}function i(n,t){return l(n[0],t[0])}function u(n){return!p(n)&&!v(n)}var c=this._ctx;if(0===e.length)return t(this);if(!e.every(function(n){return void 0!==n[0]&&void 0!==n[1]&&mn(n[0],n[1])<=0}))return n(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",dn.InvalidArgument);var a,s=!r||r.includeLowers!==!1,f=r&&r.includeUppers===!0,l=mn;try{a=e.reduce(o,[]),a.sort(i)}catch(h){return n(this,kn)}var d=0,p=f?function(n){return mn(n,a[d][1])>0}:function(n){return mn(n,a[d][1])>=0},v=s?function(n){return gn(n,a[d][0])>0}:function(n){return gn(n,a[d][0])>=0},y=p,m=new c.collClass(this,function(){return qn.bound(a[0][0],a[a.length-1][1],!s,!f)});return m._ondirectionchange=function(n){"next"===n?(y=p,l=mn):(y=v,l=gn),a.sort(i)},m._addAlgorithm(function(n,t,e){for(var r=n.key;y(r);)if(++d,d===a.length)return t(e),!1;return u(r)?!0:0===pn(r,a[d][1])||0===pn(r,a[d][0])?!1:(t(function(){l===mn?n["continue"](a[d][0]):n["continue"](a[d][1])}),!1)}),m},startsWithAnyOf:function(e){var o=r(arguments);return o.every(function(n){return"string"==typeof n})?0===o.length?t(this):this.inAnyRange(o.map(function(n){return[n,n+_n]})):n(this,"startsWithAnyOf() only works with strings")}}}),n(un.prototype,function(){function t(n,t){n.filter=Sn(n.filter,t)}function e(n,t){var e=n.replayFilter;n.replayFilter=e?function(){return Sn(e(),t())}:t}function r(n,t){n.isMatch=Sn(n.isMatch,t)}function o(n,t){if(n.isPrimKey)return t;var e=n.table.schema.idxByName[n.index];if(!e)throw new dn.Schema("KeyPath "+n.index+" on object store "+t.name+" is not indexed");return t.index(e.name)}function i(n,t){var e=o(n,t);return n.keysOnly&&"openKeyCursor"in e?e.openKeyCursor(n.range||null,n.dir+n.unique):e.openCursor(n.range||null,n.dir+n.unique)}function u(n,t,e,r,o){var u=n.replayFilter?Sn(n.filter,n.replayFilter()):n.filter;n.or?!function(){function c(){2===++f&&e()}function a(n,e,o){if(!u||u(e,o,c,r)){var i=e.primaryKey.toString();s.hasOwnProperty(i)||(s[i]=!0,t(n,e,o))}}var s={},f=0;n.or._iterate(a,c,r,o),ln(i(n,o),n.algorithm,a,c,r,!n.keysOnly&&n.valueFilter)}():ln(i(n,o),Sn(n.algorithm,u),t,e,r,!n.keysOnly&&n.valueFilter)}function c(n){return n.table.schema.instanceTemplate}return{_read:function(n,t){var e=this._ctx;return e.error?e.table._trans(null,function(n,t){t(e.error)}):e.table._idbstore(Yn,n).then(t)},_write:function(n){var t=this._ctx;return t.error?t.table._trans(null,function(n,e){e(t.error)}):t.table._idbstore(Qn,n,"locked")},_addAlgorithm:function(n){var t=this._ctx;t.algorithm=Sn(t.algorithm,n)},_iterate:function(n,t,e,r){return u(this._ctx,n,t,e,r)},clone:function(t){var e=Object.create(this.constructor.prototype),r=Object.create(this._ctx);return t&&n(r,t),e._ctx=r,e},raw:function(){return this._ctx.valueFilter=null,this},each:function(n){var t=this._ctx;return Cn&&n(c(t)),this._read(function(e,r,o){u(t,n,e,r,o)})},count:function(n){if(Cn)return K.resolve(0).then(n);var t=this,e=this._ctx;if(e.filter||e.algorithm||e.or||e.replayFilter){var r=0;return this._read(function(n,t,o){u(e,function(){return++r,!1},function(){n(r)},t,o)},n)}return this._read(function(n,r,i){var u=o(e,i),c=e.range?u.count(e.range):u.count();c.onerror=G(r,["calling","count()","on",t.name]),c.onsuccess=function(t){n(t.target.result)}},n)},sortBy:function(n,t){function e(n,t){return t?e(n[o[t]],t-1):n[i]}function r(n,t){var r=e(n,u),o=e(t,u);return o>r?-c:r>o?c:0}var o=n.split(".").reverse(),i=o[0],u=o.length-1,c="next"===this._ctx.dir?1:-1;return this.toArray(function(n){return n.sort(r)}).then(t)},toArray:function(n){var t=this._ctx;return this._read(function(n,e,r){Cn&&n([c(t)]);var o=[];u(t,function(n){o.push(n)},function(){n(o)},e,r)},n)},offset:function(n){var t=this._ctx;return 0>=n?this:(t.offset+=n,t.or||t.algorithm||t.filter||t.replayFilter?e(t,function(){var t=n;return function(){return--t<0}}):e(t,function(){var t=n;return function(n,e,r){return 0===t?!0:1===t?(--t,!1):(e(function(){n.advance(t),t=0}),!1)}}),this)},limit:function(n){return this._ctx.limit=Math.min(this._ctx.limit,n),e(this._ctx,function(){var t=n;return function(n,e,r){return--t<=0&&e(r),t>=0}}),this},until:function(n,e){var r=this._ctx;return Cn&&n(c(r)),t(this._ctx,function(t,r,o){return n(t.value)?(r(o),e):!0}),this},first:function(n){return this.limit(1).toArray(function(n){return n[0]}).then(n)},last:function(n){return this.reverse().first(n)},and:function(n){return Cn&&n(c(this._ctx)),t(this._ctx,function(t){return n(t.value)}),r(this._ctx,n),this},or:function(n){return new on(this._ctx.table,n,this)},reverse:function(){return this._ctx.dir="prev"===this._ctx.dir?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},desc:function(){return this.reverse()},eachKey:function(n){var t=this._ctx;return Cn&&n(s(c(this._ctx),this._ctx.index?this._ctx.table.schema.idxByName[this._ctx.index].keyPath:this._ctx.table.schema.primKey.keyPath)),t.keysOnly=!0,this.each(function(t,e){n(e.key,e)})},eachUniqueKey:function(n){return this._ctx.unique="unique",this.eachKey(n)},keys:function(n){var t=this._ctx;t.keysOnly=!0;var e=[];return Cn?new K(this.eachKey.bind(this)).then(function(n){return[n]}).then(n):this.each(function(n,t){e.push(t.key)}).then(function(){return e}).then(n)},uniqueKeys:function(n){return this._ctx.unique="unique",this.keys(n)},firstKey:function(n){return this.limit(1).keys(function(n){return n[0]}).then(n)},lastKey:function(n){return this.reverse().firstKey(n)},distinct:function(){var n=this._ctx,e=n.index&&n.table.schema.idxByName[n.index];if(!e||!e.multi)return this;var r={};return t(this._ctx,function(n){var t=n.primaryKey.toString(),e=r.hasOwnProperty(t);return r[t]=!0,!e}),this}}}),t(cn).from(un).extend({modify:function(t){var e=this,r=this._ctx,o=r.table.hook,i=o.updating.fire,u=o.deleting.fire;return Cn&&"function"==typeof t&&t.call({value:r.table.schema.instanceTemplate},r.table.schema.instanceTemplate),this._write(function(o,a,l,y){function m(n,t,e){function o(n){return E.push(n),I.push(i.primKey),i.onerror&&K.newPSD(function(){K.PSD.trans=y,i.onerror(n)}),b(),!0}C=t.primaryKey;var i={primKey:t.primaryKey,value:n,onsuccess:null,onerror:null};if(w.call(i,n,i)!==!1){var u=!i.hasOwnProperty("value");++P,c(function(){var e=u?t["delete"]():t.update(i.value);e.onerror=G(o,u?["deleting",n,"from",r.table.name]:["modifying",n,"on",r.table.name]),e.onsuccess=function(n){i.onsuccess&&K.newPSD(function(){K.PSD.trans=y,i.onsuccess(i.value)}),++D,b()}},o)}else i.onsuccess&&i.onsuccess(i.value)}function g(n){return n&&(E.push(n),I.push(C)),a(new O("Error modifying one or more objects",E,D,I))}function b(){S&&D+E.length===P&&(E.length>0?g():o(D))}var w;if("function"==typeof t)w=i===v&&u===v?t:function(n){var e=d(n);if(t.call(this,n,this)===!1)return!1;if(this.hasOwnProperty("value")){var r=p(e,this.value),o=i.call(this,r,this.primKey,e,y);o&&(n=this.value,en(o).forEach(function(t){f(n,t,o[t])}))}else u.call(this,this.primKey,n,y)};else if(i===v){var _=en(t),x=_.length;w=function(n){for(var e=!1,r=0;x>r;++r){var o=_[r],i=t[o];s(n,o)!==i&&(f(n,o,i),e=!0)}return e}}else{var k=t;t=h(k),w=function(e){var r=!1,o=i.call(this,t,this.primKey,d(e),y);return o&&n(t,o),en(t).forEach(function(n){var o=t[n];s(e,n)!==o&&(f(e,n,o),r=!0)}),o&&(t=h(k)),r}}var P=0,D=0,S=!1,E=[],I=[],C=null;e.clone().raw()._iterate(m,function(){S=!0,b()},g,l)})},"delete":function(){var n=this,t=this._ctx,e=t.range,r=t.table.hook.deleting.fire,o=r!==v;if(!o&&!t.or&&!t.algorithm&&!t.filter&&!t.replayFilter&&(t.isPrimKey&&!En||!e))return this._write(function(n,r,o){var i=G(r,["deleting range from",t.table.name]),u=e?o.count(e):o.count();u.onerror=i,u.onsuccess=function(){var t=u.result;c(function(){var r=e?o["delete"](e):o.clear();r.onerror=i,r.onsuccess=function(){return n(t)}},function(n){return r(I(n))})}});var i=o?2e3:1e4;return this._write(function(e,u,c,a){var s=0,f=Object.create(t.table);f._tpf=a._tpf;var l=n.clone({table:f,keysOnly:!o}).distinct().limit(i).raw(),h=[],d=function(){return l.each(o?function(n,t){h.push([t.primaryKey,t.value])}:function(n,t){h.push(t.primaryKey)}).then(function(){return o?h.sort(function(n,t){return mn(n[0],t[0])}):h.sort(mn),W(c,a,h,o,r)}).then(function(){var n=h.length;return s+=n,h=[],i>n?s:d()})};e(d())})}}),n(this,{Collection:un,Table:R,Transaction:H,Version:g,WhereClause:on,WriteableCollection:cn,WriteableTable:q}),l(),Bn.forEach(function(n){n(Xn)})}function z(n,t){var e=K.PSD;return function(){var r=K.PSD;K.PSD=e;try{n.apply(this,arguments)}catch(o){t(o)}finally{K.PSD=r}}}function H(n){if("function"==typeof n)return new n;if(rn(n))return[H(n[0])];if(n&&"object"==typeof n){var t={};return J(t,n),t}return n}function J(n,t){return en(t).forEach(function(e){var r=H(t[e]);n[e]=r}),n}function G(n,t){return function(e){var r=e&&e.target.error||new Error("");if(t){var o=" occurred when "+t.map(function(n){switch(typeof n){case"function":return n();case"string":return n;default:return JSON.stringify(n)}}).join(" ");r.message&&r.message!=r.name&&(o+=". "+r.message),r.name?r=I(r,r.name+o):r+=o}return n(r),e&&(e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()),!1}}function Y(n){n.preventDefault()}function Q(n){var t,e=L.dependencies.localStorage;if(!e)return n([]);try{t=JSON.parse(e.getItem("Dexie.DatabaseNames")||"[]")}catch(r){t=[]}n(t)&&e.setItem("Dexie.DatabaseNames",JSON.stringify(t))}function X(n){function t(n){return function(t){var r=n(t),o=r.value;return r.done?o:o&&"function"==typeof o.then?o.then(i,u):Array.isArray(o)?e(o,0):i(o)}}function e(n,t){if(t===n.length)return i(n);var r=n[t];return r.constructor&&"function"==typeof r.constructor.all?r.constructor.all(n).then(i,u):e(n,t+1)}var r=function(t){return n.next(t)},o=function(t){return n["throw"](t)},i=t(r),u=t(o);return t(r)()}function Z(n,t,e,r,o,i,u){this.name=n,this.keyPath=t,this.unique=e,this.multi=r,this.auto=o,this.compound=i,this.dotted=u;var c="string"==typeof t?t:t&&"["+[].join.call(t,"+")+"]";this.src=(e?"&":"")+(r?"*":"")+(o?"++":"")+c}function $(n,t,e,r){this.name=n,this.primKey=t||new Z,this.indexes=e||[new Z],this.instanceTemplate=r,this.mappedClass=null,this.idxByName=e.reduce(function(n,t){return n[t.name]=t,n},{})}function nn(n){return 1===n.length?n[0]:n}function tn(n){var t=n&&(n.getDatabaseNames||n.webkitGetDatabaseNames);return t&&t.bind(n)}var en=Object.keys,rn=Array.isArray,on="undefined"!=typeof self?self:"undefined"!=typeof window?window:global,un=[].slice,cn=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed"],an=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],sn=cn.concat(an),fn={VersionChanged:"Database version changed by other database connection",DatabaseClosed:"Database has been closed"};t(D).from(Error),t(O).from(D),t(E).from(D);var ln=sn.reduce(function(n,t){return n[t]=t+"Error",n},{}),hn=D,dn=sn.reduce(function(n,e){function r(n,t){this.name=o,"string"==typeof n?(this.message=n,this.inner=t||null):"object"==typeof n?(this.message=n.name+" "+n.message,this.inner=n):(this.message=fn[e],this.inner=null)}var o=e+"Error";return t(r).from(hn),n[e]=r,n},{});dn.Syntax=SyntaxError,dn.Type=TypeError,dn.Range=RangeError;var pn=an.reduce(function(n,t){return n[t+"Error"]=dn[t],n},{}),vn=sn.reduce(function(n,t){return-1===["Syntax","Type","Range"].indexOf(t)&&(n[t+"Error"]=dn[t]),n},{});vn.ModifyError=O,vn.DexieError=D,vn.BulkError=E;var yn=on.setImmediate||function(n){var t=e(arguments,1);setTimeout(function(){n.apply(on,t)},0)};o(function(){yn=mn=A=function(n){var t=arguments;setTimeout(function(){n.apply(on,e(t,1))},0)}});var mn=yn,gn=!0,bn=[],wn=[];K.all=function(){var n=e(1===arguments.length&&rn(arguments[0])?arguments[0]:arguments);return new K(function(t,e){function r(i,u){try{if(u&&("object"==typeof u||"function"==typeof u)){var c=u.then;if("function"==typeof c)return void c.call(u,function(n){r(i,n)},e)}n[i]=u,0===--o&&t(n)}catch(a){e(a)}}if(0===n.length)return t([]);for(var o=n.length,i=0;i