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
17d394dd
Commit
17d394dd
authored
Dec 07, 2016
by
Hardik Juneja
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new type multiEqual for multimapping
parent
9bb5cdfc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
129 additions
and
2 deletions
+129
-2
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+37
-2
test/jio.storage/mappingstorage.tests.js
test/jio.storage/mappingstorage.tests.js
+92
-0
No files found.
src/jio.storage/mappingstorage.js
View file @
17d394dd
...
...
@@ -36,15 +36,24 @@
return
new_mapping_dict
;
}
if
(
_mapping_dict
[
key
].
multiEqual
!==
undefined
)
{
new_mapping_dict
=
{
multiEqualArray
:
_mapping_dict
[
key
].
multiEqual
,
match_value
:
key
};
return
new_mapping_dict
;
}
if
(
key
===
"
switch
"
)
{
//xx: assuming switch is just used in case of value
new_mapping_dict
[
'
switch
'
]
=
{};
new_mapping_dict
[
'
switch
'
].
regexps
=
[];
new_mapping_dict
[
'
switch
'
].
multiEqual
=
[];
for
(
new_key
in
_mapping_dict
[
'
switch
'
])
{
if
(
_mapping_dict
[
'
switch
'
].
hasOwnProperty
(
new_key
))
{
new_kv
=
inverseMappingDict
(
_mapping_dict
[
'
switch
'
],
new_key
);
new_key
=
Object
.
keys
(
new_kv
)[
0
];
if
(
new_key
===
"
regexp
"
)
{
if
(
new_key
===
"
regexp
"
||
new_key
===
"
multiEqualArray
"
)
{
new_mapping_dict
[
'
switch
'
].
regexps
.
push
(
new_kv
);
}
else
{
new_mapping_dict
[
'
switch
'
][
new_key
]
=
new_kv
[
new_key
];
...
...
@@ -181,10 +190,12 @@
});
}
function
mapProperty
(
_mapping_dict
,
key
,
value
,
for_value
)
{
function
mapProperty
(
_mapping_dict
,
key
,
value
,
for_value
,
isQuery
)
{
var
new_prop
,
i
,
k
,
regexp
,
equalityArray
,
new_mapping_dict
=
{},
mapped_kv
=
{};
...
...
@@ -248,6 +259,30 @@
return
mapped_kv
;
}
if
(
_mapping_dict
.
multiEqual
!==
undefined
)
{
if
(
_mapping_dict
.
multiEqual
&&
_mapping_dict
.
multiEqual
.
length
)
{
for
(
i
=
0
;
i
<
_mapping_dict
.
multiEqual
.
length
;
i
=
i
+
1
)
{
equalityArray
=
_mapping_dict
.
multiEqual
[
i
].
multiEqualArray
;
if
(
equalityArray
===
undefined
)
{
break
;
}
for
(
k
=
0
;
k
<
equalityArray
.
length
;
k
=
k
+
1
)
{
if
(
value
===
equalityArray
[
k
])
{
if
(
isQuery
===
true
)
{
isQuery
=
_mapping_dict
.
multiEqual
;
}
mapped_kv
.
key
=
key
;
mapped_kv
.
value
=
_mapping_dict
.
multiEqual
[
i
].
match_value
;
return
mapped_kv
;
}
}
}
}
mapped_kv
.
key
=
key
;
mapped_kv
.
value
=
_mapping_dict
.
default_value
;
return
mapped_kv
;
}
if
(
_mapping_dict
[
"
switch
"
]
!==
undefined
)
{
if
(
_mapping_dict
[
"
switch
"
].
hasOwnProperty
(
key
))
{
return
mapProperty
(
_mapping_dict
[
'
switch
'
][
key
],
key
,
value
,
true
);
...
...
test/jio.storage/mappingstorage.tests.js
View file @
17d394dd
...
...
@@ -474,6 +474,52 @@
});
});
test
(
"
get with prop, value mapped using multiEqual and switch
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
sub_storage
:
{
type
:
"
mappingstorage2713
"
},
mapping_dict
:
{
"
title
"
:
{
"
equal
"
:
"
someTitle
"
,
"
value
"
:
{
"
switch
"
:
{
"
foo
"
:
{
"
multiEqual
"
:
[
"
otherFoo
"
,
"
otherbar
"
,
"
otherkoo
"
],
"
default_value
"
:
"
otherFoo
"
},
"
bar
"
:
{
"
equal
"
:
"
otherBar
"
}
}
}
}
}
});
Storage2713
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
42
"
,
"
get 2713 called
"
);
return
{
"
someTitle
"
:
"
otherbar
"
,
"
smth
"
:
"
bar
"
};
};
jio
.
get
(
"
42
"
)
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
});
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get with map_all_property
"
,
function
()
{
stop
();
expect
(
3
);
...
...
@@ -911,6 +957,52 @@
start
();
});
});
test
(
"
get with prop, value mapped using multiEqual and switch
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
sub_storage
:
{
type
:
"
mappingstorage2713
"
},
mapping_dict
:
{
"
title
"
:
{
"
equal
"
:
"
someTitle
"
,
"
value
"
:
{
"
switch
"
:
{
"
foo
"
:
{
"
multiEqual
"
:
[
"
otherFoo
"
,
"
otherbar
"
,
"
otherkoo
"
],
"
default_value
"
:
"
otherFoo
"
},
"
bar
"
:
{
"
equal
"
:
"
otherBar
"
}
}
}
}
}
});
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
deepEqual
(
doc
,
{
"
someTitle
"
:
"
otherFoo
"
,
"
smth
"
:
"
bar
"
},
"
post 2713 called
"
);
equal
(
id
,
"
42
"
,
"
put 2713 called
"
);
return
id
;
};
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
})
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// mappingStorage.remove
/////////////////////////////////////////////////////////////////
...
...
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