Bug 1861918 - Convert kinto-offline-client to an ES module. r=leplatrem,extension-reviewers,robwu

Differential Revision: https://phabricator.services.mozilla.com/D204431
This commit is contained in:
Mark Banner 2024-03-13 17:38:27 +00:00
parent 9f1de9d049
commit dd30d8567c
9 changed files with 14 additions and 52 deletions

View file

@ -209,10 +209,6 @@ remote/shared/messagehandler/test/browser/resources/modules/root/invalid.sys.mjs
# services/ exclusions # services/ exclusions
# Third party services
services/common/kinto-http-client.sys.mjs
services/common/kinto-offline-client.js
# Webpack-bundled library # Webpack-bundled library
services/fxaccounts/FxAccountsPairingChannel.sys.mjs services/fxaccounts/FxAccountsPairingChannel.sys.mjs

View file

@ -1399,7 +1399,7 @@ security/nss/
security/sandbox/chromium/ security/sandbox/chromium/
security/sandbox/chromium-shim/ security/sandbox/chromium-shim/
services/common/kinto-http-client.sys.mjs services/common/kinto-http-client.sys.mjs
services/common/kinto-offline-client.js services/common/kinto-offline-client.sys.mjs
testing/gtest/gmock/ testing/gtest/gmock/
testing/gtest/gtest/ testing/gtest/gtest/
testing/mochitest/MochiKit/ testing/mochitest/MochiKit/

View file

@ -12,36 +12,15 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
"use strict";
/* /*
* This file is generated from kinto.js - do not modify directly. * This file is generated from kinto.js - do not modify directly.
*/ */
// This is required because with Babel compiles ES2015 modules into a
// require() form that tries to keep its modules on "this", but
// doesn't specify "this", leaving it to default to the global
// object. However, in strict mode, "this" no longer defaults to the
// global object, so expose the global object explicitly. Babel's
// compiled output will use a variable called "global" if one is
// present.
//
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1394556#c3 for
// more details.
const global = this;
var EXPORTED_SYMBOLS = ["Kinto"];
/* /*
* Version 13.0.0 - 7fbf95d * Version 13.0.0 - 7fbf95d
*/ */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.Kinto = factory());
}(this, (function () { 'use strict';
/** /**
* Base db adapter. * Base db adapter.
* *
@ -2592,19 +2571,13 @@ class KintoBase {
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
const { setTimeout, clearTimeout } = ChromeUtils.importESModule("resource://gre/modules/Timer.sys.mjs"); const lazy = {};
const { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs"); ChromeUtils.defineESModuleGetters(lazy, {
XPCOMUtils.defineLazyGlobalGetters(global, ["fetch", "indexedDB"]);
ChromeUtils.defineESModuleGetters(global, {
EventEmitter: "resource://gre/modules/EventEmitter.sys.mjs", EventEmitter: "resource://gre/modules/EventEmitter.sys.mjs",
// Use standalone kinto-http module landed in FFx. // Use standalone kinto-http module landed in FFx.
KintoHttpClient: "resource://services-common/kinto-http-client.sys.mjs" KintoHttpClient: "resource://services-common/kinto-http-client.sys.mjs"
}); });
ChromeUtils.defineLazyGetter(global, "generateUUID", () => { export class Kinto extends KintoBase {
const { generateUUID } = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
return generateUUID;
});
class Kinto extends KintoBase {
static get adapters() { static get adapters() {
return { return {
BaseAdapter, BaseAdapter,
@ -2612,11 +2585,11 @@ class Kinto extends KintoBase {
}; };
} }
get ApiClass() { get ApiClass() {
return KintoHttpClient; return lazy.KintoHttpClient;
} }
constructor(options = {}) { constructor(options = {}) {
const events = {}; const events = {};
EventEmitter.decorate(events); lazy.EventEmitter.decorate(events);
const defaults = { const defaults = {
adapter: IDB, adapter: IDB,
events, events,
@ -2629,7 +2602,7 @@ class Kinto extends KintoBase {
return typeof id == "string" && RE_RECORD_ID.test(id); return typeof id == "string" && RE_RECORD_ID.test(id);
}, },
generate() { generate() {
return generateUUID() return Services.uuid.generateUUID()
.toString() .toString()
.replace(/[{}]/g, ""); .replace(/[{}]/g, "");
}, },
@ -2638,6 +2611,3 @@ class Kinto extends KintoBase {
} }
} }
return Kinto;
})));

View file

@ -13,9 +13,7 @@
*/ */
import { Sqlite } from "resource://gre/modules/Sqlite.sys.mjs"; import { Sqlite } from "resource://gre/modules/Sqlite.sys.mjs";
const { Kinto } = ChromeUtils.import( import { Kinto } from "resource://services-common/kinto-offline-client.sys.mjs";
"resource://services-common/kinto-offline-client.js"
);
/** /**
* Filter and sort list against provided filters and order. * Filter and sort list against provided filters and order.

View file

@ -20,7 +20,7 @@ EXTRA_COMPONENTS += [
EXTRA_JS_MODULES["services-common"] += [ EXTRA_JS_MODULES["services-common"] += [
"async.sys.mjs", "async.sys.mjs",
"kinto-http-client.sys.mjs", "kinto-http-client.sys.mjs",
"kinto-offline-client.js", "kinto-offline-client.sys.mjs",
"kinto-storage-adapter.sys.mjs", "kinto-storage-adapter.sys.mjs",
"logmanager.sys.mjs", "logmanager.sys.mjs",
"observers.sys.mjs", "observers.sys.mjs",

View file

@ -1,8 +1,8 @@
/* Any copyright is dedicated to the Public Domain. /* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */ http://creativecommons.org/publicdomain/zero/1.0/ */
const { Kinto } = ChromeUtils.import( const { Kinto } = ChromeUtils.importESModule(
"resource://services-common/kinto-offline-client.js" "resource://services-common/kinto-offline-client.sys.mjs"
); );
const { FirefoxAdapter } = ChromeUtils.importESModule( const { FirefoxAdapter } = ChromeUtils.importESModule(
"resource://services-common/kinto-storage-adapter.sys.mjs" "resource://services-common/kinto-storage-adapter.sys.mjs"

View file

@ -140,7 +140,7 @@ let gPendingTransactions = new Set();
/** /**
* Import the records into the Remote Settings Chrome IndexedDB. * Import the records into the Remote Settings Chrome IndexedDB.
* *
* Note: This duplicates some logics from `kinto-offline-client.js`. * Note: This duplicates some logics from `kinto-offline-client.sys.mjs`.
* *
* @param {String} bucket * @param {String} bucket
* @param {String} collection * @param {String} collection

View file

@ -42,6 +42,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
CryptoUtils: "resource://services-crypto/utils.sys.mjs", CryptoUtils: "resource://services-crypto/utils.sys.mjs",
ExtensionCommon: "resource://gre/modules/ExtensionCommon.sys.mjs", ExtensionCommon: "resource://gre/modules/ExtensionCommon.sys.mjs",
FirefoxAdapter: "resource://services-common/kinto-storage-adapter.sys.mjs", FirefoxAdapter: "resource://services-common/kinto-storage-adapter.sys.mjs",
Kinto: "resource://services-common/kinto-offline-client.sys.mjs",
KintoHttpClient: "resource://services-common/kinto-http-client.sys.mjs", KintoHttpClient: "resource://services-common/kinto-http-client.sys.mjs",
Observers: "resource://services-common/observers.sys.mjs", Observers: "resource://services-common/observers.sys.mjs",
Utils: "resource://services-sync/util.sys.mjs", Utils: "resource://services-sync/util.sys.mjs",
@ -54,9 +55,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
* @typedef {any} KeyBundle * @typedef {any} KeyBundle
* @typedef {any} SyncResultObject * @typedef {any} SyncResultObject
*/ */
XPCOMUtils.defineLazyModuleGetters(lazy, {
Kinto: "resource://services-common/kinto-offline-client.js",
});
ChromeUtils.defineLazyGetter(lazy, "fxAccounts", () => { ChromeUtils.defineLazyGetter(lazy, "fxAccounts", () => {
return ChromeUtils.importESModule( return ChromeUtils.importESModule(

View file

@ -156,7 +156,7 @@ security/nss/
security/sandbox/chromium/ security/sandbox/chromium/
security/sandbox/chromium-shim/ security/sandbox/chromium-shim/
services/common/kinto-http-client.sys.mjs services/common/kinto-http-client.sys.mjs
services/common/kinto-offline-client.js services/common/kinto-offline-client.sys.mjs
testing/gtest/gmock/ testing/gtest/gmock/
testing/gtest/gtest/ testing/gtest/gtest/
testing/mochitest/MochiKit/ testing/mochitest/MochiKit/