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..fffec14d6
--- /dev/null
+++ b/addons/Dexie.Observable/dist/dexie-observable.js
@@ -0,0 +1,827 @@
+(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).catch('DatabaseClosedError', function (e) {
+ // Handle database closed error gracefully while reading changes.
+ // Don't bubble to db.on.error or Promise.on.error.
+ // Even though we intercept the close() method, it might be called when in the middle of
+ // reading changes and then that flow will cancel with DatabaseClosedError.
+ });
+ });
+ }
+ }
+
+ 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).catch('DatabaseClosedError', function (e) {
+ // Handle database closed error gracefully while reading changes.
+ // Don't bubble to db.on.error or Promise.on.error.
+ // Even though we intercept the close() method, it might be called when in the middle of
+ // reading changes and then that flow will cancel with DatabaseClosedError.
+ }).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..c85809b8c
--- /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).catch('DatabaseClosedError', function (e) {\n // Handle database closed error gracefully while reading changes.\n // Don't bubble to db.on.error or Promise.on.error.\n // Even though we intercept the close() method, it might be called when in the middle of\n // reading changes and then that flow will cancel with DatabaseClosedError.\n });\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).catch('DatabaseClosedError', function (e) {\n // Handle database closed error gracefully while reading changes.\n // Don't bubble to db.on.error or Promise.on.error.\n // Even though we intercept the close() method, it might be called when in the middle of\n // reading changes and then that flow will cancel with DatabaseClosedError.\n }).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,W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,CAAC,gBAAgB,CAAC,SAAS,EAAE,UAAU,CAAC,UAAU,CAAC;QACzD,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,UAAU,CAAC,eAAe,CAAC;;;IAGvE,KAAK,CAAC,UAAU,GAAG,UAAU;IAC7B,KAAK,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..ef2a084ec
--- /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)["catch"]("DatabaseClosedError",function(e){})})}}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)["catch"]("DatabaseClosedError",function(e){})["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..2c790148e
--- /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","e","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,GAAg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eAAgBhQ,EAAW8P,kBAGvDxP,EAAMN,WAAaA,EACnBM,EAAM2P,OAAOrD,KAAK5M","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..ba600df18
--- /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..08a2d71dc
--- /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,C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/addons/Dexie.Syncable/dist/dexie-syncable.min.js b/addons/Dexie.Syncable/dist/dexie-syncable.min.js
new file mode 100644
index 000000000..f3e5c84ef
--- /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..303c33a8d
--- /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,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BAAkB,SAAUzO,GACpC,MAAOJ,GAAGY,WAAWE,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/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..dd347a434
--- /dev/null
+++ b/dist/dexie.d.ts
@@ -0,0 +1,454 @@
+// Type definitions for Dexie v1.4.0
+// 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,
+ indexedDB?: IDBFactory,
+ IDBKeyRange?: IDBKeyRange
+ });
+
+ 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: {key: IndexableType, primaryKey: Key}) => 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: {key: IndexableType, primaryKey: Key}) => any): Promise;
+ eachKey(callback: (key: IndexableType, cursor: {key: IndexableType, primaryKey: Key}) => any): Promise;
+ eachPrimaryKey(callback: (key: Key, cursor: {key: IndexableType, primaryKey: Key}) => any): Promise;
+ eachUniqueKey(callback: (key: IndexableType, cursor: {key: IndexableType, primaryKey: Key}) => any): Promise;
+ filter(filter: (x: T) => boolean): Collection;
+ first(): Promise;
+ first(onFulfilled: (value: T) => Thenable): Promise;
+ first(onFulfilled: (value: T) => U): Promise;
+ keys(): Promise;
+ keys(onFulfilled: (value: IndexableType[]) => Thenable): Promise;
+ keys(onFulfilled: (value: IndexableType[]) => U): Promise;
+ primaryKeys(): Promise;
+ primaryKeys(onFulfilled: (value: Key[]) => Thenable): Promise;
+ primaryKeys(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: IndexableType[]) => Thenable): Promise;
+ uniqueKeys(onFulfilled: (value: IndexableType[]) => U): Promise