зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1471901 - Allow synchronization of custom record IDs in RemoteSettings r=florian
MozReview-Commit-ID: 5LjcZ7Xjjxi --HG-- extra : rebase_source : 5e51abfaba7908c977d2f82e6e5b94ebf21d758c
This commit is contained in:
Родитель
b7c5c14e27
Коммит
16b4b5172c
|
@ -33,7 +33,7 @@ const global = this;
|
|||
var EXPORTED_SYMBOLS = ["Kinto"];
|
||||
|
||||
/*
|
||||
* Version 11.1.2 - 2476e07
|
||||
* Version 11.2.1 - 26601c8
|
||||
*/
|
||||
|
||||
(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){
|
||||
|
@ -394,9 +394,11 @@ class IDB extends _base2.default {
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param {String} dbname The database name.
|
||||
* @param {String} store The store name.
|
||||
* @param {Object} options Adapter options.
|
||||
* @param {String} options.dbname The IndexedDB name (default: same as store).
|
||||
*/
|
||||
constructor(dbname) {
|
||||
constructor(storeName, options = {}) {
|
||||
super();
|
||||
this._db = null;
|
||||
// public properties
|
||||
|
@ -404,6 +406,8 @@ class IDB extends _base2.default {
|
|||
* The database name.
|
||||
* @type {String}
|
||||
*/
|
||||
this.storeName = storeName;
|
||||
const { dbname = storeName } = options;
|
||||
this.dbname = dbname;
|
||||
}
|
||||
|
||||
|
@ -429,7 +433,7 @@ class IDB extends _base2.default {
|
|||
// DB object
|
||||
const db = event.target.result;
|
||||
// Main collection store
|
||||
const collStore = db.createObjectStore(this.dbname, {
|
||||
const collStore = db.createObjectStore(this.storeName, {
|
||||
keyPath: "id"
|
||||
});
|
||||
// Primary key (generated by IdSchema, UUID by default)
|
||||
|
@ -480,7 +484,7 @@ class IDB extends _base2.default {
|
|||
* @return {Object}
|
||||
*/
|
||||
prepare(mode = undefined, name = null) {
|
||||
const storeName = name || this.dbname;
|
||||
const storeName = name || this.storeName;
|
||||
// On Safari, calling IDBDatabase.transaction with mode == undefined raises
|
||||
// a TypeError.
|
||||
const transaction = mode ? this._db.transaction([storeName], mode) : this._db.transaction([storeName]);
|
||||
|
@ -652,7 +656,7 @@ class IDB extends _base2.default {
|
|||
await this.open();
|
||||
return new Promise((resolve, reject) => {
|
||||
const { transaction, store } = this.prepare("readwrite", "__meta__");
|
||||
store.put({ name: "lastModified", value: value });
|
||||
store.put({ name: `${this.storeName}-lastModified`, value: value });
|
||||
transaction.onerror = event => reject(event.target.error);
|
||||
transaction.oncomplete = event => resolve(value);
|
||||
});
|
||||
|
@ -668,7 +672,7 @@ class IDB extends _base2.default {
|
|||
await this.open();
|
||||
return new Promise((resolve, reject) => {
|
||||
const { transaction, store } = this.prepare(undefined, "__meta__");
|
||||
const request = store.get("lastModified");
|
||||
const request = store.get(`${this.storeName}-lastModified`);
|
||||
transaction.onerror = event => reject(event.target.error);
|
||||
transaction.oncomplete = event => {
|
||||
resolve(request.result && request.result.value || null);
|
||||
|
@ -950,7 +954,7 @@ function createUUIDSchema() {
|
|||
},
|
||||
|
||||
validate(id) {
|
||||
return (0, _utils.isUUID)(id);
|
||||
return typeof id == "string" && /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(id);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -2320,11 +2324,9 @@ Object.defineProperty(exports, "__esModule", {
|
|||
exports.sortObjects = sortObjects;
|
||||
exports.filterObject = filterObject;
|
||||
exports.filterObjects = filterObjects;
|
||||
exports.isUUID = isUUID;
|
||||
exports.waterfall = waterfall;
|
||||
exports.deepEqual = deepEqual;
|
||||
exports.omitKeys = omitKeys;
|
||||
const RE_UUID = exports.RE_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
/**
|
||||
* Checks if a value is undefined.
|
||||
|
@ -2390,16 +2392,6 @@ function filterObjects(filters, list) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string is an UUID.
|
||||
*
|
||||
* @param {String} uuid The uuid to validate.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function isUUID(uuid) {
|
||||
return RE_UUID.test(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a list of functions sequentially, which can be sync or async; in
|
||||
* case of async, functions must return a promise.
|
||||
|
|
|
@ -337,8 +337,12 @@ add_task(async function test_kinto_sync() {
|
|||
result = await collection.sync();
|
||||
Assert.ok(result.ok);
|
||||
list = await collection.list();
|
||||
const after = list.data[0].title;
|
||||
const after = list.data[1].title;
|
||||
Assert.notEqual(before, after);
|
||||
|
||||
const manualID = list.data[0].id;
|
||||
Assert.equal(list.data.length, 3);
|
||||
Assert.equal(manualID, "some-manually-chosen-id");
|
||||
} finally {
|
||||
await sqliteHandle.close();
|
||||
}
|
||||
|
@ -431,7 +435,7 @@ function getSampleResponse(req, port) {
|
|||
"Access-Control-Expose-Headers: Retry-After, Content-Length, Alert, Backoff",
|
||||
"Content-Type: application/json; charset=UTF-8",
|
||||
"Server: waitress",
|
||||
"Etag: \"1445607541265\""
|
||||
"Etag: \"1445607541267\""
|
||||
],
|
||||
"status": {status: 200, statusText: "OK"},
|
||||
"responseBody": JSON.stringify({
|
||||
|
@ -440,6 +444,11 @@ function getSampleResponse(req, port) {
|
|||
"done": false,
|
||||
"id": "901967b0-f729-4b30-8d8d-499cba7f4b1d",
|
||||
"title": "Modified title"
|
||||
}, {
|
||||
"last_modified": 1445607541267,
|
||||
"done": true,
|
||||
"id": "some-manually-chosen-id",
|
||||
"title": "New record with custom ID"
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче