Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Hardik Juneja
jio
Commits
c76af5ed
Commit
c76af5ed
authored
Dec 23, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom keys: respect naming conventions
parent
749d779e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
94 deletions
+94
-94
src/queries/core/simplequery.js
src/queries/core/simplequery.js
+33
-33
test/queries/key-schema.tests.js
test/queries/key-schema.tests.js
+20
-20
test/queries/key-typechecks.tests.js
test/queries/key-typechecks.tests.js
+6
-6
test/queries/keys.tests.js
test/queries/keys.tests.js
+31
-31
test/queries/localstorage-keys.tests.js
test/queries/localstorage-keys.tests.js
+4
-4
No files found.
src/queries/core/simplequery.js
View file @
c76af5ed
...
@@ -10,17 +10,17 @@ var checkKeySchema = function (key_schema) {
...
@@ -10,17 +10,17 @@ var checkKeySchema = function (key_schema) {
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
"
key_schema is not of type 'object'
"
);
"
key_schema is not of type 'object'
"
);
}
}
// key
s
is mandatory
// key
_set
is mandatory
if
(
key_schema
.
key
s
===
undefined
)
{
if
(
key_schema
.
key
_set
===
undefined
)
{
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
"
key_schema has no 'key
s
' property
"
);
"
key_schema has no 'key
_set
' property
"
);
}
}
for
(
prop
in
key_schema
)
{
for
(
prop
in
key_schema
)
{
if
(
key_schema
.
hasOwnProperty
(
prop
))
{
if
(
key_schema
.
hasOwnProperty
(
prop
))
{
switch
(
prop
)
{
switch
(
prop
)
{
case
'
key
s
'
:
case
'
key
_set
'
:
case
'
types
'
:
case
'
cast_lookup
'
:
case
'
comparators
'
:
case
'
match_lookup
'
:
break
;
break
;
default
:
default
:
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
...
@@ -83,16 +83,16 @@ inherits(SimpleQuery, Query);
...
@@ -83,16 +83,16 @@ inherits(SimpleQuery, Query);
var
checkKey
=
function
(
key
)
{
var
checkKey
=
function
(
key
)
{
var
prop
;
var
prop
;
if
(
key
.
read
F
rom
===
undefined
)
{
if
(
key
.
read
_f
rom
===
undefined
)
{
throw
new
TypeError
(
"
Custom key is missing the read
F
rom property
"
);
throw
new
TypeError
(
"
Custom key is missing the read
_f
rom property
"
);
}
}
for
(
prop
in
key
)
{
for
(
prop
in
key
)
{
if
(
key
.
hasOwnProperty
(
prop
))
{
if
(
key
.
hasOwnProperty
(
prop
))
{
switch
(
prop
)
{
switch
(
prop
)
{
case
'
read
F
rom
'
:
case
'
read
_f
rom
'
:
case
'
cast
T
o
'
:
case
'
cast
_t
o
'
:
case
'
default
M
atch
'
:
case
'
default
_m
atch
'
:
break
;
break
;
default
:
default
:
throw
new
TypeError
(
"
Custom key has unknown property '
"
+
throw
new
TypeError
(
"
Custom key has unknown property '
"
+
...
@@ -108,50 +108,50 @@ var checkKey = function (key) {
...
@@ -108,50 +108,50 @@ var checkKey = function (key) {
*/
*/
SimpleQuery
.
prototype
.
match
=
function
(
item
,
wildcard_character
)
{
SimpleQuery
.
prototype
.
match
=
function
(
item
,
wildcard_character
)
{
var
object_value
=
null
,
var
object_value
=
null
,
default
M
atch
=
null
,
default
_m
atch
=
null
,
cast
T
o
=
null
,
cast
_t
o
=
null
,
matchMethod
=
null
,
matchMethod
=
null
,
value
=
null
,
value
=
null
,
key
=
this
.
key
;
key
=
this
.
key
;
matchMethod
=
this
[
this
.
operator
];
matchMethod
=
this
[
this
.
operator
];
if
(
this
.
_key_schema
.
key
s
&&
this
.
_key_schema
.
keys
[
key
]
!==
undefined
)
{
if
(
this
.
_key_schema
.
key
_set
&&
this
.
_key_schema
.
key_set
[
key
]
!==
undefined
)
{
key
=
this
.
_key_schema
.
key
s
[
key
];
key
=
this
.
_key_schema
.
key
_set
[
key
];
}
}
if
(
typeof
key
===
'
object
'
)
{
if
(
typeof
key
===
'
object
'
)
{
checkKey
(
key
);
checkKey
(
key
);
object_value
=
item
[
key
.
read
F
rom
];
object_value
=
item
[
key
.
read
_f
rom
];
// default
M
atch overrides the default '=' operator
// default
_m
atch overrides the default '=' operator
default
Match
=
key
.
defaultM
atch
;
default
_match
=
key
.
default_m
atch
;
// default
M
atch can be a string
// default
_m
atch can be a string
if
(
typeof
default
M
atch
===
'
string
'
)
{
if
(
typeof
default
_m
atch
===
'
string
'
)
{
// XXX raise error if default
Match not in comparators
// XXX raise error if default
_match not in match_lookup
default
Match
=
this
.
_key_schema
.
comparators
[
defaultM
atch
];
default
_match
=
this
.
_key_schema
.
match_lookup
[
default_m
atch
];
}
}
// default
M
atch overrides the default '=' operator
// default
_m
atch overrides the default '=' operator
matchMethod
=
(
default
M
atch
||
matchMethod
);
matchMethod
=
(
default
_m
atch
||
matchMethod
);
// but an explicit operator: key overrides
DefaultM
atch
// but an explicit operator: key overrides
default_m
atch
if
(
this
.
_spec
&&
this
.
_spec
.
operator
)
{
if
(
this
.
_spec
&&
this
.
_spec
.
operator
)
{
matchMethod
=
this
[
this
.
operator
];
matchMethod
=
this
[
this
.
operator
];
}
}
value
=
this
.
value
;
value
=
this
.
value
;
cast
To
=
key
.
castT
o
;
cast
_to
=
key
.
cast_t
o
;
if
(
cast
T
o
)
{
if
(
cast
_t
o
)
{
// cast
T
o can be a string
// cast
_t
o can be a string
if
(
typeof
cast
T
o
===
'
string
'
)
{
if
(
typeof
cast
_t
o
===
'
string
'
)
{
// XXX raise error if cast
To not in types
// XXX raise error if cast
_to not in cast_lookup
cast
To
=
this
.
_key_schema
.
types
[
castT
o
];
cast
_to
=
this
.
_key_schema
.
cast_lookup
[
cast_t
o
];
}
}
value
=
cast
T
o
(
value
);
value
=
cast
_t
o
(
value
);
object_value
=
cast
T
o
(
object_value
);
object_value
=
cast
_t
o
(
object_value
);
}
}
}
else
{
}
else
{
object_value
=
item
[
key
];
object_value
=
item
[
key
];
...
...
test/queries/key-schema.tests.js
View file @
c76af5ed
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
/*jslint unparam: true*/
/*jslint unparam: true*/
var
key_schema
=
{
var
key_schema
=
{
types
:
{
cast_lookup
:
{
dateType
:
function
(
obj
)
{
dateType
:
function
(
obj
)
{
if
(
Object
.
prototype
.
toString
.
call
(
obj
)
===
'
[object Date]
'
)
{
if
(
Object
.
prototype
.
toString
.
call
(
obj
)
===
'
[object Date]
'
)
{
// no need to clone
// no need to clone
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
}
}
},
},
comparators
:
{
match_lookup
:
{
sameDay
:
function
(
a
,
b
)
{
sameDay
:
function
(
a
,
b
)
{
return
(
return
(
(
a
.
getFullYear
()
===
b
.
getFullYear
())
&&
(
a
.
getFullYear
()
===
b
.
getFullYear
())
&&
...
@@ -55,32 +55,32 @@
...
@@ -55,32 +55,32 @@
equalState
:
translationEqualityMatcher
({
'
ouvert
'
:
'
open
'
})
equalState
:
translationEqualityMatcher
({
'
ouvert
'
:
'
open
'
})
},
},
key
s
:
{
key
_set
:
{
case_insensitive_identifier
:
{
case_insensitive_identifier
:
{
read
F
rom
:
'
identifier
'
,
read
_f
rom
:
'
identifier
'
,
default
M
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
default
_m
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
// XXX do this with a regexp and wildcard support
// XXX do this with a regexp and wildcard support
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
}
}
},
},
date_day
:
{
date_day
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
'
dateType
'
,
cast
_t
o
:
'
dateType
'
,
default
M
atch
:
'
sameDay
'
default
_m
atch
:
'
sameDay
'
},
},
date_month
:
{
date_month
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
'
dateType
'
,
cast
_t
o
:
'
dateType
'
,
default
M
atch
:
'
sameMonth
'
default
_m
atch
:
'
sameMonth
'
},
},
date_year
:
{
date_year
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
'
dateType
'
,
cast
_t
o
:
'
dateType
'
,
default
M
atch
:
'
sameYear
'
default
_m
atch
:
'
sameYear
'
},
},
translated_state
:
{
translated_state
:
{
read
F
rom
:
'
state
'
,
read
_f
rom
:
'
state
'
,
default
M
atch
:
'
equalState
'
default
_m
atch
:
'
equalState
'
}
}
}
}
};
};
...
@@ -176,7 +176,7 @@
...
@@ -176,7 +176,7 @@
{
'
identifier
'
:
'
100
'
,
'
number
'
:
'
100
'
}
{
'
identifier
'
:
'
100
'
,
'
number
'
:
'
100
'
}
];
];
},
key_schema
=
{
},
key_schema
=
{
types
:
{
cast_lookup
:
{
intType
:
function
(
value
)
{
intType
:
function
(
value
)
{
if
(
typeof
value
===
'
string
'
)
{
if
(
typeof
value
===
'
string
'
)
{
return
parseInt
(
value
,
10
);
return
parseInt
(
value
,
10
);
...
@@ -184,10 +184,10 @@
...
@@ -184,10 +184,10 @@
return
value
;
return
value
;
}
}
},
},
key
s
:
{
key
_set
:
{
number
:
{
number
:
{
read
F
rom
:
'
number
'
,
read
_f
rom
:
'
number
'
,
cast
T
o
:
'
intType
'
cast
_t
o
:
'
intType
'
}
}
}
}
};
};
...
...
test/queries/key-typechecks.tests.js
View file @
c76af5ed
...
@@ -60,16 +60,16 @@
...
@@ -60,16 +60,16 @@
try
{
try
{
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
},
{});
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
},
{});
ok
(
false
,
'
key_schema.key
s
is not checked
'
);
ok
(
false
,
'
key_schema.key
_set
is not checked
'
);
}
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
s
' property
"
,
"
SimpleQuery().create(): key_schema has no 'key
_set
' property
"
,
'
wrong exception message
'
);
'
wrong exception message
'
);
}
}
try
{
try
{
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
},
{
key
s
:
{},
foobar
:
{}});
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
},
{
key
_set
:
{},
foobar
:
{}});
ok
(
false
,
'
unknown key_schema properties are not checked
'
);
ok
(
false
,
'
unknown key_schema properties are not checked
'
);
}
catch
(
e
)
{
}
catch
(
e
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
...
@@ -92,11 +92,11 @@
...
@@ -92,11 +92,11 @@
key
:
{},
key
:
{},
value
:
'
a
'
value
:
'
a
'
}).
exec
(
doc_list
);
}).
exec
(
doc_list
);
ok
(
false
,
'
key.read
F
rom is not checked
'
);
ok
(
false
,
'
key.read
_f
rom is not checked
'
);
}
catch
(
e
)
{
}
catch
(
e
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
message
,
equal
(
e
.
message
,
"
Custom key is missing the read
F
rom property
"
,
"
Custom key is missing the read
_f
rom property
"
,
'
wrong exception message
'
);
'
wrong exception message
'
);
}
}
...
@@ -104,7 +104,7 @@
...
@@ -104,7 +104,7 @@
complex_queries
.
QueryFactory
.
create
({
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
type
:
'
simple
'
,
key
:
{
key
:
{
read
F
rom
:
'
identifier
'
,
read
_f
rom
:
'
identifier
'
,
foobar
:
''
foobar
:
''
},
},
value
:
'
a
'
value
:
'
a
'
...
...
test/queries/keys.tests.js
View file @
c76af5ed
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
module
(
'
Custom Key Queries
'
);
module
(
'
Custom Key Queries
'
);
test
(
'
Simple Key with read
F
rom
'
,
function
()
{
test
(
'
Simple Key with read
_f
rom
'
,
function
()
{
/*jslint unparam: true*/
/*jslint unparam: true*/
var
doc_list
,
docList
=
function
()
{
var
doc_list
,
docList
=
function
()
{
return
[
return
[
...
@@ -27,11 +27,11 @@
...
@@ -27,11 +27,11 @@
];
];
},
keys
=
{
},
keys
=
{
title
:
{
title
:
{
read
F
rom
:
'
identifier
'
read
_f
rom
:
'
identifier
'
},
},
case_insensitive_identifier
:
{
case_insensitive_identifier
:
{
read
F
rom
:
'
identifier
'
,
read
_f
rom
:
'
identifier
'
,
default
M
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
default
_m
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
}
}
}
}
...
@@ -103,19 +103,19 @@
...
@@ -103,19 +103,19 @@
var
keys
=
{
var
keys
=
{
day
:
{
day
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
dateCast
,
cast
_t
o
:
dateCast
,
default
M
atch
:
sameDay
default
_m
atch
:
sameDay
},
},
month
:
{
month
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
dateCast
,
cast
_t
o
:
dateCast
,
default
M
atch
:
sameMonth
default
_m
atch
:
sameMonth
},
},
year
:
{
year
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
dateCast
,
cast
_t
o
:
dateCast
,
default
M
atch
:
sameYear
default
_m
atch
:
sameYear
}
}
};
};
...
@@ -173,8 +173,8 @@
...
@@ -173,8 +173,8 @@
];
];
},
keys
=
{
},
keys
=
{
mydate
:
{
mydate
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
dateCast
cast
_t
o
:
dateCast
}
}
};
};
...
@@ -250,7 +250,7 @@
...
@@ -250,7 +250,7 @@
});
});
test
(
'
Simple Key with both default
M
atch and operator attributes
'
,
function
()
{
test
(
'
Simple Key with both default
_m
atch and operator attributes
'
,
function
()
{
var
doc_list
,
docList
=
function
()
{
var
doc_list
,
docList
=
function
()
{
return
[
return
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
...
@@ -259,9 +259,9 @@
...
@@ -259,9 +259,9 @@
];
];
},
keys
=
{
},
keys
=
{
mydate
:
{
mydate
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
dateCast
,
cast
_t
o
:
dateCast
,
default
M
atch
:
function
alwaysTrue
()
{
return
true
;
}
default
_m
atch
:
function
alwaysTrue
()
{
return
true
;
}
}
}
};
};
...
@@ -315,8 +315,8 @@
...
@@ -315,8 +315,8 @@
complex_queries
.
QueryFactory
.
create
({
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
type
:
'
simple
'
,
key
:
{
key
:
{
read
F
rom
:
'
number
'
,
read
_f
rom
:
'
number
'
,
cast
T
o
:
intType
cast
_t
o
:
intType
},
},
operator
:
'
>
'
,
operator
:
'
>
'
,
value
:
'
19
'
value
:
'
19
'
...
@@ -329,8 +329,8 @@
...
@@ -329,8 +329,8 @@
complex_queries
.
QueryFactory
.
create
({
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
type
:
'
simple
'
,
key
:
{
key
:
{
read
F
rom
:
'
number
'
,
read
_f
rom
:
'
number
'
,
cast
T
o
:
intType
cast
_t
o
:
intType
},
},
operator
:
'
<
'
,
operator
:
'
<
'
,
value
:
'
19
'
value
:
'
19
'
...
@@ -346,16 +346,16 @@
...
@@ -346,16 +346,16 @@
query_list
:
[{
query_list
:
[{
type
:
'
simple
'
,
type
:
'
simple
'
,
key
:
{
key
:
{
read
F
rom
:
'
number
'
,
read
_f
rom
:
'
number
'
,
cast
T
o
:
intType
cast
_t
o
:
intType
},
},
operator
:
'
<
'
,
operator
:
'
<
'
,
value
:
'
19
'
value
:
'
19
'
},
{
},
{
type
:
'
simple
'
,
type
:
'
simple
'
,
key
:
{
key
:
{
read
F
rom
:
'
number
'
,
read
_f
rom
:
'
number
'
,
cast
T
o
:
intType
cast
_t
o
:
intType
},
},
operator
:
'
=
'
,
operator
:
'
=
'
,
value
:
'
19
'
value
:
'
19
'
...
@@ -387,8 +387,8 @@
...
@@ -387,8 +387,8 @@
equalState
=
translationEqualityMatcher
({
'
ouvert
'
:
'
open
'
}),
equalState
=
translationEqualityMatcher
({
'
ouvert
'
:
'
open
'
}),
keys
=
{
keys
=
{
translated_state
:
{
translated_state
:
{
read
F
rom
:
'
state
'
,
read
_f
rom
:
'
state
'
,
default
M
atch
:
equalState
default
_m
atch
:
equalState
}
}
};
};
...
@@ -479,8 +479,8 @@
...
@@ -479,8 +479,8 @@
];
];
},
keys
=
{
},
keys
=
{
identifier
:
{
identifier
:
{
read
F
rom
:
'
identifier
'
,
read
_f
rom
:
'
identifier
'
,
default
M
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
default
_m
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
// XXX todo: regexp & support wildcard_character
// XXX todo: regexp & support wildcard_character
return
accentFold
(
object_value
)
===
accentFold
(
value
);
return
accentFold
(
object_value
)
===
accentFold
(
value
);
}
}
...
...
test/queries/localstorage-keys.tests.js
View file @
c76af5ed
...
@@ -70,7 +70,7 @@
...
@@ -70,7 +70,7 @@
var
key_schema
=
{
var
key_schema
=
{
types
:
{
cast_lookup
:
{
dateType
:
function
(
obj
)
{
dateType
:
function
(
obj
)
{
if
(
Object
.
prototype
.
toString
.
call
(
obj
)
===
'
[object Date]
'
)
{
if
(
Object
.
prototype
.
toString
.
call
(
obj
)
===
'
[object Date]
'
)
{
// no need to clone
// no need to clone
...
@@ -79,10 +79,10 @@
...
@@ -79,10 +79,10 @@
return
new
Date
(
obj
);
return
new
Date
(
obj
);
}
}
},
},
key
s
:
{
key
_set
:
{
mydate
:
{
mydate
:
{
read
F
rom
:
'
date
'
,
read
_f
rom
:
'
date
'
,
cast
T
o
:
'
dateType
'
cast
_t
o
:
'
dateType
'
}
}
}
}
};
};
...
...
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