Commit 3d68e978 authored by Aurel's avatar Aurel

merge mapping & wip from romain

parents 3d191693 9e9d22cb
...@@ -8455,11 +8455,10 @@ return new Parser; ...@@ -8455,11 +8455,10 @@ return new Parser;
function ReplicateStorage(spec) { function ReplicateStorage(spec) {
this._query_options = spec.query || {}; this._query_options = spec.query || {};
if (spec.signature_select_metadata !== undefined) { if (spec.signature_hash_key !== undefined) {
this._query_options.select_list = [spec.signature_select_metadata]; this._query_options.select_list = [spec.signature_hash_key];
} }
this._signature_select_metadata = spec.signature_select_metadata; this._signature_hash_key = spec.signature_hash_key;
this._local_sub_storage = jIO.createJIO(spec.local_sub_storage); this._local_sub_storage = jIO.createJIO(spec.local_sub_storage);
this._remote_sub_storage = jIO.createJIO(spec.remote_sub_storage); this._remote_sub_storage = jIO.createJIO(spec.remote_sub_storage);
...@@ -9176,12 +9175,12 @@ return new Parser; ...@@ -9176,12 +9175,12 @@ return new Parser;
options) { options) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (options.signature_select_metadata !== undefined) { if (options.signature_hash_key !== undefined) {
return callAllDocsOnStorage(context, destination, return callAllDocsOnStorage(context, destination,
cache, destination_key) cache, destination_key)
.push(function (result) { .push(function (result) {
if (result.hasOwnProperty(id)) { if (result.hasOwnProperty(id)) {
return [null, result[id][options.signature_select_metadata]]; return [null, result[id][options.signature_hash_key]];
} }
return [null, null]; return [null, null];
}); });
...@@ -9388,8 +9387,8 @@ return new Parser; ...@@ -9388,8 +9387,8 @@ return new Parser;
} }
local_hash = null; local_hash = null;
if (options.signature_select_metadata !== undefined) { if (options.signature_hash_key !== undefined) {
local_hash = local_dict[key][options.signature_select_metadata]; local_hash = local_dict[key][options.signature_hash_key];
if (is_modification === true) { if (is_modification === true) {
// Bypass fetching all documents and calculating the sha // Bypass fetching all documents and calculating the sha
// Compare the select list values returned by allDocs calls // Compare the select list values returned by allDocs calls
...@@ -9541,7 +9540,7 @@ return new Parser; ...@@ -9541,7 +9540,7 @@ return new Parser;
check_creation: context._check_local_creation, check_creation: context._check_local_creation,
check_deletion: context._check_local_deletion, check_deletion: context._check_local_deletion,
operation_amount: context._parallel_operation_amount, operation_amount: context._parallel_operation_amount,
signature_select_metadata: context._signature_select_metadata signature_hash_key: context._signature_hash_key
}) })
.push(function () { .push(function () {
return signature_allDocs; return signature_allDocs;
...@@ -9569,7 +9568,7 @@ return new Parser; ...@@ -9569,7 +9568,7 @@ return new Parser;
check_creation: context._check_remote_creation, check_creation: context._check_remote_creation,
check_deletion: context._check_remote_deletion, check_deletion: context._check_remote_deletion,
operation_amount: context._parallel_operation_amount, operation_amount: context._parallel_operation_amount,
signature_select_metadata: context._signature_select_metadata signature_hash_key: context._signature_hash_key
}); });
} }
}) })
...@@ -12653,14 +12652,18 @@ return new Parser; ...@@ -12653,14 +12652,18 @@ return new Parser;
}); });
}; };
function handleGet(request, resolve, reject) { function handleGet(store, id, resolve, reject) {
var request = store.get(id);
request.onerror = reject; request.onerror = reject;
request.onsuccess = function () { request.onsuccess = function () {
if (request.result) { if (request.result) {
resolve(request.result); resolve(request.result);
} else { } else {
// XXX How to get ID reject(new jIO.util.jIOError(
reject(new jIO.util.jIOError("Cannot find document", 404)); "IndexedDB: cannot find object '" + id + "' in the '" +
store.name + "' store",
404
));
} }
}; };
} }
...@@ -12671,7 +12674,8 @@ return new Parser; ...@@ -12671,7 +12674,8 @@ return new Parser;
return new RSVP.Promise(function (resolve, reject) { return new RSVP.Promise(function (resolve, reject) {
var transaction = openTransaction(db, ["metadata"], "readonly"); var transaction = openTransaction(db, ["metadata"], "readonly");
handleGet( handleGet(
transaction.objectStore("metadata").get(id), transaction.objectStore("metadata"),
id,
resolve, resolve,
reject reject
); );
...@@ -12704,7 +12708,8 @@ return new Parser; ...@@ -12704,7 +12708,8 @@ return new Parser;
); );
} }
handleGet( handleGet(
transaction.objectStore("metadata").get(id), transaction.objectStore("metadata"),
id,
getAttachments, getAttachments,
reject reject
); );
...@@ -12832,7 +12837,8 @@ return new Parser; ...@@ -12832,7 +12837,8 @@ return new Parser;
result_list.push(result); result_list.push(result);
} }
i += 1; i += 1;
handleGet(store.get(buildKeyPath([id, name, i])), handleGet(store,
buildKeyPath([id, name, i]),
(i <= end_index) ? getPart(i) : resolver, (i <= end_index) ? getPart(i) : resolver,
reject reject
); );
...@@ -12841,8 +12847,8 @@ return new Parser; ...@@ -12841,8 +12847,8 @@ return new Parser;
getPart(start_index - 1)(); getPart(start_index - 1)();
} }
// XXX Should raise if key is not good // XXX Should raise if key is not good
handleGet(transaction.objectStore("attachment") handleGet(transaction.objectStore("attachment"),
.get(buildKeyPath([id, name])), buildKeyPath([id, name]),
getBlob, getBlob,
reject reject
); );
...@@ -13686,6 +13692,9 @@ return new Parser; ...@@ -13686,6 +13692,9 @@ return new Parser;
} }
} }
} }
if (storage._map_id[0] === "equalSubProperty") {
storage._mapping_dict[storage._map_id[1]] = ["keep"];
}
if (storage._query.query !== undefined) { if (storage._query.query !== undefined) {
query_list.push(QueryFactory.create(storage._query.query)); query_list.push(QueryFactory.create(storage._query.query));
} }
...@@ -13853,12 +13862,25 @@ return new Parser; ...@@ -13853,12 +13862,25 @@ return new Parser;
this, this,
doc doc
), ),
id = doc[this._property_for_sub_id]; id = doc[this._property_for_sub_id],
storage = this;
if (this._property_for_sub_id && id !== undefined) { if (this._property_for_sub_id && id !== undefined) {
return this._sub_storage.put(id, sub_doc); return this._sub_storage.put(id, sub_doc);
} }
if (!this._id_mapped || doc[this._id_mapped] !== undefined) { if (!this._id_mapped || doc[this._id_mapped] !== undefined) {
return this._sub_storage.post(sub_doc); return getSubStorageId(storage, id, doc)
.push(function (sub_id) {
return storage._sub_storage.put(sub_id, sub_doc);
})
.push(function () {
return doc[storage._id_mapped];
})
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError) {
return storage._sub_storage.post(sub_doc);
}
throw error;
});
} }
throw new jIO.util.jIOError( throw new jIO.util.jIOError(
"post is not supported with id mapped", "post is not supported with id mapped",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2597,11 +2597,10 @@ return new Parser; ...@@ -2597,11 +2597,10 @@ return new Parser;
function ReplicateStorage(spec) { function ReplicateStorage(spec) {
this._query_options = spec.query || {}; this._query_options = spec.query || {};
if (spec.signature_select_metadata !== undefined) { if (spec.signature_hash_key !== undefined) {
this._query_options.select_list = [spec.signature_select_metadata]; this._query_options.select_list = [spec.signature_hash_key];
} }
this._signature_select_metadata = spec.signature_select_metadata; this._signature_hash_key = spec.signature_hash_key;
this._local_sub_storage = jIO.createJIO(spec.local_sub_storage); this._local_sub_storage = jIO.createJIO(spec.local_sub_storage);
this._remote_sub_storage = jIO.createJIO(spec.remote_sub_storage); this._remote_sub_storage = jIO.createJIO(spec.remote_sub_storage);
...@@ -3318,12 +3317,12 @@ return new Parser; ...@@ -3318,12 +3317,12 @@ return new Parser;
options) { options) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (options.signature_select_metadata !== undefined) { if (options.signature_hash_key !== undefined) {
return callAllDocsOnStorage(context, destination, return callAllDocsOnStorage(context, destination,
cache, destination_key) cache, destination_key)
.push(function (result) { .push(function (result) {
if (result.hasOwnProperty(id)) { if (result.hasOwnProperty(id)) {
return [null, result[id][options.signature_select_metadata]]; return [null, result[id][options.signature_hash_key]];
} }
return [null, null]; return [null, null];
}); });
...@@ -3530,8 +3529,8 @@ return new Parser; ...@@ -3530,8 +3529,8 @@ return new Parser;
} }
local_hash = null; local_hash = null;
if (options.signature_select_metadata !== undefined) { if (options.signature_hash_key !== undefined) {
local_hash = local_dict[key][options.signature_select_metadata]; local_hash = local_dict[key][options.signature_hash_key];
if (is_modification === true) { if (is_modification === true) {
// Bypass fetching all documents and calculating the sha // Bypass fetching all documents and calculating the sha
// Compare the select list values returned by allDocs calls // Compare the select list values returned by allDocs calls
...@@ -3683,7 +3682,7 @@ return new Parser; ...@@ -3683,7 +3682,7 @@ return new Parser;
check_creation: context._check_local_creation, check_creation: context._check_local_creation,
check_deletion: context._check_local_deletion, check_deletion: context._check_local_deletion,
operation_amount: context._parallel_operation_amount, operation_amount: context._parallel_operation_amount,
signature_select_metadata: context._signature_select_metadata signature_hash_key: context._signature_hash_key
}) })
.push(function () { .push(function () {
return signature_allDocs; return signature_allDocs;
...@@ -3711,7 +3710,7 @@ return new Parser; ...@@ -3711,7 +3710,7 @@ return new Parser;
check_creation: context._check_remote_creation, check_creation: context._check_remote_creation,
check_deletion: context._check_remote_deletion, check_deletion: context._check_remote_deletion,
operation_amount: context._parallel_operation_amount, operation_amount: context._parallel_operation_amount,
signature_select_metadata: context._signature_select_metadata signature_hash_key: context._signature_hash_key
}); });
} }
}) })
...@@ -5255,6 +5254,9 @@ return new Parser; ...@@ -5255,6 +5254,9 @@ return new Parser;
} }
} }
} }
if (storage._map_id[0] === "equalSubProperty") {
storage._mapping_dict[storage._map_id[1]] = ["keep"];
}
if (storage._query.query !== undefined) { if (storage._query.query !== undefined) {
query_list.push(QueryFactory.create(storage._query.query)); query_list.push(QueryFactory.create(storage._query.query));
} }
...@@ -5422,12 +5424,25 @@ return new Parser; ...@@ -5422,12 +5424,25 @@ return new Parser;
this, this,
doc doc
), ),
id = doc[this._property_for_sub_id]; id = doc[this._property_for_sub_id],
storage = this;
if (this._property_for_sub_id && id !== undefined) { if (this._property_for_sub_id && id !== undefined) {
return this._sub_storage.put(id, sub_doc); return this._sub_storage.put(id, sub_doc);
} }
if (!this._id_mapped || doc[this._id_mapped] !== undefined) { if (!this._id_mapped || doc[this._id_mapped] !== undefined) {
return this._sub_storage.post(sub_doc); return getSubStorageId(storage, id, doc)
.push(function (sub_id) {
return storage._sub_storage.put(sub_id, sub_doc);
})
.push(function () {
return doc[storage._id_mapped];
})
.push(undefined, function (error) {
if (error instanceof jIO.util.jIOError) {
return storage._sub_storage.post(sub_doc);
}
throw error;
});
} }
throw new jIO.util.jIOError( throw new jIO.util.jIOError(
"post is not supported with id mapped", "post is not supported with id mapped",
......
{ {
"name": "jio", "name": "jio",
"version": "v3.17.0", "version": "v3.18.0",
"license": "LGPLv3", "license": "LGPLv3",
"author": "Nexedi SA", "author": "Nexedi SA",
"contributors": [ "contributors": [
......
...@@ -209,14 +209,18 @@ ...@@ -209,14 +209,18 @@
}); });
}; };
function handleGet(request, resolve, reject) { function handleGet(store, id, resolve, reject) {
var request = store.get(id);
request.onerror = reject; request.onerror = reject;
request.onsuccess = function () { request.onsuccess = function () {
if (request.result) { if (request.result) {
resolve(request.result); resolve(request.result);
} else { } else {
// XXX How to get ID reject(new jIO.util.jIOError(
reject(new jIO.util.jIOError("Cannot find document", 404)); "IndexedDB: cannot find object '" + id + "' in the '" +
store.name + "' store",
404
));
} }
}; };
} }
...@@ -227,7 +231,8 @@ ...@@ -227,7 +231,8 @@
return new RSVP.Promise(function (resolve, reject) { return new RSVP.Promise(function (resolve, reject) {
var transaction = openTransaction(db, ["metadata"], "readonly"); var transaction = openTransaction(db, ["metadata"], "readonly");
handleGet( handleGet(
transaction.objectStore("metadata").get(id), transaction.objectStore("metadata"),
id,
resolve, resolve,
reject reject
); );
...@@ -260,7 +265,8 @@ ...@@ -260,7 +265,8 @@
); );
} }
handleGet( handleGet(
transaction.objectStore("metadata").get(id), transaction.objectStore("metadata"),
id,
getAttachments, getAttachments,
reject reject
); );
...@@ -388,7 +394,8 @@ ...@@ -388,7 +394,8 @@
result_list.push(result); result_list.push(result);
} }
i += 1; i += 1;
handleGet(store.get(buildKeyPath([id, name, i])), handleGet(store,
buildKeyPath([id, name, i]),
(i <= end_index) ? getPart(i) : resolver, (i <= end_index) ? getPart(i) : resolver,
reject reject
); );
...@@ -397,8 +404,8 @@ ...@@ -397,8 +404,8 @@
getPart(start_index - 1)(); getPart(start_index - 1)();
} }
// XXX Should raise if key is not good // XXX Should raise if key is not good
handleGet(transaction.objectStore("attachment") handleGet(transaction.objectStore("attachment"),
.get(buildKeyPath([id, name])), buildKeyPath([id, name]),
getBlob, getBlob,
reject reject
); );
......
...@@ -55,11 +55,10 @@ ...@@ -55,11 +55,10 @@
function ReplicateStorage(spec) { function ReplicateStorage(spec) {
this._query_options = spec.query || {}; this._query_options = spec.query || {};
if (spec.signature_select_metadata !== undefined) { if (spec.signature_hash_key !== undefined) {
this._query_options.select_list = [spec.signature_select_metadata]; this._query_options.select_list = [spec.signature_hash_key];
} }
this._signature_select_metadata = spec.signature_select_metadata; this._signature_hash_key = spec.signature_hash_key;
this._local_sub_storage = jIO.createJIO(spec.local_sub_storage); this._local_sub_storage = jIO.createJIO(spec.local_sub_storage);
this._remote_sub_storage = jIO.createJIO(spec.remote_sub_storage); this._remote_sub_storage = jIO.createJIO(spec.remote_sub_storage);
...@@ -776,12 +775,12 @@ ...@@ -776,12 +775,12 @@
options) { options) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
if (options.signature_select_metadata !== undefined) { if (options.signature_hash_key !== undefined) {
return callAllDocsOnStorage(context, destination, return callAllDocsOnStorage(context, destination,
cache, destination_key) cache, destination_key)
.push(function (result) { .push(function (result) {
if (result.hasOwnProperty(id)) { if (result.hasOwnProperty(id)) {
return [null, result[id][options.signature_select_metadata]]; return [null, result[id][options.signature_hash_key]];
} }
return [null, null]; return [null, null];
}); });
...@@ -988,8 +987,8 @@ ...@@ -988,8 +987,8 @@
} }
local_hash = null; local_hash = null;
if (options.signature_select_metadata !== undefined) { if (options.signature_hash_key !== undefined) {
local_hash = local_dict[key][options.signature_select_metadata]; local_hash = local_dict[key][options.signature_hash_key];
if (is_modification === true) { if (is_modification === true) {
// Bypass fetching all documents and calculating the sha // Bypass fetching all documents and calculating the sha
// Compare the select list values returned by allDocs calls // Compare the select list values returned by allDocs calls
...@@ -1141,7 +1140,7 @@ ...@@ -1141,7 +1140,7 @@
check_creation: context._check_local_creation, check_creation: context._check_local_creation,
check_deletion: context._check_local_deletion, check_deletion: context._check_local_deletion,
operation_amount: context._parallel_operation_amount, operation_amount: context._parallel_operation_amount,
signature_select_metadata: context._signature_select_metadata signature_hash_key: context._signature_hash_key
}) })
.push(function () { .push(function () {
return signature_allDocs; return signature_allDocs;
...@@ -1169,7 +1168,7 @@ ...@@ -1169,7 +1168,7 @@
check_creation: context._check_remote_creation, check_creation: context._check_remote_creation,
check_deletion: context._check_remote_deletion, check_deletion: context._check_remote_deletion,
operation_amount: context._parallel_operation_amount, operation_amount: context._parallel_operation_amount,
signature_select_metadata: context._signature_select_metadata signature_hash_key: context._signature_hash_key
}); });
} }
}) })
......
...@@ -493,7 +493,10 @@ ...@@ -493,7 +493,10 @@
}) })
.fail(function (error) { .fail(function (error) {
ok(error instanceof jIO.util.jIOError); ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document"); equal(
error.message,
"IndexedDB: cannot find object 'inexistent' in the 'metadata' store"
);
equal(error.status_code, 404); equal(error.status_code, 404);
}) })
.fail(function (error) { .fail(function (error) {
...@@ -679,7 +682,10 @@ ...@@ -679,7 +682,10 @@
}) })
.fail(function (error) { .fail(function (error) {
ok(error instanceof jIO.util.jIOError); ok(error instanceof jIO.util.jIOError);
equal(error.message, "Cannot find document"); equal(
error.message,
"IndexedDB: cannot find object 'inexistent' in the 'metadata' store"
);
equal(error.status_code, 404); equal(error.status_code, 404);
}) })
.fail(function (error) { .fail(function (error) {
......
...@@ -73,8 +73,7 @@ ...@@ -73,8 +73,7 @@
equal(jio.__storage._check_remote_attachment_creation, false); equal(jio.__storage._check_remote_attachment_creation, false);
equal(jio.__storage._check_remote_attachment_deletion, false); equal(jio.__storage._check_remote_attachment_deletion, false);
equal(jio.__storage._check_remote_attachment_modification, false); equal(jio.__storage._check_remote_attachment_modification, false);
equal(jio.__storage._signature_select_metadata, undefined); equal(jio.__storage._signature_hash_key, undefined);
equal(jio.__storage._custom_signature_sub_storage, false); equal(jio.__storage._custom_signature_sub_storage, false);
equal(jio.__storage._signature_hash, equal(jio.__storage._signature_hash,
"_replicate_7209dfbcaff00f6637f939fdd71fa896793ed385"); "_replicate_7209dfbcaff00f6637f939fdd71fa896793ed385");
...@@ -129,7 +128,7 @@ ...@@ -129,7 +128,7 @@
check_remote_attachment_creation: true, check_remote_attachment_creation: true,
check_remote_attachment_deletion: true, check_remote_attachment_deletion: true,
check_remote_attachment_modification: true, check_remote_attachment_modification: true,
signature_select_metadata: 'bar' signature_hash_key: 'bar'
}); });
deepEqual( deepEqual(
...@@ -153,8 +152,7 @@ ...@@ -153,8 +152,7 @@
equal(jio.__storage._check_remote_attachment_creation, true); equal(jio.__storage._check_remote_attachment_creation, true);
equal(jio.__storage._check_remote_attachment_deletion, true); equal(jio.__storage._check_remote_attachment_deletion, true);
equal(jio.__storage._check_remote_attachment_modification, true); equal(jio.__storage._check_remote_attachment_modification, true);
equal(jio.__storage._signature_select_metadata, 'bar'); equal(jio.__storage._signature_hash_key, 'bar');
equal(jio.__storage._custom_signature_sub_storage, false); equal(jio.__storage._custom_signature_sub_storage, false);
ok(jio.__storage._signature_sub_storage instanceof jio.constructor); ok(jio.__storage._signature_sub_storage instanceof jio.constructor);
equal(jio.__storage._signature_sub_storage.__type, "query"); equal(jio.__storage._signature_sub_storage.__type, "query");
...@@ -734,4 +732,4 @@ ...@@ -734,4 +732,4 @@
}); });
}); });
}(jIO, QUnit, Blob)); }(jIO, QUnit, Blob));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment