Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Stefane Fermigier
jio
Commits
167105f4
Commit
167105f4
authored
Oct 09, 2017
by
Vincent Bechu
Committed by
Vincent Bechu
Oct 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Query] move key_schema from SimpleQuery to Query
parent
a0194082
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
38 deletions
+37
-38
src/queries/query.js
src/queries/query.js
+34
-35
test/queries/key-typechecks.tests.js
test/queries/key-typechecks.tests.js
+3
-3
No files found.
src/queries/query.js
View file @
167105f4
...
...
@@ -158,6 +158,35 @@
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.
* This is an abstract class.
...
...
@@ -165,7 +194,10 @@
* @class Query
* @constructor
*/
function
Query
()
{
function
Query
(
key_schema
)
{
checkKeySchema
(
key_schema
);
this
.
_key_schema
=
key_schema
||
{};
/**
* Called before parsing the query. Must be overridden!
...
...
@@ -609,35 +641,6 @@
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
*
...
...
@@ -649,11 +652,7 @@
* @param {String} spec.value The value of the metadata to compare
*/
function
SimpleQuery
(
spec
,
key_schema
)
{
Query
.
call
(
this
);
checkKeySchema
(
key_schema
);
this
.
_key_schema
=
key_schema
||
{};
Query
.
call
(
this
,
key_schema
);
/**
* Operator to use to compare object values
...
...
test/queries/key-typechecks.tests.js
View file @
167105f4
...
...
@@ -54,7 +54,7 @@
}
catch
(
e
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
message
,
"
Simple
Query().create(): key_schema is not of type 'object'
"
,
"
Query().create(): key_schema is not of type 'object'
"
,
'
wrong exception message
'
);
}
...
...
@@ -64,7 +64,7 @@
}
catch
(
e
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
message
,
"
Simple
Query().create(): key_schema has no 'key_set' property
"
,
"
Query().create(): key_schema has no 'key_set' property
"
,
'
wrong exception message
'
);
}
...
...
@@ -76,7 +76,7 @@
}
catch
(
e
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
message
,
"
Simple
Query().create(): key_schema has unknown property 'foobar'
"
,
"
Query().create(): key_schema has unknown property 'foobar'
"
,
'
wrong exception message
'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment