Bug 1577218 - Upgrade kinto-offline-client to 12.7.0 r=glasserc
authorMathieu Leplatre <mathieu@mozilla.com>
Wed, 28 Aug 2019 16:08:29 +0000
changeset 551103 2f2200fc375781f23a1e2e15d82aa09bebbba348
parent 551102 67f3cd7e58ca8aadcddaf11b00a6aeedf4113727
child 551104 720ff3a404a7e289cd0437b012aeea6bfbee6c5c
push id11865
push userbtara@mozilla.com
push dateMon, 02 Sep 2019 08:54:37 +0000
treeherdermozilla-beta@37f59c4671b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglasserc
bugs1577218
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1577218 - Upgrade kinto-offline-client to 12.7.0 r=glasserc Differential Revision: https://phabricator.services.mozilla.com/D43773
services/common/kinto-offline-client.js
--- 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 12.6.0 - f14a3e6
+ * Version 12.7.0 - c2b1b94
  */
 
 (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 r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({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
@@ -86,23 +86,26 @@ XPCOMUtils.defineLazyGetter(global, "gen
 class Kinto extends _KintoBase.default {
   static get adapters() {
     return {
       BaseAdapter: _base.default,
       IDB: _IDB.default
     };
   }
 
+  get ApiClass() {
+    return KintoHttpClient;
+  }
+
   constructor(options = {}) {
     const events = {};
     EventEmitter.decorate(events);
     const defaults = {
       adapter: _IDB.default,
-      events,
-      ApiClass: KintoHttpClient
+      events
     };
     super({ ...defaults,
       ...options
     });
   }
 
   collection(collName, options = {}) {
     const idSchema = {
@@ -207,44 +210,51 @@ class KintoBase {
     this._options = { ...defaults,
       ...options
     };
 
     if (!this._options.adapter) {
       throw new Error("No adapter provided");
     }
 
+    this._api = null;
+    /**
+     * The event emitter instance.
+     * @type {EventEmitter}
+     */
+
+    this.events = this._options.events;
+  }
+  /**
+   * The kinto HTTP client instance.
+   * @type {KintoClient}
+   */
+
+
+  get api() {
     const {
-      ApiClass,
       events,
       headers,
       remote,
       requestMode,
       retry,
       timeout
-    } = this._options; // public properties
-
-    /**
-     * The kinto HTTP client instance.
-     * @type {KintoClient}
-     */
-
-    this.api = new ApiClass(remote, {
-      events,
-      headers,
-      requestMode,
-      retry,
-      timeout
-    });
-    /**
-     * The event emitter instance.
-     * @type {EventEmitter}
-     */
-
-    this.events = this._options.events;
+    } = this._options;
+
+    if (!this._api) {
+      this._api = new this.ApiClass(remote, {
+        events,
+        headers,
+        requestMode,
+        retry,
+        timeout
+      });
+    }
+
+    return this._api;
   }
   /**
    * Creates a {@link Collection} instance. The second (optional) parameter
    * will set collection-level options like e.g. `remoteTransformers`.
    *
    * @param  {String} collName The collection name.
    * @param  {Object} [options={}]                 Extra options or override client's options.
    * @param  {Object} [options.idSchema]           IdSchema instance (default: UUID)
@@ -269,17 +279,17 @@ class KintoBase {
       ...options
     };
     const {
       idSchema,
       remoteTransformers,
       hooks,
       localFields
     } = options;
-    return new _collection.default(bucket, collName, this.api, {
+    return new _collection.default(bucket, collName, this, {
       events,
       adapter,
       adapterOptions,
       idSchema,
       remoteTransformers,
       hooks,
       localFields
     });
@@ -321,17 +331,26 @@ async function open(dbname, {
   onupgradeneeded
 }) {
   return new Promise((resolve, reject) => {
     const request = indexedDB.open(dbname, version);
 
     request.onupgradeneeded = event => {
       const db = event.target.result;
 
-      db.onerror = event => reject(event.target.error);
+      db.onerror = event => reject(event.target.error); // When an upgrade is needed, a transaction is started.
+
+
+      const transaction = event.target.transaction;
+
+      transaction.onabort = event => {
+        const error = event.target.error || transaction.error || new DOMException("The operation has been aborted", "AbortError");
+        reject(error);
+      }; // Callback for store creation etc.
+
 
       return onupgradeneeded(event);
     };
 
     request.onerror = event => {
       reject(event.target.error);
     };
 
@@ -377,16 +396,21 @@ async function execute(db, name, callbac
       result = callback(store, abort);
     } catch (e) {
       abort(e);
     }
 
     transaction.onerror = event => reject(event.target.error);
 
     transaction.oncomplete = event => resolve(result);
+
+    transaction.onabort = event => {
+      const error = event.target.error || transaction.error || new DOMException("The operation has been aborted", "AbortError");
+      reject(error);
+    };
   });
 }
 /**
  * Helper to wrap the deletion of an IndexedDB database into a promise.
  *
  * @param dbName {String} the database to delete
  * @return {Promise}
  */
@@ -1588,22 +1612,22 @@ function importChange(transaction, remot
 
 class Collection {
   /**
    * Constructor.
    *
    * Options:
    * - `{BaseAdapter} adapter` The DB adapter (default: `IDB`)
    *
-   * @param  {String} bucket  The bucket identifier.
-   * @param  {String} name    The collection name.
-   * @param  {Api}    api     The Api instance.
-   * @param  {Object} options The options object.
+   * @param  {String}    bucket  The bucket identifier.
+   * @param  {String}    name    The collection name.
+   * @param  {KintoBase} kinto   The Kinto instance.
+   * @param  {Object}    options The options object.
    */
-  constructor(bucket, name, api, options = {}) {
+  constructor(bucket, name, kinto, options = {}) {
     this._bucket = bucket;
     this._name = name;
     this._lastModified = null;
     const DBAdapter = options.adapter || _IDB.default;
 
     if (!DBAdapter) {
       throw new Error("No adapter provided");
     }
@@ -1617,21 +1641,21 @@ class Collection {
     /**
      * The db adapter instance
      * @type {BaseAdapter}
      */
 
 
     this.db = db;
     /**
-     * The Api instance.
-     * @type {KintoClient}
+     * The KintoBase instance.
+     * @type {KintoBase}
      */
 
-    this.api = api;
+    this.kinto = kinto;
     /**
      * The event emitter instance.
      * @type {EventEmitter}
      */
 
     this.events = options.events;
     /**
      * The IdSchema instance.
@@ -1654,16 +1678,25 @@ class Collection {
     /**
      * The list of fields names that will remain local.
      * @type {Array}
      */
 
     this.localFields = options.localFields || [];
   }
   /**
+   * The HTTP client.
+   * @type {KintoClient}
+   */
+
+
+  get api() {
+    return this.kinto.api;
+  }
+  /**
    * The collection name.
    * @type {String}
    */
 
 
   get name() {
     return this._name;
   }