Commit 1f88c5ad authored by Marco Mariani's avatar Marco Mariani

jio.js and complex_queries.js updated

parent a935229f
......@@ -97,17 +97,18 @@ function __NODEJS_lex( info )
switch( state )
{
case 0:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 8 ) || ( info.src.charCodeAt( pos ) >= 10 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || info.src.charCodeAt( pos ) == 59 || ( info.src.charCodeAt( pos ) >= 63 && info.src.charCodeAt( pos ) <= 64 ) || ( info.src.charCodeAt( pos ) >= 66 && info.src.charCodeAt( pos ) <= 77 ) || ( info.src.charCodeAt( pos ) >= 80 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 8 ) || ( info.src.charCodeAt( pos ) >= 10 && info.src.charCodeAt( pos ) <= 31 ) || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || info.src.charCodeAt( pos ) == 59 || ( info.src.charCodeAt( pos ) >= 63 && info.src.charCodeAt( pos ) <= 64 ) || ( info.src.charCodeAt( pos ) >= 66 && info.src.charCodeAt( pos ) <= 77 ) || ( info.src.charCodeAt( pos ) >= 80 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 9 ) state = 2;
else if( info.src.charCodeAt( pos ) == 40 ) state = 3;
else if( info.src.charCodeAt( pos ) == 41 ) state = 4;
else if( info.src.charCodeAt( pos ) == 60 || info.src.charCodeAt( pos ) == 62 ) state = 5;
else if( info.src.charCodeAt( pos ) == 34 ) state = 11;
else if( info.src.charCodeAt( pos ) == 33 ) state = 11;
else if( info.src.charCodeAt( pos ) == 79 ) state = 12;
else if( info.src.charCodeAt( pos ) == 32 ) state = 13;
else if( info.src.charCodeAt( pos ) == 61 ) state = 14;
else if( info.src.charCodeAt( pos ) == 65 ) state = 18;
else if( info.src.charCodeAt( pos ) == 78 ) state = 19;
else if( info.src.charCodeAt( pos ) == 34 ) state = 15;
else if( info.src.charCodeAt( pos ) == 65 ) state = 19;
else if( info.src.charCodeAt( pos ) == 78 ) state = 20;
else state = -1;
break;
......@@ -183,9 +184,7 @@ switch( state )
break;
case 11:
if( info.src.charCodeAt( pos ) == 34 ) state = 7;
else if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 33 ) || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 91 ) || ( info.src.charCodeAt( pos ) >= 93 && info.src.charCodeAt( pos ) <= 254 ) ) state = 11;
else if( info.src.charCodeAt( pos ) == 92 ) state = 15;
if( info.src.charCodeAt( pos ) == 61 ) state = 14;
else state = -1;
break;
......@@ -211,7 +210,9 @@ switch( state )
break;
case 15:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 254 ) ) state = 11;
if( info.src.charCodeAt( pos ) == 34 ) state = 7;
else if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 33 ) || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 91 ) || ( info.src.charCodeAt( pos ) >= 93 && info.src.charCodeAt( pos ) <= 254 ) ) state = 15;
else if( info.src.charCodeAt( pos ) == 92 ) state = 17;
else state = -1;
break;
......@@ -225,6 +226,11 @@ switch( state )
break;
case 17:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 254 ) ) state = 15;
else state = -1;
break;
case 18:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 83 ) || ( info.src.charCodeAt( pos ) >= 85 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else if( info.src.charCodeAt( pos ) == 84 ) state = 10;
......@@ -233,7 +239,7 @@ switch( state )
match_pos = pos;
break;
case 18:
case 19:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 77 ) || ( info.src.charCodeAt( pos ) >= 79 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else if( info.src.charCodeAt( pos ) == 78 ) state = 16;
......@@ -242,10 +248,10 @@ switch( state )
match_pos = pos;
break;
case 19:
case 20:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 78 ) || ( info.src.charCodeAt( pos ) >= 80 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else if( info.src.charCodeAt( pos ) == 79 ) state = 17;
else if( info.src.charCodeAt( pos ) == 79 ) state = 18;
else state = -1;
match = 10;
match_pos = pos;
......@@ -755,7 +761,7 @@ var query_class_dict = {};
* @param {String} spec.key The metadata key
* @param {String} spec.value The value of the metadata to compare
*/
function ComplexQuery(spec) {
function ComplexQuery(spec, key_schema) {
Query.call(this);
/**
......@@ -777,7 +783,12 @@ function ComplexQuery(spec) {
* @optional
*/
this.query_list = spec.query_list || [];
this.query_list = this.query_list.map(QueryFactory.create);
/*jslint unparam: true*/
this.query_list = this.query_list.map(
// decorate the map to avoid sending the index as key_schema argument
function (o, i) { return QueryFactory.create(o, key_schema); }
);
/*jslint unparam: false*/
}
inherits(ComplexQuery, Query);
......@@ -1070,7 +1081,7 @@ function QueryFactory() {
* of a Query
* @return {Query} A Query object
*/
QueryFactory.create = function (object) {
QueryFactory.create = function (object, key_schema) {
if (object === "") {
return new Query();
}
......@@ -1079,7 +1090,7 @@ QueryFactory.create = function (object) {
}
if (typeof (object || {}).type === "string" &&
query_class_dict[object.type]) {
return new query_class_dict[object.type](object);
return new query_class_dict[object.type](object, key_schema);
}
throw new TypeError("QueryFactory.create(): " +
"Argument 1 is not a search text or a parsable object");
......@@ -1114,6 +1125,36 @@ _export("objectToSearchText", objectToSearchText);
/*global Query: true, inherits: true, query_class_dict: true, _export: true,
convertStringToRegExp: true */
var checkKeySchema = function (key_schema) {
var prop;
if (key_schema !== undefined) {
if (typeof key_schema !== 'object') {
throw new TypeError("SimpleQuery().create(): " +
"key_schema is not of type 'object'");
}
// key_set is mandatory
if (key_schema.key_set === undefined) {
throw new TypeError("SimpleQuery().create(): " +
"key_schema has no 'key_set' property");
}
for (prop in key_schema) {
if (key_schema.hasOwnProperty(prop)) {
switch (prop) {
case 'key_set':
case 'cast_lookup':
case 'match_lookup':
break;
default:
throw new TypeError("SimpleQuery().create(): " +
"key_schema has unknown property '" + prop + "'");
}
}
}
}
};
/**
* The SimpleQuery inherits from Query, and compares one metadata value
*
......@@ -1124,9 +1165,13 @@ _export("objectToSearchText", objectToSearchText);
* @param {String} spec.key The metadata key
* @param {String} spec.value The value of the metadata to compare
*/
function SimpleQuery(spec) {
function SimpleQuery(spec, key_schema) {
Query.call(this);
checkKeySchema(key_schema);
this._key_schema = key_schema || {};
/**
* Operator to use to compare object values
*
......@@ -1156,11 +1201,81 @@ function SimpleQuery(spec) {
}
inherits(SimpleQuery, Query);
var checkKey = function (key) {
var prop;
if (key.read_from === undefined) {
throw new TypeError("Custom key is missing the read_from property");
}
for (prop in key) {
if (key.hasOwnProperty(prop)) {
switch (prop) {
case 'read_from':
case 'cast_to':
case 'equal_match':
break;
default:
throw new TypeError("Custom key has unknown property '" +
prop + "'");
}
}
}
};
/**
* #crossLink "Query/match:method"
*/
SimpleQuery.prototype.match = function (item, wildcard_character) {
return this[this.operator](item[this.key], this.value, wildcard_character);
var object_value = null,
equal_match = null,
cast_to = null,
matchMethod = null,
value = null,
key = this.key;
matchMethod = this[this.operator];
if (this._key_schema.key_set && this._key_schema.key_set[key] !== undefined) {
key = this._key_schema.key_set[key];
}
if (typeof key === 'object') {
checkKey(key);
object_value = item[key.read_from];
equal_match = key.equal_match;
// equal_match can be a string
if (typeof equal_match === 'string') {
// XXX raise error if equal_match not in match_lookup
equal_match = this._key_schema.match_lookup[equal_match];
}
// equal_match overrides the default '=' operator
if (equal_match !== undefined) {
matchMethod = (this.operator === '=') ? equal_match : matchMethod;
}
value = this.value;
cast_to = key.cast_to;
if (cast_to) {
// cast_to can be a string
if (typeof cast_to === 'string') {
// XXX raise error if cast_to not in cast_lookup
cast_to = this._key_schema.cast_lookup[cast_to];
}
value = cast_to(value);
object_value = cast_to(object_value);
}
} else {
object_value = item[key];
value = this.value;
}
return matchMethod(object_value, value, wildcard_character);
};
/**
......@@ -1200,7 +1315,7 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
if (typeof value === 'object' && value.hasOwnProperty('content')) {
value = value.content;
}
if (comparison_value === undefined) {
......@@ -1212,6 +1327,9 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
if (value === undefined) {
return false;
}
if (value.cmp !== undefined) {
return value.cmp(comparison_value) === 0;
}
if (
convertStringToRegExp(
comparison_value.toString(),
......@@ -1241,7 +1359,7 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
if (typeof value === 'object' && value.hasOwnProperty('content')) {
value = value.content;
}
if (comparison_value === undefined) {
......@@ -1253,6 +1371,9 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
if (value === undefined) {
return true;
}
if (value.cmp !== undefined) {
return value.cmp(comparison_value) !== 0;
}
if (
convertStringToRegExp(
comparison_value.toString(),
......@@ -1279,9 +1400,15 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
if (typeof value === 'object' && value.hasOwnProperty('content')) {
value = value.content;
}
if (value === undefined || comparison_value === undefined) {
return false;
}
if (value.cmp !== undefined) {
return value.cmp(comparison_value) < 0;
}
return value < comparison_value;
};
......@@ -1300,9 +1427,15 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
if (typeof value === 'object' && value.hasOwnProperty('content')) {
value = value.content;
}
if (value === undefined || comparison_value === undefined) {
return false;
}
if (value.cmp !== undefined) {
return value.cmp(comparison_value) <= 0;
}
return value <= comparison_value;
};
......@@ -1321,9 +1454,15 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
if (typeof value === 'object' && value.hasOwnProperty('content')) {
value = value.content;
}
if (value === undefined || comparison_value === undefined) {
return false;
}
if (value.cmp !== undefined) {
return value.cmp(comparison_value) > 0;
}
return value > comparison_value;
};
......@@ -1342,9 +1481,15 @@ SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
if (typeof value === 'object' && value.hasOwnProperty('content')) {
value = value.content;
}
if (value === undefined || comparison_value === undefined) {
return false;
}
if (value.cmp !== undefined) {
return value.cmp(comparison_value) >= 0;
}
return value >= comparison_value;
};
......
......@@ -50,6 +50,7 @@ constants.http_status_text = {
"204": "No Content",
"205": "Reset Content",
"206": "Partial Content",
"304": "Not Modified",
"400": "Bad Request",
"401": "Unauthorized",
"402": "Payment Required",
......@@ -83,6 +84,7 @@ constants.http_status_text = {
"No Content": "No Content",
"Reset Content": "Reset Content",
"Partial Content": "Partial Content",
"Not Modified": "Not Modified",
"Bad Request": "Bad Request",
"Unauthorized": "Unauthorized",
"Payment Required": "Payment Required",
......@@ -115,6 +117,7 @@ constants.http_status_text = {
"no_content": "No Content",
"reset_content": "Reset Content",
"partial_content": "Partial Content",
"not_modified": "Not Modified",
"bad_request": "Bad Request",
"unauthorized": "Unauthorized",
"payment_required": "Payment Required",
......@@ -159,6 +162,7 @@ constants.http_status = {
"204": 204,
"205": 205,
"206": 206,
"304": 304,
"400": 400,
"401": 401,
"402": 402,
......@@ -192,6 +196,7 @@ constants.http_status = {
"No Content": 204,
"Reset Content": 205,
"Partial Content": 206,
"Not Modified": 304,
"Bad Request": 400,
"Unauthorized": 401,
"Payment Required": 402,
......@@ -224,6 +229,7 @@ constants.http_status = {
"no_content": 204,
"reset_content": 205,
"partial_content": 206,
"not_modified": 304,
"bad_request": 400,
"unauthorized": 401,
"payment_required": 402,
......@@ -268,6 +274,7 @@ constants.http_action = {
"204": "success",
"205": "success",
"206": "success",
"304": "success",
"400": "error",
"401": "error",
"402": "error",
......@@ -301,6 +308,7 @@ constants.http_action = {
"No Content": "success",
"Reset Content": "success",
"Partial Content": "success",
"Not Modified": "success",
"Bad Request": "error",
"Unauthorized": "error",
"Payment Required": "error",
......@@ -333,6 +341,7 @@ constants.http_action = {
"no_content": "success",
"reset_content": "success",
"partial_content": "success",
"not_modified": "success",
"bad_request": "error",
"unauthorized": "error",
"payment_required": "error",
......
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