diff --git a/services/common/kinto-offline-client.js b/services/common/kinto-offline-client.js index 39d16114aa9f..50fa2f05059b 100644 --- a/services/common/kinto-offline-client.js +++ b/services/common/kinto-offline-client.js @@ -33,7 +33,7 @@ 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 "foo" + * .catch(console.error.bind(console)); + * .then(console.log.bind(console)); // => "foo" * * @override * @param {Function} callback The operation description callback. @@ -1394,6 +1410,19 @@ class Collection { }, { 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. @@ -1679,6 +1708,8 @@ class Collection { 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). @@ -2116,6 +2147,23 @@ class CollectionTransaction { 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. @@ -2378,7 +2426,7 @@ function deepEqual(a, b) { 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; }