--- a/services/common/kinto-offline-client.js
+++ b/services/common/kinto-offline-client.js
@@ -28,17 +28,17 @@
//
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1394556#c3 for
// more details.
const global = this;
var EXPORTED_SYMBOLS = ["Kinto"];
/*
- * Version 11.0.0 - 1dbc5fb
+ * Version 11.1.0 - 91f9229
*/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Kinto = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
/*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -57,34 +57,50 @@ var EXPORTED_SYMBOLS = ["Kinto"];
Object.defineProperty(exports, "__esModule", {
value: true
});
var _KintoBase = require("../src/KintoBase");
var _KintoBase2 = _interopRequireDefault(_KintoBase);
+var _base = require("../src/adapters/base");
+
+var _base2 = _interopRequireDefault(_base);
+
+var _IDB = require("../src/adapters/IDB");
+
+var _IDB2 = _interopRequireDefault(_IDB);
+
var _utils = require("../src/utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
ChromeUtils.import("resource://gre/modules/Timer.jsm");
-Cu.importGlobalProperties(["fetch"]);
+Cu.importGlobalProperties(["fetch", "indexedDB"]);
const { EventEmitter } = ChromeUtils.import("resource://gre/modules/EventEmitter.jsm", {});
const { generateUUID } = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
// Use standalone kinto-http module landed in FFx.
const { KintoHttpClient } = ChromeUtils.import("resource://services-common/kinto-http-client.js");
class Kinto extends _KintoBase2.default {
+ static get adapters() {
+ return {
+ BaseAdapter: _base2.default,
+ IDB: _IDB2.default
+ };
+ }
+
constructor(options = {}) {
const events = {};
EventEmitter.decorate(events);
const defaults = {
+ adapter: _IDB2.default,
events,
ApiClass: KintoHttpClient
};
super({ ...defaults, ...options });
}
collection(collName, options = {}) {
const idSchema = {
@@ -99,17 +115,17 @@ class Kinto extends _KintoBase2.default
exports.default = Kinto; // This fixes compatibility with CommonJS required by browserify.
// See http://stackoverflow.com/questions/33505992/babel-6-changes-how-it-exports-default/33683495#33683495
if (typeof module === "object") {
module.exports = Kinto;
}
-},{"../src/KintoBase":3,"../src/utils":7}],2:[function(require,module,exports){
+},{"../src/KintoBase":3,"../src/adapters/IDB":4,"../src/adapters/base":5,"../src/utils":7}],2:[function(require,module,exports){
},{}],3:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
@@ -509,18 +525,18 @@ class IDB extends _base2.default {
* @example
* const db = new IDB("example");
* db.execute(transaction => {
* transaction.create({id: 1, title: "foo"});
* transaction.update({id: 2, title: "bar"});
* transaction.delete(3);
* return "foo";
* })
- * .catch(console.error);
- * .then(console.log); // => "foo"
+ * .catch(console.error.bind(console));
+ * .then(console.log.bind(console)); // => "foo"
*
* @override
* @param {Function} callback The operation description callback.
* @param {Object} options The options object.
* @return {Promise}
*/
async execute(callback, options = { preload: [] }) {
// Transactions in IndexedDB are autocommited when a callback does not
@@ -1390,16 +1406,29 @@ class Collection {
*/
delete(id, options = { virtual: true }) {
return this.execute(transaction => {
return transaction.delete(id, options);
}, { preloadIds: [id] });
}
/**
+ * Same as {@link Collection#deleteAll}, but wrapped in its own transaction, execulding the parameter.
+ *
+ * @return {Promise}
+ */
+ async deleteAll() {
+ const { data } = await this.list({}, { includeDeleted: false });
+ const recordIds = data.map(record => record.id);
+ return this.execute(transaction => {
+ return transaction.deleteAll(recordIds);
+ }, { preloadIds: recordIds });
+ }
+
+ /**
* The same as {@link CollectionTransaction#deleteAny}, but wrapped
* in its own transaction.
*
* @param {String} id The record's Id.
* @return {Promise}
*/
deleteAny(id) {
return this.execute(txn => txn.deleteAny(id), { preloadIds: [id] });
@@ -1674,16 +1703,18 @@ class Collection {
filters = { exclude_id };
}
// First fetch remote changes from the server
const { data, last_modified } = await client.listRecords({
// Since should be ETag (see https://github.com/Kinto/kinto.js/issues/356)
since: options.lastModified ? `${options.lastModified}` : undefined,
headers: options.headers,
retry: options.retry,
+ // Fetch every page by default (FIXME: option to limit pages, see #277)
+ pages: Infinity,
filters
});
// last_modified is the ETag header value (string).
// For retro-compatibility with first kinto.js versions
// parse it to integer.
const unquoted = last_modified ? parseInt(last_modified, 10) : undefined;
// Check if server was flushed.
@@ -2112,16 +2143,33 @@ class CollectionTransaction {
// Delete for real.
this.adapterTransaction.delete(id);
}
this._queueEvent("delete", { data: existing });
return { data: existing, permissions: {} };
}
/**
+ * Soft delete all records from the local database.
+ *
+ * @param {Array} ids Array of non-deleted Record Ids.
+ * @return {Object}
+ */
+ deleteAll(ids) {
+ const existingRecords = [];
+ ids.forEach(id => {
+ existingRecords.push(this.adapterTransaction.get(id));
+ this.delete(id);
+ });
+
+ this._queueEvent("deleteAll", { data: existingRecords });
+ return { data: existingRecords, permissions: {} };
+ }
+
+ /**
* Deletes a record from the local database, if any exists.
* Otherwise, do nothing.
*
* @param {String} id The record's Id.
* @return {Object}
*/
deleteAny(id) {
const existing = this.adapterTransaction.get(id);
@@ -2373,17 +2421,17 @@ function deepEqual(a, b) {
return false;
}
if (!(a && typeof a == "object") || !(b && typeof b == "object")) {
return false;
}
if (Object.keys(a).length !== Object.keys(b).length) {
return false;
}
- for (let k in a) {
+ for (const k in a) {
if (!deepEqual(a[k], b[k])) {
return false;
}
}
return true;
}
/**