Commit 0bd5794b authored by Romain Courteaud's avatar Romain Courteaud

Update external libraries.

parent 661b7ac5
......@@ -12,7 +12,9 @@ all: external lint test build doc
#########################################
# Download all external libs
external: lib/sinon/sinon.js \
lib/sinon/sinon-qunit.js \
lib/jquery/jquery.js \
lib/require/require.js \
lib/qunit/qunit.js \
lib/qunit/qunit.css \
lib/jio/jio.js \
......@@ -24,9 +26,18 @@ lib/sinon/sinon.js:
@mkdir -p $(@D)
curl -s -o $@ http://sinonjs.org/releases/sinon-1.7.3.js
lib/sinon/sinon-qunit.js:
@mkdir -p $(@D)
# curl -s -o $@ http://sinonjs.org/releases/sinon-qunit-1.0.0.js
curl -s -o $@ https://raw.github.com/jfromaniello/jmail/master/scripts/Tests/sinon-qunit-1.0.0.js
lib/jquery/jquery.js:
@mkdir -p $(@D)
curl -s -o $@ http://code.jquery.com/jquery-1.9.1.js
curl -s -o $@ http://code.jquery.com/jquery-2.0.3.js
lib/require/require.js:
@mkdir -p $(@D)
curl -s -o $@ http://requirejs.org/docs/release/2.1.8/comments/require.js
lib/qunit/qunit.%:
@mkdir -p $(@D)
......@@ -69,4 +80,4 @@ lint: ${BUILDDIR}/$(RENDERJS).lint
doc:
$(YUIDOC_CMD) .
clean:
rm -rf $(RENDERJS_MIN) ${BUILDDIR} lib/sinon lib/jquery lib/qunit lib/jio
rm -rf $(RENDERJS_MIN) ${BUILDDIR} lib/sinon lib/jquery lib/qunit lib/jio lib/require
......@@ -741,6 +741,33 @@ function stringEscapeRegexpCharacters(string) {
_export("stringEscapeRegexpCharacters", stringEscapeRegexpCharacters);
/**
* Convert metadata values to array of strings. ex:
*
* "a" -> ["a"],
* {"content": "a"} -> ["a"]
*
* @param {Any} value The metadata value
* @return {Array} The value in string array format
*/
function metadataValueToStringArray(value) {
var i, new_value = [];
if (value === undefined) {
return undefined;
}
if (!Array.isArray(value)) {
value = [value];
}
for (i = 0; i < value.length; i += 1) {
if (typeof value[i] === 'object') {
new_value[i] = value[i].content;
} else {
new_value[i] = value[i];
}
}
return new_value;
}
/**
* A sort function to sort items by key
*
......@@ -751,12 +778,50 @@ _export("stringEscapeRegexpCharacters", stringEscapeRegexpCharacters);
function sortFunction(key, way) {
if (way === 'descending') {
return function (a, b) {
return a[key] < b[key] ? 1 : a[key] > b[key] ? -1 : 0;
// this comparison is 5 times faster than json comparison
var i, l;
a = metadataValueToStringArray(a[key]) || [];
b = metadataValueToStringArray(b[key]) || [];
l = a.length > b.length ? a.length : b.length;
for (i = 0; i < l; i += 1) {
if (a[i] === undefined) {
return 1;
}
if (b[i] === undefined) {
return -1;
}
if (a[i] > b[i]) {
return -1;
}
if (a[i] < b[i]) {
return 1;
}
}
return 0;
};
}
if (way === 'ascending') {
return function (a, b) {
return a[key] > b[key] ? 1 : a[key] < b[key] ? -1 : 0;
// this comparison is 5 times faster than json comparison
var i, l;
a = metadataValueToStringArray(a[key]) || [];
b = metadataValueToStringArray(b[key]) || [];
l = a.length > b.length ? a.length : b.length;
for (i = 0; i < l; i += 1) {
if (a[i] === undefined) {
return -1;
}
if (b[i] === undefined) {
return 1;
}
if (a[i] > b[i]) {
return 1;
}
if (a[i] < b[i]) {
return -1;
}
}
return 0;
};
}
throw new TypeError("complex_queries.sortFunction(): " +
......@@ -1238,10 +1303,34 @@ SimpleQuery.prototype.serialized = function () {
*/
SimpleQuery.prototype["="] = function (object_value, comparison_value,
wildcard_character) {
return convertStringToRegExp(
comparison_value.toString(),
wildcard_character || "%"
).test(object_value.toString());
var value, i;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
value = value.content;
}
if (comparison_value === undefined) {
if (value === undefined) {
return true;
}
return false;
}
if (value === undefined) {
return false;
}
if (
convertStringToRegExp(
comparison_value.toString(),
wildcard_character
).test(value.toString())
) {
return true;
}
}
return false;
};
/**
......@@ -1255,10 +1344,34 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
*/
SimpleQuery.prototype["!="] = function (object_value, comparison_value,
wildcard_character) {
return !convertStringToRegExp(
comparison_value.toString(),
wildcard_character || "%"
).test(object_value.toString());
var value, i;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
value = value.content;
}
if (comparison_value === undefined) {
if (value === undefined) {
return false;
}
return true;
}
if (value === undefined) {
return true;
}
if (
convertStringToRegExp(
comparison_value.toString(),
wildcard_character
).test(value.toString())
) {
return false;
}
}
return true;
};
/**
......@@ -1270,7 +1383,15 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
* @return {Boolean} true if lower, false otherwise
*/
SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
return object_value < comparison_value;
var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value < comparison_value;
};
/**
......@@ -1283,7 +1404,15 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
* @return {Boolean} true if equal or lower, false otherwise
*/
SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
return object_value <= comparison_value;
var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value <= comparison_value;
};
/**
......@@ -1296,7 +1425,15 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
* @return {Boolean} true if greater, false otherwise
*/
SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
return object_value > comparison_value;
var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value > comparison_value;
};
/**
......@@ -1309,7 +1446,15 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
* @return {Boolean} true if equal or greater, false otherwise
*/
SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
return object_value >= comparison_value;
var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value >= comparison_value;
};
query_class_dict.simple = SimpleQuery;
......
......@@ -531,13 +531,13 @@ var command = function (spec, my) {
* @param {object} storage The storage.
*/
that.validate = function (storage) {
if (typeof priv.doc._id === "string" && priv.doc._id.match(" ")) {
if (typeof priv.doc._id === "string" && priv.doc._id === "") {
that.error({
"status": 21,
"statusText": "Invalid Document Id",
"error": "invalid_document_id",
"message": "The document id is invalid",
"reason": "The document id contains spaces"
"reason": "empty"
});
return false;
}
......
This diff is collapsed.
This diff is collapsed.
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