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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aurel
jio
Commits
fc92bad8
Commit
fc92bad8
authored
Jan 19, 2017
by
Vincent Bechu
Committed by
Aurel
Feb 23, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mappingstorage: add test and change way to add new mapping function
parent
d646889f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
336 additions
and
348 deletions
+336
-348
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+187
-139
test/jio.storage/mappingstorage.tests.js
test/jio.storage/mappingstorage.tests.js
+149
-209
No files found.
src/jio.storage/mappingstorage.js
View file @
fc92bad8
...
@@ -5,6 +5,116 @@
...
@@ -5,6 +5,116 @@
Query
)
{
Query
)
{
"
use strict
"
;
"
use strict
"
;
function
getSubIdEqualSubProperty
(
storage
,
value
,
key
)
{
var
query
;
query
=
new
SimpleQuery
({
key
:
key
,
value
:
value
,
type
:
"
simple
"
});
if
(
storage
.
_query
.
query
!==
undefined
)
{
query
=
new
ComplexQuery
({
operator
:
"
AND
"
,
query_list
:
[
query
,
storage
.
_query
.
query
],
type
:
"
complex
"
});
}
query
=
Query
.
objectToSearchText
(
query
);
return
storage
.
_sub_storage
.
allDocs
({
"
query
"
:
query
,
"
sort_on
"
:
storage
.
_query
.
sort_on
,
"
select_list
"
:
storage
.
_query
.
select_list
,
"
limit
"
:
storage
.
_query
.
limit
})
.
push
(
function
(
data
)
{
if
(
data
.
data
.
rows
.
length
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Can not find id
"
,
404
);
}
if
(
data
.
data
.
rows
.
length
>
1
)
{
throw
new
TypeError
(
"
id must be unique field:
"
+
key
+
"
, result:
"
+
data
.
data
.
rows
.
toString
());
}
return
data
.
data
.
rows
[
0
].
id
;
});
}
/*jslint unparam: true*/
var
mapping_function
=
{
"
equalSubProperty
"
:
{
"
mapToSubProperty
"
:
function
(
property
,
sub_doc
,
doc
,
args
,
id
)
{
sub_doc
[
args
]
=
doc
[
property
];
return
args
;
},
"
mapToMainProperty
"
:
function
(
property
,
sub_doc
,
doc
,
args
,
sub_id
)
{
if
(
sub_doc
.
hasOwnProperty
(
args
))
{
doc
[
property
]
=
sub_doc
[
args
];
}
return
args
;
},
"
mapToSubId
"
:
function
(
storage
,
doc
,
id
,
args
)
{
if
(
doc
!==
undefined
)
{
if
(
storage
.
_property_for_sub_id
&&
doc
.
hasOwnProperty
(
storage
.
_property_for_sub_id
))
{
return
doc
[
storage
.
_property_for_sub_id
];
}
if
(
doc
.
hasOwnProperty
(
args
))
{
return
doc
[
args
];
}
}
return
getSubIdEqualSubProperty
(
storage
,
id
,
storage
.
_map_id
[
1
]);
},
"
mapToId
"
:
function
(
storage
,
sub_doc
,
sub_id
,
args
)
{
return
sub_doc
[
args
];
}
},
"
equalValue
"
:
{
"
mapToSubProperty
"
:
function
(
property
,
sub_doc
,
doc
,
args
)
{
sub_doc
[
property
]
=
args
;
return
property
;
},
"
mapToMainProperty
"
:
function
(
property
)
{
return
property
;
}
},
"
ignore
"
:
{
"
mapToSubProperty
"
:
function
()
{
return
false
;
},
"
mapToMainProperty
"
:
function
(
property
)
{
return
property
;
}
},
"
equalSubId
"
:
{
"
mapToSubProperty
"
:
function
()
{
return
false
;
},
"
mapToMainProperty
"
:
function
(
property
,
sub_doc
,
doc
,
args
,
sub_id
)
{
doc
[
property
]
=
sub_id
;
return
property
;
},
"
mapToSubId
"
:
function
(
storage
,
doc
,
id
,
args
)
{
return
id
;
},
"
mapToId
"
:
function
(
storage
,
sub_doc
,
sub_id
)
{
return
sub_id
;
}
},
"
keep
"
:
{
"
mapToSubProperty
"
:
function
(
property
,
sub_doc
,
doc
)
{
sub_doc
[
property
]
=
doc
[
property
];
return
property
;
},
"
mapToMainProperty
"
:
function
(
property
,
sub_doc
,
doc
)
{
doc
[
property
]
=
sub_doc
[
property
];
return
property
;
}
}
};
/*jslint unparam: false*/
function
initializeQueryAndDefaultMapping
(
storage
)
{
function
initializeQueryAndDefaultMapping
(
storage
)
{
var
property
,
query_list
=
[];
var
property
,
query_list
=
[];
for
(
property
in
storage
.
_mapping_dict
)
{
for
(
property
in
storage
.
_mapping_dict
)
{
...
@@ -47,14 +157,14 @@
...
@@ -47,14 +157,14 @@
}
}
function
MappingStorage
(
spec
)
{
function
MappingStorage
(
spec
)
{
this
.
_mapping_dict
=
spec
.
mapping_dict
||
{};
this
.
_mapping_dict
=
spec
.
property
||
{};
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
this
.
_map_all_property
=
spec
.
map_all_property
!==
undefined
?
this
.
_map_all_property
=
spec
.
map_all_property
!==
undefined
?
spec
.
map_all_property
:
true
;
spec
.
map_all_property
:
true
;
this
.
_attachment_mapping_dict
=
spec
.
attachment
_mapping_dict
||
{};
this
.
_attachment_mapping_dict
=
spec
.
attachment
||
{};
this
.
_query
=
spec
.
query
||
{};
this
.
_query
=
spec
.
query
||
{};
this
.
_map_id
=
spec
.
map_id
;
this
.
_map_id
=
spec
.
id
||
[
"
equalSubId
"
]
;
this
.
_id_mapped
=
(
spec
.
map_id
!==
undefined
)
?
spec
.
map_
id
[
1
]
:
false
;
this
.
_id_mapped
=
(
spec
.
id
!==
undefined
)
?
spec
.
id
[
1
]
:
false
;
if
(
this
.
_query
.
query
!==
undefined
)
{
if
(
this
.
_query
.
query
!==
undefined
)
{
this
.
_query
.
query
=
QueryFactory
.
create
(
this
.
_query
.
query
);
this
.
_query
.
query
=
QueryFactory
.
create
(
this
.
_query
.
query
);
...
@@ -78,113 +188,42 @@
...
@@ -78,113 +188,42 @@
}
}
function
getSubStorageId
(
storage
,
id
,
doc
)
{
function
getSubStorageId
(
storage
,
id
,
doc
)
{
var
query
;
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
if
(
storage
.
_property_for_sub_id
!==
undefined
&&
var
map_info
=
storage
.
_map_id
||
[
"
equalSubId
"
];
doc
!==
undefined
&&
if
(
storage
.
_property_for_sub_id
&&
doc
!==
undefined
&&
doc
[
storage
.
_property_for_sub_id
]
!==
undefined
)
{
doc
.
hasOwnProperty
(
storage
.
_property_for_sub_id
)
)
{
return
doc
[
storage
.
_property_for_sub_id
];
return
doc
[
storage
.
_property_for_sub_id
];
}
}
if
(
!
storage
.
_id_mapped
)
{
return
mapping_function
[
map_info
[
0
]].
mapToSubId
(
return
id
;
storage
,
}
doc
,
if
(
storage
.
_map_id
[
0
]
===
"
equalSubProperty
"
)
{
id
,
query
=
new
SimpleQuery
({
map_info
[
1
]
key
:
storage
.
_map_id
[
1
],
value
:
id
,
type
:
"
simple
"
});
if
(
storage
.
_query
.
query
!==
undefined
)
{
query
=
new
ComplexQuery
({
operator
:
"
AND
"
,
query_list
:
[
query
,
storage
.
_query
.
query
],
type
:
"
complex
"
});
}
query
=
Query
.
objectToSearchText
(
query
);
return
storage
.
_sub_storage
.
allDocs
({
"
query
"
:
query
,
"
sort_on
"
:
storage
.
_query
.
sort_on
,
"
select_list
"
:
storage
.
_query
.
select_list
,
"
limit
"
:
storage
.
_query
.
limit
})
.
push
(
function
(
data
)
{
if
(
data
.
data
.
rows
.
length
===
0
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Can not find id
"
,
404
);
}
if
(
data
.
data
.
rows
.
length
>
1
)
{
throw
new
TypeError
(
"
id must be unique field:
"
+
id
+
"
, result:
"
+
data
.
data
.
rows
.
toString
());
}
return
data
.
data
.
rows
[
0
].
id
;
});
}
throw
new
jIO
.
util
.
jIOError
(
"
Unsuported option:
"
+
storage
.
_mapping_dict
.
id
,
400
);
);
});
});
}
}
function
mapToSubProperty
(
storage
,
property
,
sub_doc
,
doc
)
{
function
mapToSubProperty
(
storage
,
property
,
sub_doc
,
doc
,
id
)
{
var
mapping_function
,
parameter
;
var
mapping_info
=
storage
.
_mapping_dict
[
property
]
||
[
"
keep
"
];
if
(
storage
.
_mapping_dict
[
property
]
!==
undefined
)
{
return
mapping_function
[
mapping_info
[
0
]].
mapToSubProperty
(
mapping_function
=
storage
.
_mapping_dict
[
property
][
0
];
property
,
parameter
=
storage
.
_mapping_dict
[
property
][
1
];
sub_doc
,
if
(
mapping_function
===
"
equalSubProperty
"
)
{
doc
,
sub_doc
[
parameter
]
=
doc
[
property
];
mapping_info
[
1
],
return
parameter
;
id
}
if
(
mapping_function
===
"
equalValue
"
)
{
sub_doc
[
property
]
=
parameter
;
return
property
;
}
if
(
mapping_function
===
"
ignore
"
||
mapping_function
===
"
equalSubId
"
)
{
return
false
;
}
}
if
(
!
storage
.
_map_all_property
)
{
return
false
;
}
if
(
storage
.
_map_all_property
)
{
sub_doc
[
property
]
=
doc
[
property
];
return
property
;
}
throw
new
jIO
.
util
.
jIOError
(
"
Unsuported option(s):
"
+
storage
.
_mapping_dict
[
property
],
400
);
);
}
}
function
mapToMainProperty
(
storage
,
property
,
sub_doc
,
doc
)
{
function
mapToMainProperty
(
storage
,
property
,
sub_doc
,
doc
,
sub_id
)
{
var
mapping_function
,
parameter
;
var
mapping_info
=
storage
.
_mapping_dict
[
property
]
||
[
"
keep
"
];
if
(
storage
.
_mapping_dict
[
property
]
!==
undefined
)
{
return
mapping_function
[
mapping_info
[
0
]].
mapToMainProperty
(
mapping_function
=
storage
.
_mapping_dict
[
property
][
0
];
property
,
parameter
=
storage
.
_mapping_dict
[
property
][
1
];
sub_doc
,
if
(
mapping_function
===
"
equalSubProperty
"
)
{
doc
,
if
(
sub_doc
.
hasOwnProperty
(
parameter
))
{
mapping_info
[
1
],
doc
[
property
]
=
sub_doc
[
parameter
];
sub_id
}
);
return
parameter
;
}
if
(
mapping_function
===
"
equalValue
"
)
{
return
property
;
}
if
(
mapping_function
===
"
ignore
"
)
{
return
property
;
}
}
if
(
storage
.
_map_all_property
)
{
if
(
sub_doc
.
hasOwnProperty
(
property
))
{
doc
[
property
]
=
sub_doc
[
property
];
}
return
property
;
}
return
false
;
}
}
function
mapToMainDocument
(
storage
,
sub_doc
,
sub_id
)
{
function
mapToMainDocument
(
storage
,
sub_doc
,
sub_id
)
{
...
@@ -193,7 +232,13 @@
...
@@ -193,7 +232,13 @@
property_list
=
[
storage
.
_id_mapped
];
property_list
=
[
storage
.
_id_mapped
];
for
(
property
in
storage
.
_mapping_dict
)
{
for
(
property
in
storage
.
_mapping_dict
)
{
if
(
storage
.
_mapping_dict
.
hasOwnProperty
(
property
))
{
if
(
storage
.
_mapping_dict
.
hasOwnProperty
(
property
))
{
property_list
.
push
(
mapToMainProperty
(
storage
,
property
,
sub_doc
,
doc
));
property_list
.
push
(
mapToMainProperty
(
storage
,
property
,
sub_doc
,
doc
,
sub_id
));
}
}
}
}
if
(
storage
.
_map_all_property
)
{
if
(
storage
.
_map_all_property
)
{
...
@@ -205,9 +250,8 @@
...
@@ -205,9 +250,8 @@
}
}
}
}
}
}
if
(
storage
.
_property_for_sub_id
!==
undefined
&&
if
(
storage
.
_map_for_sub_storage_id
!==
undefined
)
{
sub_id
!==
undefined
)
{
doc
[
storage
.
_map_for_sub_storage_id
]
=
sub_id
;
doc
[
storage
.
_property_for_sub_id
]
=
sub_id
;
}
}
return
doc
;
return
doc
;
}
}
...
@@ -217,7 +261,7 @@
...
@@ -217,7 +261,7 @@
for
(
property
in
doc
)
{
for
(
property
in
doc
)
{
if
(
doc
.
hasOwnProperty
(
property
))
{
if
(
doc
.
hasOwnProperty
(
property
))
{
mapToSubProperty
(
storage
,
property
,
sub_doc
,
doc
);
mapToSubProperty
(
storage
,
property
,
sub_doc
,
doc
,
id
);
}
}
}
}
for
(
property
in
storage
.
_default_mapping
)
{
for
(
property
in
storage
.
_default_mapping
)
{
...
@@ -225,36 +269,36 @@
...
@@ -225,36 +269,36 @@
sub_doc
[
property
]
=
storage
.
_default_mapping
[
property
];
sub_doc
[
property
]
=
storage
.
_default_mapping
[
property
];
}
}
}
}
if
(
storage
.
_
id_mapped
&&
id
!==
undefined
)
{
if
(
storage
.
_
map_id
[
0
]
===
"
equalSubProperty
"
&&
id
!==
undefined
)
{
sub_doc
[
storage
.
_
id_mapped
]
=
id
;
sub_doc
[
storage
.
_
map_id
[
1
]
]
=
id
;
}
}
return
sub_doc
;
return
sub_doc
;
}
}
function
handleAttachment
(
context
,
argument_list
,
method
)
{
function
handleAttachment
(
storage
,
argument_list
,
method
)
{
return
getSubStorageId
(
context
,
argument_list
[
0
])
return
getSubStorageId
(
storage
,
argument_list
[
0
])
.
push
(
function
(
sub_id
)
{
.
push
(
function
(
sub_id
)
{
argument_list
[
0
]
=
sub_id
;
argument_list
[
0
]
=
sub_id
;
argument_list
[
1
]
=
getAttachmentId
(
argument_list
[
1
]
=
getAttachmentId
(
context
,
storage
,
sub_id
,
sub_id
,
argument_list
[
1
],
argument_list
[
1
],
method
method
);
);
return
context
.
_sub_storage
[
method
+
"
Attachment
"
].
apply
(
return
storage
.
_sub_storage
[
method
+
"
Attachment
"
].
apply
(
context
.
_sub_storage
,
storage
.
_sub_storage
,
argument_list
argument_list
);
);
});
});
}
}
MappingStorage
.
prototype
.
get
=
function
(
id
)
{
MappingStorage
.
prototype
.
get
=
function
(
id
)
{
var
context
=
this
;
var
storage
=
this
;
return
getSubStorageId
(
this
,
id
)
return
getSubStorageId
(
this
,
id
)
.
push
(
function
(
sub_id
)
{
.
push
(
function
(
sub_id
)
{
return
context
.
_sub_storage
.
get
(
sub_id
)
return
storage
.
_sub_storage
.
get
(
sub_id
)
.
push
(
function
(
sub_doc
)
{
.
push
(
function
(
sub_doc
)
{
return
mapToMainDocument
(
context
,
sub_doc
,
sub_id
);
return
mapToMainDocument
(
storage
,
sub_doc
,
sub_id
);
});
});
});
});
};
};
...
@@ -278,15 +322,15 @@
...
@@ -278,15 +322,15 @@
};
};
MappingStorage
.
prototype
.
put
=
function
(
id
,
doc
)
{
MappingStorage
.
prototype
.
put
=
function
(
id
,
doc
)
{
var
context
=
this
,
var
storage
=
this
,
sub_doc
=
mapToSubstorageDocument
(
this
,
doc
,
id
);
sub_doc
=
mapToSubstorageDocument
(
this
,
doc
,
id
);
return
getSubStorageId
(
this
,
id
,
doc
)
return
getSubStorageId
(
this
,
id
,
doc
)
.
push
(
function
(
sub_id
)
{
.
push
(
function
(
sub_id
)
{
return
context
.
_sub_storage
.
put
(
sub_id
,
sub_doc
);
return
storage
.
_sub_storage
.
put
(
sub_id
,
sub_doc
);
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
)
{
return
context
.
_sub_storage
.
post
(
sub_doc
);
return
storage
.
_sub_storage
.
post
(
sub_doc
);
}
}
throw
error
;
throw
error
;
})
})
...
@@ -296,10 +340,10 @@
...
@@ -296,10 +340,10 @@
};
};
MappingStorage
.
prototype
.
remove
=
function
(
id
)
{
MappingStorage
.
prototype
.
remove
=
function
(
id
)
{
var
context
=
this
;
var
storage
=
this
;
return
getSubStorageId
(
this
,
id
)
return
getSubStorageId
(
this
,
id
)
.
push
(
function
(
sub_id
)
{
.
push
(
function
(
sub_id
)
{
return
context
.
_sub_storage
.
remove
(
sub_id
);
return
storage
.
_sub_storage
.
remove
(
sub_id
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
id
;
return
id
;
...
@@ -325,19 +369,19 @@
...
@@ -325,19 +369,19 @@
};
};
MappingStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
MappingStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
context
=
this
,
sub_id
;
var
storage
=
this
,
sub_id
;
return
getSubStorageId
(
context
,
id
)
return
getSubStorageId
(
storage
,
id
)
.
push
(
function
(
sub_id_result
)
{
.
push
(
function
(
sub_id_result
)
{
sub_id
=
sub_id_result
;
sub_id
=
sub_id_result
;
return
context
.
_sub_storage
.
allAttachments
(
sub_id
);
return
storage
.
_sub_storage
.
allAttachments
(
sub_id
);
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
attachment_id
,
var
attachment_id
,
attachments
=
{},
attachments
=
{},
mapping_dict
=
{};
mapping_dict
=
{};
for
(
attachment_id
in
context
.
_attachment_mapping_dict
)
{
for
(
attachment_id
in
storage
.
_attachment_mapping_dict
)
{
if
(
context
.
_attachment_mapping_dict
.
hasOwnProperty
(
attachment_id
))
{
if
(
storage
.
_attachment_mapping_dict
.
hasOwnProperty
(
attachment_id
))
{
mapping_dict
[
getAttachmentId
(
context
,
sub_id
,
attachment_id
,
"
get
"
)]
mapping_dict
[
getAttachmentId
(
storage
,
sub_id
,
attachment_id
,
"
get
"
)]
=
attachment_id
;
=
attachment_id
;
}
}
}
}
...
@@ -363,10 +407,10 @@
...
@@ -363,10 +407,10 @@
};
};
MappingStorage
.
prototype
.
bulk
=
function
(
id_list
)
{
MappingStorage
.
prototype
.
bulk
=
function
(
id_list
)
{
var
context
=
this
;
var
storage
=
this
;
function
mapId
(
parameter
)
{
function
mapId
(
parameter
)
{
return
getSubStorageId
(
context
,
parameter
.
parameter_list
[
0
])
return
getSubStorageId
(
storage
,
parameter
.
parameter_list
[
0
])
.
push
(
function
(
id
)
{
.
push
(
function
(
id
)
{
return
{
"
method
"
:
parameter
.
method
,
"
parameter_list
"
:
[
id
]};
return
{
"
method
"
:
parameter
.
method
,
"
parameter_list
"
:
[
id
]};
});
});
...
@@ -378,13 +422,13 @@
...
@@ -378,13 +422,13 @@
return
RSVP
.
all
(
promise_list
);
return
RSVP
.
all
(
promise_list
);
})
})
.
push
(
function
(
id_list_mapped
)
{
.
push
(
function
(
id_list_mapped
)
{
return
context
.
_sub_storage
.
bulk
(
id_list_mapped
);
return
storage
.
_sub_storage
.
bulk
(
id_list_mapped
);
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
mapped_result
=
[],
i
;
var
mapped_result
=
[],
i
;
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
mapped_result
.
push
(
mapToMainDocument
(
mapped_result
.
push
(
mapToMainDocument
(
context
,
storage
,
result
[
i
]
result
[
i
]
));
));
}
}
...
@@ -393,7 +437,7 @@
...
@@ -393,7 +437,7 @@
};
};
MappingStorage
.
prototype
.
buildQuery
=
function
(
option
)
{
MappingStorage
.
prototype
.
buildQuery
=
function
(
option
)
{
var
context
=
this
,
var
storage
=
this
,
i
,
i
,
query
,
query
,
property
,
property
,
...
@@ -412,7 +456,7 @@
...
@@ -412,7 +456,7 @@
one_query
.
query_list
=
query_list
;
one_query
.
query_list
=
query_list
;
return
one_query
;
return
one_query
;
}
}
key
=
mapToMainProperty
(
context
,
one_query
.
key
,
{},
{});
key
=
mapToMainProperty
(
storage
,
one_query
.
key
,
{},
{});
if
(
key
)
{
if
(
key
)
{
one_query
.
key
=
key
;
one_query
.
key
=
key
;
return
one_query
;
return
one_query
;
...
@@ -483,17 +527,21 @@
...
@@ -483,17 +527,21 @@
}
}
)
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
doc
;
var
sub_doc
,
map_info
=
storage
.
_map_id
||
[
"
equalSubId
"
]
;
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
result
.
data
.
total_rows
;
i
+=
1
)
{
doc
=
result
.
data
.
rows
[
i
].
value
;
sub_doc
=
result
.
data
.
rows
[
i
].
value
;
result
.
data
.
rows
[
i
].
id
=
mapping_function
[
map_info
[
0
]].
mapToId
(
storage
,
sub_doc
,
result
.
data
.
rows
[
i
].
id
,
map_info
[
1
]
);
result
.
data
.
rows
[
i
].
value
=
result
.
data
.
rows
[
i
].
value
=
mapToMainDocument
(
mapToMainDocument
(
context
,
storage
,
doc
sub_
doc
);
);
if
(
context
.
_id_mapped
)
{
result
.
data
.
rows
[
i
].
id
=
doc
[
context
.
_id_mapped
];
}
}
}
return
result
.
data
.
rows
;
return
result
.
data
.
rows
;
});
});
...
...
test/jio.storage/mappingstorage.tests.js
View file @
fc92bad8
...
@@ -46,9 +46,9 @@
...
@@ -46,9 +46,9 @@
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_all_property
:
false
,
map_all_property
:
false
,
query
:
{
"
query
"
:
'
foo: "bar"
'
},
query
:
{
"
query
"
:
'
foo: "bar"
'
},
attachment
_mapping_dict
:
{
"
foo
"
:
{
"
get
"
:
"
bar
"
}},
attachment
:
{
"
foo
"
:
{
"
get
"
:
"
bar
"
}},
mapping_dict
:
{
"
bar
"
:
[
"
equalSubProperty
"
,
"
foo
"
]},
property
:
{
"
bar
"
:
[
"
equalSubProperty
"
,
"
foo
"
]},
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -71,13 +71,13 @@
...
@@ -71,13 +71,13 @@
// mappingStorage.get
// mappingStorage.get
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.get
"
);
module
(
"
mappingStorage.get
"
);
test
(
"
get
called substorage get
"
,
function
()
{
test
(
"
called substorage get
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
mapping_dict
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
title
"
]},
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
title
"
]},
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -102,46 +102,14 @@
...
@@ -102,46 +102,14 @@
});
});
});
});
test
(
"
get with id mapped
"
,
function
()
{
test
(
"
with query and id equalSubProperty
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
mapping_dict
:
{
"
title
"
:
[
"
equalSubId
"
]},
sub_storage
:
{
type
:
"
mappingstorage2713
"
}
});
Storage2713
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
bar
"
,
"
get 2713 called
"
);
return
{};
};
jio
.
get
(
"
bar
"
)
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
bar
"
});
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get with id and props mapped
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
'
otherId
'
],
mapping_dict
:
{
query
:
{
"
query
"
:
'
otherTitle: "foo"
'
},
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -152,13 +120,17 @@
...
@@ -152,13 +120,17 @@
};
};
Storage2713
.
prototype
.
buildQuery
=
function
(
options
)
{
Storage2713
.
prototype
.
buildQuery
=
function
(
options
)
{
equal
(
options
.
query
,
'
otherId: "42"
'
,
"
allDoc 2713 called
"
);
equal
(
options
.
query
,
'
( otherId: "42" AND otherTitle: "foo" )
'
,
"
allDoc 2713 called
"
);
return
[{
id
:
"
2713
"
}];
return
[{
id
:
"
2713
"
}];
};
};
Storage2713
.
prototype
.
get
=
function
(
id
)
{
Storage2713
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
2713
"
,
"
get 2713 called
"
);
equal
(
id
,
"
2713
"
,
"
get 2713 called
"
);
return
{
"
otherT
itle
"
:
"
foo
"
};
return
{
"
t
itle
"
:
"
foo
"
};
};
};
jio
.
get
(
"
42
"
)
jio
.
get
(
"
42
"
)
...
@@ -174,17 +146,13 @@
...
@@ -174,17 +146,13 @@
});
});
});
});
test
(
"
get with id mapped and quer
y
"
,
function
()
{
test
(
"
with id equalSubPropert
y
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
query
:
{
"
query
"
:
'
otherTitle: "foo"
'
},
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
map_id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
mapping_dict
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -195,17 +163,13 @@
...
@@ -195,17 +163,13 @@
};
};
Storage2713
.
prototype
.
buildQuery
=
function
(
options
)
{
Storage2713
.
prototype
.
buildQuery
=
function
(
options
)
{
equal
(
equal
(
options
.
query
,
'
otherId: "42"
'
,
"
allDoc 2713 called
"
);
options
.
query
,
'
( otherId: "42" AND otherTitle: "foo" )
'
,
"
allDoc 2713 called
"
);
return
[{
id
:
"
2713
"
}];
return
[{
id
:
"
2713
"
}];
};
};
Storage2713
.
prototype
.
get
=
function
(
id
)
{
Storage2713
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
2713
"
,
"
get 2713 called
"
);
equal
(
id
,
"
2713
"
,
"
get 2713 called
"
);
return
{
"
otherT
itle
"
:
"
foo
"
};
return
{
"
t
itle
"
:
"
foo
"
};
};
};
jio
.
get
(
"
42
"
)
jio
.
get
(
"
42
"
)
...
@@ -221,15 +185,13 @@
...
@@ -221,15 +185,13 @@
});
});
});
});
test
(
"
get with not map_all_p
roperty
"
,
function
()
{
test
(
"
with prop equalSubP
roperty
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_all_property
:
false
,
property
:
{
map_id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
mapping_dict
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -237,25 +199,12 @@
...
@@ -237,25 +199,12 @@
}
}
});
});
Storage2713
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
Storage2713
.
prototype
.
buildQuery
=
function
(
options
)
{
equal
(
options
.
query
,
'
otherId: "42"
'
,
"
allDoc 2713 called
"
);
return
[{
id
:
"
2713
"
}];
};
Storage2713
.
prototype
.
get
=
function
(
id
)
{
Storage2713
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
2713
"
,
"
get 2713 called
"
);
equal
(
id
,
"
bar
"
,
"
get 2713 called
"
);
return
{
"
otherTitle
"
:
"
foo
"
,
"
foo
"
:
"
bar
"
};
return
{
otherTitle
:
"
foo
"
};
};
};
jio
.
get
(
"
42
"
)
jio
.
get
(
"
bar
"
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
"
title
"
:
"
foo
"
...
@@ -268,15 +217,13 @@
...
@@ -268,15 +217,13 @@
});
});
});
});
test
(
"
get with props equal
"
,
function
()
{
test
(
"
with prop equalSubId
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSubId
"
]},
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -284,13 +231,13 @@
...
@@ -284,13 +231,13 @@
Storage2713
.
prototype
.
get
=
function
(
id
)
{
Storage2713
.
prototype
.
get
=
function
(
id
)
{
equal
(
id
,
"
bar
"
,
"
get 2713 called
"
);
equal
(
id
,
"
bar
"
,
"
get 2713 called
"
);
return
{
otherTitle
:
"
foo
"
};
return
{};
};
};
jio
.
get
(
"
bar
"
)
jio
.
get
(
"
bar
"
)
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
"
title
"
:
"
bar
"
});
});
}).
push
(
undefined
,
function
(
error
)
{
}).
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
...
@@ -300,13 +247,14 @@
...
@@ -300,13 +247,14 @@
});
});
});
});
test
(
"
get with ignore
"
,
function
()
{
test
(
"
with prop ignore
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
ignore
"
]
"
title
"
:
[
"
ignore
"
]
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -337,13 +285,13 @@
...
@@ -337,13 +285,13 @@
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.put
"
);
module
(
"
mappingStorage.put
"
);
test
(
"
put with substorage put
"
,
function
()
{
test
(
"
substorage put called
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
title
"
]
"
title
"
:
[
"
equalSubProperty
"
,
"
title
"
]
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -369,27 +317,36 @@
...
@@ -369,27 +317,36 @@
});
});
});
});
test
(
"
put with default values
"
,
function
()
{
test
(
"
with id equalSubProperty
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
mapping_dict
:
{
"
title
"
:
[
"
equalValue
"
,
"
foobar
"
]}
,
id
:
[
"
equalSubProperty
"
,
"
otherId
"
]
,
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
});
});
Storage2713
.
prototype
.
p
ut
=
function
(
id
,
param
)
{
Storage2713
.
prototype
.
p
ost
=
function
(
doc
)
{
equal
(
id
,
"
bar
"
,
"
put 2713 called
"
);
deepEqual
(
doc
,
deepEqual
(
param
,
{
"
title
"
:
"
foobar
"
},
"
pu
t 2713 called
"
);
{
"
otherId
"
:
"
42
"
,
"
title
"
:
"
foo
"
},
"
pos
t 2713 called
"
);
return
id
;
return
"
bar
"
;
};
};
jio
.
put
(
"
bar
"
,
{})
Storage2713
.
prototype
.
buildQuery
=
function
(
option
)
{
equal
(
option
.
query
,
'
otherId: "42"
'
,
"
allDocs 2713 called
"
);
return
[];
};
Storage2713
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
equal
(
result
,
"
42
"
);
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
...
@@ -399,39 +356,61 @@
...
@@ -399,39 +356,61 @@
});
});
});
});
test
(
"
put with id and prop mappe
d
"
,
function
()
{
test
(
"
with id equalSubProperty and prop equalSubI
d
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSub
Property
"
,
"
otherTitle
"
]
"
title
"
:
[
"
equalSub
Id
"
]
},
},
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
});
});
Storage2713
.
prototype
.
p
ost
=
function
(
doc
)
{
Storage2713
.
prototype
.
p
ut
=
function
(
id
,
doc
)
{
deepEqual
(
doc
,
deepEqual
(
doc
,
{
"
otherId
"
:
"
42
"
,
"
otherTitle
"
:
"
foo
"
},
"
post 2713 called
"
);
{
"
otherId
"
:
"
42
"
},
"
post 2713 called
"
);
equal
(
id
,
"
bar
"
);
return
"
bar
"
;
return
"
bar
"
;
};
};
Storage2713
.
prototype
.
buildQuery
=
function
(
option
)
{
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
bar
"
})
equal
(
option
.
query
,
'
otherId: "42"
'
,
"
allDocs 2713 called
"
);
.
push
(
function
(
result
)
{
return
[];
equal
(
result
,
"
42
"
);
};
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
Storage2713
.
prototype
.
hasCapacity
=
function
()
{
test
(
"
with prop equalSubId
"
,
function
()
{
return
true
;
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
property
:
{
"
title
"
:
[
"
equalSubId
"
]},
sub_storage
:
{
type
:
"
mappingstorage2713
"
}
});
Storage2713
.
prototype
.
put
=
function
(
id
,
param
)
{
equal
(
id
,
"
2713
"
,
"
put 2713 called
"
);
deepEqual
(
param
,
{
"
foo
"
:
"
bar
"
},
"
put 2713 called
"
);
return
id
;
};
};
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
})
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
2713
"
,
"
foo
"
:
"
bar
"
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
equal
(
result
,
"
bar
"
);
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
...
@@ -441,31 +420,27 @@
...
@@ -441,31 +420,27 @@
});
});
});
});
test
(
"
put with id mapped
"
,
function
()
{
test
(
"
with prop equalSubProperty
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
subTitle
"
]},
mapping_dict
:
{
"
title
"
:
[
"
equalSubId
"
]
},
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
});
});
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
Storage2713
.
prototype
.
put
=
function
(
id
,
param
)
{
deepEqual
(
doc
,
equal
(
id
,
"
bar
"
,
"
put 2713 called
"
);
{
"
otherId
"
:
"
42
"
},
"
post 2713 called
"
);
deepEqual
(
param
,
{
"
subTitle
"
:
"
foo
"
},
"
put 2713 called
"
);
equal
(
id
,
"
bar
"
);
return
id
;
return
"
bar
"
;
};
};
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
bar
"
})
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
equal
(
result
,
"
bar
"
);
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
...
@@ -475,31 +450,27 @@
...
@@ -475,31 +450,27 @@
});
});
});
});
test
(
"
put with no map_all_property
"
,
function
()
{
test
(
"
with prop equalValues
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_all_property
:
false
,
property
:
{
"
title
"
:
[
"
equalValue
"
,
"
foobar
"
]},
mapping_dict
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
title
"
]
},
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
});
});
Storage2713
.
prototype
.
put
=
function
(
id
,
doc
)
{
Storage2713
.
prototype
.
put
=
function
(
id
,
param
)
{
deepEqual
(
doc
,
equal
(
id
,
"
bar
"
,
"
put 2713 called
"
);
{
"
title
"
:
"
foo
"
},
"
post 2713 called
"
);
deepEqual
(
param
,
{
"
title
"
:
"
foobar
"
},
"
put 2713 called
"
);
equal
(
id
,
"
42
"
,
"
put 2713 called
"
);
return
id
;
return
id
;
};
};
jio
.
put
(
"
42
"
,
{
"
title
"
:
"
foo
"
,
"
smth
"
:
"
bar
"
,
"
smth2
"
:
"
bar2
"
})
jio
.
put
(
"
bar
"
,
{
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
equal
(
result
,
"
bar
"
);
})
})
.
push
(
undefined
,
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
ok
(
false
,
error
);
...
@@ -514,7 +485,7 @@
...
@@ -514,7 +485,7 @@
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.remove
"
);
module
(
"
mappingStorage.remove
"
);
test
(
"
remove
with substorage remove
"
,
function
()
{
test
(
"
with substorage remove
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
...
@@ -542,13 +513,13 @@
...
@@ -542,13 +513,13 @@
});
});
});
});
test
(
"
remove
with id mapped
"
,
function
()
{
test
(
"
with id mapped
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -584,44 +555,13 @@
...
@@ -584,44 +555,13 @@
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.post
"
);
module
(
"
mappingStorage.post
"
);
test
(
"
post with mapped property
"
,
function
()
{
test
(
"
with id equalSubProperty, no id in doc
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
mapping_dict
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
sub_storage
:
{
type
:
"
mappingstorage2713
"
}
});
Storage2713
.
prototype
.
post
=
function
(
doc
)
{
deepEqual
(
doc
,
{
"
otherTitle
"
:
"
foo
"
},
"
remove 2713 called
"
);
return
"
42
"
;
};
jio
.
post
({
"
title
"
:
"
foo
"
})
.
push
(
function
(
result
)
{
equal
(
result
,
"
42
"
);
})
.
push
(
undefined
,
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
post with id mapped, no id in doc
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -641,13 +581,13 @@
...
@@ -641,13 +581,13 @@
});
});
});
});
test
(
"
post with id mapped an
d in doc
"
,
function
()
{
test
(
"
with id equalSubProperty and i
d in doc
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -670,13 +610,13 @@
...
@@ -670,13 +610,13 @@
});
});
});
});
test
(
"
post with sub_id mapped an
d in doc
"
,
function
()
{
test
(
"
with equalSubId mapped and i
d in doc
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
mapping_dict
:
{
"
otherId
"
:
[
"
equalSubId
"
]},
property
:
{
"
otherId
"
:
[
"
equalSubId
"
]},
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
}
}
...
@@ -704,7 +644,7 @@
...
@@ -704,7 +644,7 @@
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.putAttachment
"
);
module
(
"
mappingStorage.putAttachment
"
);
test
(
"
putAttachment use sub_storage one's
"
,
function
()
{
test
(
"
sub_storage putAttachment called
"
,
function
()
{
stop
();
stop
();
expect
(
4
);
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
...
@@ -734,13 +674,13 @@
...
@@ -734,13 +674,13 @@
});
});
});
});
test
(
"
putAttachment
with UriTemplate
"
,
function
()
{
test
(
"
with UriTemplate
"
,
function
()
{
stop
();
stop
();
expect
(
4
);
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
attachment
_mapping_dict
:
{
attachment
:
{
"
2713
"
:
{
"
put
"
:
{
"
uri_template
"
:
"
www.2713.foo/{id}
"
}}
"
2713
"
:
{
"
put
"
:
{
"
uri_template
"
:
"
www.2713.foo/{id}
"
}}
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -768,13 +708,13 @@
...
@@ -768,13 +708,13 @@
});
});
});
});
test
(
"
putAttachment with UriTemplate and id mapped
"
,
function
()
{
test
(
"
with UriTemplate and id equalSubProperty
"
,
function
()
{
stop
();
stop
();
expect
(
5
);
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
attachment
_mapping_dict
:
{
attachment
:
{
"
2713
"
:
{
"
put
"
:
{
"
uri_template
"
:
"
www.2713.foo/{id}
"
}}
"
2713
"
:
{
"
put
"
:
{
"
uri_template
"
:
"
www.2713.foo/{id}
"
}}
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -815,7 +755,7 @@
...
@@ -815,7 +755,7 @@
// mappingStorage.getAttachment
// mappingStorage.getAttachment
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.getAttachment
"
);
module
(
"
mappingStorage.getAttachment
"
);
test
(
"
getAttachment use sub_storage one's
"
,
function
()
{
test
(
"
sub_storage getAttachment called
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
...
@@ -843,13 +783,13 @@
...
@@ -843,13 +783,13 @@
});
});
});
});
test
(
"
getAttachment using
UriTemplate
"
,
function
()
{
test
(
"
with
UriTemplate
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
attachment
_mapping_dict
:
{
attachment
:
{
"
2713
"
:
{
"
get
"
:
{
"
uri_template
"
:
"
www.2713/{id}/ok.com
"
}}
"
2713
"
:
{
"
get
"
:
{
"
uri_template
"
:
"
www.2713/{id}/ok.com
"
}}
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -875,14 +815,14 @@
...
@@ -875,14 +815,14 @@
});
});
});
});
test
(
"
getAttachment
with UriTemplate and id mapped
"
,
function
()
{
test
(
"
with UriTemplate and id mapped
"
,
function
()
{
stop
();
stop
();
expect
(
4
);
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
attachment
_mapping_dict
:
{
attachment
:
{
"
2713
"
:
{
"
get
"
:
{
"
uri_template
"
:
"
www.2713.foo/{id}
"
}}
"
2713
"
:
{
"
get
"
:
{
"
uri_template
"
:
"
www.2713.foo/{id}
"
}}
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -922,7 +862,7 @@
...
@@ -922,7 +862,7 @@
// mappingStorage.removeAttachment
// mappingStorage.removeAttachment
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.removeAttachment
"
);
module
(
"
mappingStorage.removeAttachment
"
);
test
(
"
removeAttachment use sub_storage one's
"
,
function
()
{
test
(
"
sub_storage removeAttachment called
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
...
@@ -951,13 +891,13 @@
...
@@ -951,13 +891,13 @@
});
});
});
});
test
(
"
removeAttachment
use UriTemplate
"
,
function
()
{
test
(
"
with
use UriTemplate
"
,
function
()
{
stop
();
stop
();
expect
(
3
);
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
attachment
_mapping_dict
:
{
attachment
:
{
"
2713
"
:
{
"
remove
"
:
{
"
uri_template
"
:
"
www.2713/{id}.bar
"
}}
"
2713
"
:
{
"
remove
"
:
{
"
uri_template
"
:
"
www.2713/{id}.bar
"
}}
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -983,14 +923,14 @@
...
@@ -983,14 +923,14 @@
});
});
});
});
test
(
"
removeAttachment with UriTemplate and id mapped
"
,
function
()
{
test
(
"
with UriTemplate and id equalSubProperty
"
,
function
()
{
stop
();
stop
();
expect
(
4
);
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
attachment
_mapping_dict
:
{
attachment
:
{
"
2713
"
:
{
"
remove
"
:
{
"
uri_template
"
:
"
www.2713.foo/{id}
"
}}
"
2713
"
:
{
"
remove
"
:
{
"
uri_template
"
:
"
www.2713.foo/{id}
"
}}
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -1030,7 +970,7 @@
...
@@ -1030,7 +970,7 @@
// mappingStorage.allAttachments
// mappingStorage.allAttachments
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.allAttachments
"
);
module
(
"
mappingStorage.allAttachments
"
);
test
(
"
allAttachments use sub_storage one's
"
,
function
()
{
test
(
"
sub_storage allAttachments called
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
...
@@ -1058,13 +998,13 @@
...
@@ -1058,13 +998,13 @@
});
});
});
});
test
(
"
allAttachments use
UriTemplate
"
,
function
()
{
test
(
"
with
UriTemplate
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
attachment
_mapping_dict
:
{
attachment
:
{
"
2713
"
:
{
"
get
"
:
{
"
uri_template
"
:
"
www.2713.bar
"
}}
"
2713
"
:
{
"
get
"
:
{
"
uri_template
"
:
"
www.2713.bar
"
}}
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -1093,7 +1033,7 @@
...
@@ -1093,7 +1033,7 @@
// mappingStorage.allDocs
// mappingStorage.allDocs
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.buildQuery
"
);
module
(
"
mappingStorage.buildQuery
"
);
test
(
"
allDocs with complex query, with map_all_propert
y
"
,
function
()
{
test
(
"
with complex quer
y
"
,
function
()
{
stop
();
stop
();
expect
(
1
);
expect
(
1
);
...
@@ -1144,14 +1084,14 @@
...
@@ -1144,14 +1084,14 @@
});
});
});
});
test
(
"
allDocs with complex query, id and prop mapped
"
,
function
()
{
test
(
"
with complex query, id and prop equalSubProperty
"
,
function
()
{
stop
();
stop
();
expect
(
1
);
expect
(
1
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
],
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
],
"
smth
"
:
[
"
equalSubProperty
"
,
"
otherSmth
"
]
"
smth
"
:
[
"
equalSubProperty
"
,
"
otherSmth
"
]
},
},
...
@@ -1221,14 +1161,14 @@
...
@@ -1221,14 +1161,14 @@
});
});
});
});
test
(
"
allDocs without option, id and prop mapped
"
,
function
()
{
test
(
"
without option, id and prop equalSubProperty
"
,
function
()
{
stop
();
stop
();
expect
(
1
);
expect
(
1
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -1273,14 +1213,14 @@
...
@@ -1273,14 +1213,14 @@
});
});
});
});
test
(
"
allDocs id and prop mapped and map_all_p
roperty
"
,
function
()
{
test
(
"
with id and prop equalSubP
roperty
"
,
function
()
{
stop
();
stop
();
expect
(
1
);
expect
(
1
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -1328,15 +1268,15 @@
...
@@ -1328,15 +1268,15 @@
});
});
});
});
test
(
"
allDocs id and prop mapped
and query
"
,
function
()
{
test
(
"
with id and prop equalSubProperty
and query
"
,
function
()
{
stop
();
stop
();
expect
(
1
);
expect
(
1
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
query
:
{
"
query
"
:
'
otherId: "42"
'
},
query
:
{
"
query
"
:
'
otherId: "42"
'
},
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -1388,14 +1328,14 @@
...
@@ -1388,14 +1328,14 @@
// mappingStorage.bulk
// mappingStorage.bulk
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingstorage.bulk
"
);
module
(
"
mappingstorage.bulk
"
);
test
(
"
bulk with map_all_p
roperty
"
,
function
()
{
test
(
"
with id and prop equalSubP
roperty
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
var
jio
=
jIO
.
createJIO
({
type
:
"
mapping
"
,
type
:
"
mapping
"
,
map_
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
id
:
[
"
equalSubProperty
"
,
"
otherId
"
],
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
"
title
"
:
[
"
equalSubProperty
"
,
"
otherTitle
"
]
},
},
sub_storage
:
{
sub_storage
:
{
...
@@ -1475,7 +1415,7 @@
...
@@ -1475,7 +1415,7 @@
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
module
(
"
mappingStorage.repair
"
);
module
(
"
mappingStorage.repair
"
);
test
(
"
repair called substorage repair
"
,
function
()
{
test
(
"
substorage repair called
"
,
function
()
{
stop
();
stop
();
expect
(
2
);
expect
(
2
);
...
@@ -1484,7 +1424,7 @@
...
@@ -1484,7 +1424,7 @@
sub_storage
:
{
sub_storage
:
{
type
:
"
mappingstorage2713
"
type
:
"
mappingstorage2713
"
},
},
mapping_dict
:
{
property
:
{
"
title
"
:
[
"
equalSubProperty
"
,
"
title
"
]
"
title
"
:
[
"
equalSubProperty
"
,
"
title
"
]
}
}
});
});
...
...
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