From 16b4b5172c88c74725606256334890e109df24ad Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Wed, 11 Jul 2018 14:50:47 +0200 Subject: [PATCH] Bug 1471901 - Allow synchronization of custom record IDs in RemoteSettings r=florian MozReview-Commit-ID: 5LjcZ7Xjjxi --HG-- extra : rebase_source : 5e51abfaba7908c977d2f82e6e5b94ebf21d758c --- services/common/kinto-offline-client.js | 32 +++++++++--------------- services/common/tests/unit/test_kinto.js | 13 ++++++++-- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/services/common/kinto-offline-client.js b/services/common/kinto-offline-client.js index 9b039b90e642..12c21963d78c 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.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 { 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. diff --git a/services/common/tests/unit/test_kinto.js b/services/common/tests/unit/test_kinto.js index cedf7e1c99d0..0b48742605d4 100644 --- a/services/common/tests/unit/test_kinto.js +++ b/services/common/tests/unit/test_kinto.js @@ -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" }] }) }