Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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-main
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
Hide 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) {
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
"
key_schema is not of type 'object'
"
);
}
// key
s
is mandatory
if
(
key_schema
.
key
s
===
undefined
)
{
// key
_set
is mandatory
if
(
key_schema
.
key
_set
===
undefined
)
{
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
"
key_schema has no 'key
s
' property
"
);
"
key_schema has no 'key
_set
' property
"
);
}
for
(
prop
in
key_schema
)
{
if
(
key_schema
.
hasOwnProperty
(
prop
))
{
switch
(
prop
)
{
case
'
key
s
'
:
case
'
types
'
:
case
'
comparators
'
:
case
'
key
_set
'
:
case
'
cast_lookup
'
:
case
'
match_lookup
'
:
break
;
default
:
throw
new
TypeError
(
"
SimpleQuery().create():
"
+
...
...
@@ -83,16 +83,16 @@ inherits(SimpleQuery, Query);
var
checkKey
=
function
(
key
)
{
var
prop
;
if
(
key
.
read
F
rom
===
undefined
)
{
throw
new
TypeError
(
"
Custom key is missing the read
F
rom property
"
);
if
(
key
.
read
_f
rom
===
undefined
)
{
throw
new
TypeError
(
"
Custom key is missing the read
_f
rom property
"
);
}
for
(
prop
in
key
)
{
if
(
key
.
hasOwnProperty
(
prop
))
{
switch
(
prop
)
{
case
'
read
F
rom
'
:
case
'
cast
T
o
'
:
case
'
default
M
atch
'
:
case
'
read
_f
rom
'
:
case
'
cast
_t
o
'
:
case
'
default
_m
atch
'
:
break
;
default
:
throw
new
TypeError
(
"
Custom key has unknown property '
"
+
...
...
@@ -108,50 +108,50 @@ var checkKey = function (key) {
*/
SimpleQuery
.
prototype
.
match
=
function
(
item
,
wildcard_character
)
{
var
object_value
=
null
,
default
M
atch
=
null
,
cast
T
o
=
null
,
default
_m
atch
=
null
,
cast
_t
o
=
null
,
matchMethod
=
null
,
value
=
null
,
key
=
this
.
key
;
matchMethod
=
this
[
this
.
operator
];
if
(
this
.
_key_schema
.
key
s
&&
this
.
_key_schema
.
keys
[
key
]
!==
undefined
)
{
key
=
this
.
_key_schema
.
key
s
[
key
];
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
F
rom
];
object_value
=
item
[
key
.
read
_f
rom
];
// default
M
atch overrides the default '=' operator
default
Match
=
key
.
defaultM
atch
;
// default
_m
atch overrides the default '=' operator
default
_match
=
key
.
default_m
atch
;
// default
M
atch can be a string
if
(
typeof
default
M
atch
===
'
string
'
)
{
// XXX raise error if default
Match not in comparators
default
Match
=
this
.
_key_schema
.
comparators
[
defaultM
atch
];
// default
_m
atch can be a string
if
(
typeof
default
_m
atch
===
'
string
'
)
{
// XXX raise error if default
_match not in match_lookup
default
_match
=
this
.
_key_schema
.
match_lookup
[
default_m
atch
];
}
// default
M
atch overrides the default '=' operator
matchMethod
=
(
default
M
atch
||
matchMethod
);
// default
_m
atch overrides the default '=' operator
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
)
{
matchMethod
=
this
[
this
.
operator
];
}
value
=
this
.
value
;
cast
To
=
key
.
castT
o
;
if
(
cast
T
o
)
{
// cast
T
o can be a string
if
(
typeof
cast
T
o
===
'
string
'
)
{
// XXX raise error if cast
To not in types
cast
To
=
this
.
_key_schema
.
types
[
castT
o
];
cast
_to
=
key
.
cast_t
o
;
if
(
cast
_t
o
)
{
// cast
_t
o can be a string
if
(
typeof
cast
_t
o
===
'
string
'
)
{
// XXX raise error if cast
_to not in cast_lookup
cast
_to
=
this
.
_key_schema
.
cast_lookup
[
cast_t
o
];
}
value
=
cast
T
o
(
value
);
object_value
=
cast
T
o
(
object_value
);
value
=
cast
_t
o
(
value
);
object_value
=
cast
_t
o
(
object_value
);
}
}
else
{
object_value
=
item
[
key
];
...
...
test/queries/key-schema.tests.js
View file @
c76af5ed
...
...
@@ -25,7 +25,7 @@
/*jslint unparam: true*/
var
key_schema
=
{
types
:
{
cast_lookup
:
{
dateType
:
function
(
obj
)
{
if
(
Object
.
prototype
.
toString
.
call
(
obj
)
===
'
[object Date]
'
)
{
// no need to clone
...
...
@@ -35,7 +35,7 @@
}
},
comparators
:
{
match_lookup
:
{
sameDay
:
function
(
a
,
b
)
{
return
(
(
a
.
getFullYear
()
===
b
.
getFullYear
())
&&
...
...
@@ -55,32 +55,32 @@
equalState
:
translationEqualityMatcher
({
'
ouvert
'
:
'
open
'
})
},
key
s
:
{
key
_set
:
{
case_insensitive_identifier
:
{
read
F
rom
:
'
identifier
'
,
default
M
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
read
_f
rom
:
'
identifier
'
,
default
_m
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
// XXX do this with a regexp and wildcard support
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
}
},
date_day
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
'
dateType
'
,
default
M
atch
:
'
sameDay
'
read
_f
rom
:
'
date
'
,
cast
_t
o
:
'
dateType
'
,
default
_m
atch
:
'
sameDay
'
},
date_month
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
'
dateType
'
,
default
M
atch
:
'
sameMonth
'
read
_f
rom
:
'
date
'
,
cast
_t
o
:
'
dateType
'
,
default
_m
atch
:
'
sameMonth
'
},
date_year
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
'
dateType
'
,
default
M
atch
:
'
sameYear
'
read
_f
rom
:
'
date
'
,
cast
_t
o
:
'
dateType
'
,
default
_m
atch
:
'
sameYear
'
},
translated_state
:
{
read
F
rom
:
'
state
'
,
default
M
atch
:
'
equalState
'
read
_f
rom
:
'
state
'
,
default
_m
atch
:
'
equalState
'
}
}
};
...
...
@@ -176,7 +176,7 @@
{
'
identifier
'
:
'
100
'
,
'
number
'
:
'
100
'
}
];
},
key_schema
=
{
types
:
{
cast_lookup
:
{
intType
:
function
(
value
)
{
if
(
typeof
value
===
'
string
'
)
{
return
parseInt
(
value
,
10
);
...
...
@@ -184,10 +184,10 @@
return
value
;
}
},
key
s
:
{
key
_set
:
{
number
:
{
read
F
rom
:
'
number
'
,
cast
T
o
:
'
intType
'
read
_f
rom
:
'
number
'
,
cast
_t
o
:
'
intType
'
}
}
};
...
...
test/queries/key-typechecks.tests.js
View file @
c76af5ed
...
...
@@ -60,16 +60,16 @@
try
{
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
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
message
,
"
SimpleQuery().create(): key_schema has no 'key
s
' property
"
,
"
SimpleQuery().create(): key_schema has no 'key
_set
' property
"
,
'
wrong exception message
'
);
}
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
'
);
}
catch
(
e
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
...
...
@@ -92,11 +92,11 @@
key
:
{},
value
:
'
a
'
}).
exec
(
doc_list
);
ok
(
false
,
'
key.read
F
rom is not checked
'
);
ok
(
false
,
'
key.read
_f
rom is not checked
'
);
}
catch
(
e
)
{
equal
(
e
.
name
,
'
TypeError
'
,
'
wrong exception type
'
);
equal
(
e
.
message
,
"
Custom key is missing the read
F
rom property
"
,
"
Custom key is missing the read
_f
rom property
"
,
'
wrong exception message
'
);
}
...
...
@@ -104,7 +104,7 @@
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
{
read
F
rom
:
'
identifier
'
,
read
_f
rom
:
'
identifier
'
,
foobar
:
''
},
value
:
'
a
'
...
...
test/queries/keys.tests.js
View file @
c76af5ed
...
...
@@ -17,7 +17,7 @@
module
(
'
Custom Key Queries
'
);
test
(
'
Simple Key with read
F
rom
'
,
function
()
{
test
(
'
Simple Key with read
_f
rom
'
,
function
()
{
/*jslint unparam: true*/
var
doc_list
,
docList
=
function
()
{
return
[
...
...
@@ -27,11 +27,11 @@
];
},
keys
=
{
title
:
{
read
F
rom
:
'
identifier
'
read
_f
rom
:
'
identifier
'
},
case_insensitive_identifier
:
{
read
F
rom
:
'
identifier
'
,
default
M
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
read
_f
rom
:
'
identifier
'
,
default
_m
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
}
}
...
...
@@ -103,19 +103,19 @@
var
keys
=
{
day
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
dateCast
,
default
M
atch
:
sameDay
read
_f
rom
:
'
date
'
,
cast
_t
o
:
dateCast
,
default
_m
atch
:
sameDay
},
month
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
dateCast
,
default
M
atch
:
sameMonth
read
_f
rom
:
'
date
'
,
cast
_t
o
:
dateCast
,
default
_m
atch
:
sameMonth
},
year
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
dateCast
,
default
M
atch
:
sameYear
read
_f
rom
:
'
date
'
,
cast
_t
o
:
dateCast
,
default
_m
atch
:
sameYear
}
};
...
...
@@ -173,8 +173,8 @@
];
},
keys
=
{
mydate
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
dateCast
read
_f
rom
:
'
date
'
,
cast
_t
o
:
dateCast
}
};
...
...
@@ -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
()
{
return
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
...
...
@@ -259,9 +259,9 @@
];
},
keys
=
{
mydate
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
dateCast
,
default
M
atch
:
function
alwaysTrue
()
{
return
true
;
}
read
_f
rom
:
'
date
'
,
cast
_t
o
:
dateCast
,
default
_m
atch
:
function
alwaysTrue
()
{
return
true
;
}
}
};
...
...
@@ -315,8 +315,8 @@
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
{
read
F
rom
:
'
number
'
,
cast
T
o
:
intType
read
_f
rom
:
'
number
'
,
cast
_t
o
:
intType
},
operator
:
'
>
'
,
value
:
'
19
'
...
...
@@ -329,8 +329,8 @@
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
{
read
F
rom
:
'
number
'
,
cast
T
o
:
intType
read
_f
rom
:
'
number
'
,
cast
_t
o
:
intType
},
operator
:
'
<
'
,
value
:
'
19
'
...
...
@@ -346,16 +346,16 @@
query_list
:
[{
type
:
'
simple
'
,
key
:
{
read
F
rom
:
'
number
'
,
cast
T
o
:
intType
read
_f
rom
:
'
number
'
,
cast
_t
o
:
intType
},
operator
:
'
<
'
,
value
:
'
19
'
},
{
type
:
'
simple
'
,
key
:
{
read
F
rom
:
'
number
'
,
cast
T
o
:
intType
read
_f
rom
:
'
number
'
,
cast
_t
o
:
intType
},
operator
:
'
=
'
,
value
:
'
19
'
...
...
@@ -387,8 +387,8 @@
equalState
=
translationEqualityMatcher
({
'
ouvert
'
:
'
open
'
}),
keys
=
{
translated_state
:
{
read
F
rom
:
'
state
'
,
default
M
atch
:
equalState
read
_f
rom
:
'
state
'
,
default
_m
atch
:
equalState
}
};
...
...
@@ -479,8 +479,8 @@
];
},
keys
=
{
identifier
:
{
read
F
rom
:
'
identifier
'
,
default
M
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
read
_f
rom
:
'
identifier
'
,
default
_m
atch
:
function
(
object_value
,
value
,
wildcard_character
)
{
// XXX todo: regexp & support wildcard_character
return
accentFold
(
object_value
)
===
accentFold
(
value
);
}
...
...
test/queries/localstorage-keys.tests.js
View file @
c76af5ed
...
...
@@ -70,7 +70,7 @@
var
key_schema
=
{
types
:
{
cast_lookup
:
{
dateType
:
function
(
obj
)
{
if
(
Object
.
prototype
.
toString
.
call
(
obj
)
===
'
[object Date]
'
)
{
// no need to clone
...
...
@@ -79,10 +79,10 @@
return
new
Date
(
obj
);
}
},
key
s
:
{
key
_set
:
{
mydate
:
{
read
F
rom
:
'
date
'
,
cast
T
o
:
'
dateType
'
read
_f
rom
:
'
date
'
,
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