Commit 21704054 authored by Aurélien Vermylen's avatar Aurélien Vermylen

Merge branch 'mappingstorage' of https://lab.nexedi.com/vincentB/jio into HEAD

and don't take new dists into account.

Conflicts:
	Gruntfile.js
parents aefd3402 6a835b79
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "jio",
"version": "v3.20.0",
"version": "v3.21.0",
"license": "LGPLv3",
"author": "Nexedi SA",
"contributors": [
......
......@@ -10,24 +10,29 @@
(function (jIO, RSVP, DOMException, Blob, crypto, Uint8Array, ArrayBuffer) {
"use strict";
/*
The cryptography system used by this storage is AES-GCM.
Here is an example of how to generate a key to the json format:
return new RSVP.Queue()
.push(function () {
return crypto.subtle.generateKey({name: "AES-GCM", length: 256},
true, ["encrypt", "decrypt"]);
})
.push(function (key) {
return crypto.subtle.exportKey("jwk", key);
})
.push(function (json_key) {
var jio = jIO.createJIO({
type: "crypt",
key: json_key,
sub_storage: {storage_definition}
});
});
// you the cryptography system used by this storage is AES-GCM.
// here is an example of how to generate a key to the json format.
// var key,
// jsonKey;
// crypto.subtle.generateKey({name: "AES-GCM",length: 256},
// (true), ["encrypt", "decrypt"])
// .then(function(res){key = res;});
//
// window.crypto.subtle.exportKey("jwk", key)
// .then(function(res){jsonKey = val})
//
//var storage = jIO.createJIO({type: "crypt", key: jsonKey,
// sub_storage: {...}});
// find more informations about this cryptography system on
// https://github.com/diafygi/webcrypto-examples#aes-gcm
Find more informations about this cryptography system on
https://github.com/diafygi/webcrypto-examples#aes-gcm
*/
/**
* The JIO Cryptography Storage extension
......
This diff is collapsed.
......@@ -90,7 +90,7 @@ case 5: case 8: case 11: case 14: case 16:
this.$ = $$[$0];
break;
case 6:
this.$ = mkComplexQuery('OR', [$$[$0-1], $$[$0]]);
this.$ = mkComplexQuery('AND', [$$[$0-1], $$[$0]]);
break;
case 7:
this.$ = mkComplexQuery('OR', [$$[$0-2], $$[$0]]);
......
......@@ -45,7 +45,7 @@ end
search_text
: and_expression { $$ = $1; }
| and_expression search_text { $$ = mkComplexQuery('OR', [$1, $2]); }
| and_expression search_text { $$ = mkComplexQuery('AND', [$1, $2]); }
| and_expression OR search_text { $$ = mkComplexQuery('OR', [$1, $3]); }
;
......
......@@ -717,7 +717,8 @@
matchMethod = null,
operator = this.operator,
value = null,
key = this.key;
key = this.key,
k;
if (!(regexp_comparaison.test(operator))) {
// `operator` is not correct, we have to change it to "like" or "="
......@@ -736,6 +737,22 @@
key = this._key_schema.key_set[key];
}
// match with all the fields if key is empty
if (key === '') {
matchMethod = this.like;
value = '%' + this.value + '%';
for (k in item) {
if (item.hasOwnProperty(k)) {
if (k !== '__id') {
if (matchMethod(item[k], value) === true) {
return true;
}
}
}
}
return false;
}
if (typeof key === 'object') {
checkKey(key);
object_value = item[key.read_from];
......
This diff is collapsed.
......@@ -154,7 +154,8 @@
.exec(doc_list);
})
.then(function (doc_list) {
deepEqual(doc_list, [], 'No document should be kept');
deepEqual(doc_list, [{"identifier": "测试一", "title": "标题"}
], 'Full text query matched document should be returned');
})
.fail(function (error) {
ok(false, error);
......@@ -357,4 +358,103 @@
], 'Documents with newlines are matched');
}).always(start);
});
test('Default operator for complex query', function () {
var doc_list = [
{"identifier": "a", "value": "test1", "time": "2016"},
{"identifier": "a", "value": "test", "time": "2016"},
{"identifier": "c", "value": "test1", "time": "2017"}
];
stop();
expect(1);
jIO.QueryFactory.create('identifier:%a% value:"%test1%" time:%2016%')
.exec(doc_list)
.then(function (doc_list) {
deepEqual(doc_list, [
{"identifier": "a", "value": "test1", "time": "2016"}],
'Document which matches all the fields is matched');
}).always(start);
});
test('Full text query with single word', function () {
var doc_list = [
{"identifier": "a", "value": "test", "time": "2016"},
{"identifier": "b", "value": "test 1", "time": "2017"},
{"identifier": "c", "value": "test 2016", "time": "2017"}
];
stop();
expect(2);
jIO.QueryFactory.create('test').exec(doc_list).
then(function (doc_list) {
deepEqual(doc_list, [
{"identifier": "a", "value": "test", "time": "2016"},
{"identifier": "b", "value": "test 1", "time": "2017"},
{"identifier": "c", "value": "test 2016", "time": "2017"}
], 'Documents which have test in any column are matched');
doc_list = [
{"identifier": "a", "value": "test", "time": "2016"},
{"identifier": "b", "value": "test 1", "time": "2017"},
{"identifier": "c", "value": "test 2016", "time": "2017"}
];
return jIO.QueryFactory.create('2016').exec(doc_list).
then(function (doc_list) {
deepEqual(doc_list, [
{"identifier": "a", "value": "test", "time": "2016"},
{"identifier": "c", "value": "test 2016", "time": "2017"}
], 'Documents which have 2016 in any column are matched');
}).always(start);
});
});
test('Full text query with multiple words', function () {
var doc_list = [
{"identifier": "a", "value": "test post", "time": "2016"},
{"identifier": "b", "value": "test post 1", "time": "2017"},
{"identifier": "c", "value": "test post 2016", "time": "2017"}
];
stop();
expect(2);
jIO.QueryFactory.create('test post').exec(doc_list).
then(function (doc_list) {
deepEqual(doc_list, [
{"identifier": "a", "value": "test post", "time": "2016"},
{"identifier": "b", "value": "test post 1", "time": "2017"},
{"identifier": "c", "value": "test post 2016", "time": "2017"}
], 'Documents which have test post in any column are matched');
doc_list = [
{"identifier": "a", "value": "test post", "time": "2016"},
{"identifier": "b", "value": "test post 1", "time": "2017"},
{"identifier": "c", "value": "test post 2016", "time": "2017"}
];
return jIO.QueryFactory.create('test post 2016').exec(doc_list).
then(function (doc_list) {
deepEqual(doc_list, [
{"identifier": "a", "value": "test post", "time": "2016"},
{"identifier": "c", "value": "test post 2016", "time": "2017"}
], 'Documents which have test post 2016 in any column are matched');
}).always(start);
});
});
// Asterisk wildcard is not supported yet.
/* test('Full text query with asterisk', function () {
var doc_list = [
{"identifier": "abc"},
{"identifier": "ab"}
];
stop();
expect(1);
jIO.QueryFactory.create('a*').exec(doc_list).
then(function (doc_list) {
deepEqual(doc_list, [
{"identifier": "abc"},
{"identifier": "ab"}
], 'Documents which satisfy the asterisk wildcard should be returned')
.always(start);
});
});*/
}));
......@@ -28,7 +28,6 @@
<script src="queries/key-jiodate.tests.js"></script>
<!--script src="queries/key-localstorage.tests.js"></script-->
<script src="jio.storage/memorystorage.tests.js"></script>
<script src="jio.storage/querystorage.tests.js"></script>
<script src="jio.storage/localstorage.tests.js"></script>
......@@ -45,7 +44,7 @@
<script src="jio.storage/replicatestorage_fastrepair.tests.js"></script>
<script src="jio.storage/replicatestorage_fastrepairattachment.tests.js"></script>
<script src="jio.storage/shastorage.tests.js"></script>
<script src="jio.storage/mappingstorage.tests.js"></script>
<!--script src="jio.storage/qiniustorage.tests.js"></script-->
<!--script src="jio.storage/indexstorage.tests.js"></script-->
<script src="jio.storage/cryptstorage.tests.js"></script>
......
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