Commit 167105f4 authored by Vincent Bechu's avatar Vincent Bechu Committed by Vincent Bechu

[Query] move key_schema from SimpleQuery to Query

parent a0194082
...@@ -158,6 +158,35 @@ ...@@ -158,6 +158,35 @@
return list; return list;
} }
function checkKeySchema(key_schema) {
var prop;
if (key_schema !== undefined) {
if (typeof key_schema !== 'object') {
throw new TypeError("Query().create(): " +
"key_schema is not of type 'object'");
}
// key_set is mandatory
if (key_schema.key_set === undefined) {
throw new TypeError("Query().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("Query().create(): " +
"key_schema has unknown property '" + prop + "'");
}
}
}
}
}
/** /**
* The query to use to filter a list of objects. * The query to use to filter a list of objects.
* This is an abstract class. * This is an abstract class.
...@@ -165,7 +194,10 @@ ...@@ -165,7 +194,10 @@
* @class Query * @class Query
* @constructor * @constructor
*/ */
function Query() { function Query(key_schema) {
checkKeySchema(key_schema);
this._key_schema = key_schema || {};
/** /**
* Called before parsing the query. Must be overridden! * Called before parsing the query. Must be overridden!
...@@ -609,35 +641,6 @@ ...@@ -609,35 +641,6 @@
throw new TypeError("This object is not a query"); throw new TypeError("This object is not a query");
} }
function checkKeySchema(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 * The SimpleQuery inherits from Query, and compares one metadata value
* *
...@@ -649,11 +652,7 @@ ...@@ -649,11 +652,7 @@
* @param {String} spec.value The value of the metadata to compare * @param {String} spec.value The value of the metadata to compare
*/ */
function SimpleQuery(spec, key_schema) { function SimpleQuery(spec, key_schema) {
Query.call(this); Query.call(this, key_schema);
checkKeySchema(key_schema);
this._key_schema = key_schema || {};
/** /**
* Operator to use to compare object values * Operator to use to compare object values
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
} catch (e) { } catch (e) {
equal(e.name, 'TypeError', 'wrong exception type'); equal(e.name, 'TypeError', 'wrong exception type');
equal(e.message, equal(e.message,
"SimpleQuery().create(): key_schema is not of type 'object'", "Query().create(): key_schema is not of type 'object'",
'wrong exception message'); 'wrong exception message');
} }
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
} catch (e) { } catch (e) {
equal(e.name, 'TypeError', 'wrong exception type'); equal(e.name, 'TypeError', 'wrong exception type');
equal(e.message, equal(e.message,
"SimpleQuery().create(): key_schema has no 'key_set' property", "Query().create(): key_schema has no 'key_set' property",
'wrong exception message'); 'wrong exception message');
} }
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
} catch (e) { } catch (e) {
equal(e.name, 'TypeError', 'wrong exception type'); equal(e.name, 'TypeError', 'wrong exception type');
equal(e.message, equal(e.message,
"SimpleQuery().create(): key_schema has unknown property 'foobar'", "Query().create(): key_schema has unknown property 'foobar'",
'wrong exception message'); 'wrong exception message');
} }
......
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