jungles-data
v2.0.0
Published
Test your jungles-data layer with this tool
Downloads
3
Readme
Jungles Data
If you are thinking of creating your own data layer for jungles you can use this module to test it.
var data = require('your-dal');
var test = require('jungles-data');
test(data);
You need mocha and should to run the test.
mocha test.js -r should
API
Find
var result = data.find(<query object>); // Info query object at bottom
result.many(function (response) {
// Always called
// response: Array (can be empty)
});
result.one(function (response) {
// called when there is atleast one result
// { name, path, sort, ..data.. }
});
result.empty(function () {
// called when result is empty
});
result.error(function (error) {
// error
});
Remove
var result = data.remove(<query object>);
result.success(function () { });
result.error(function (error) { });
Create
var result = data.save({ name: 'products', order: 0 });
var result = data.save({ parent: '/products', name: 'snowboard', order: 0 });
result.success(function (instance) { });
result.error(function (error) { });
Result
[
{ name: 'products', path: '/products', sort: [0] },
{ name: 'snowboard', path: '/products/snowboard', sort: [0, 0] }
]
Update
var result = data.update({ path: '/products/snowboard', name: 'skateboard', order: 1 });
result.success(function (instance) { });
result.error(function (error) { });
Result
[
{ name: 'products', path: '/products', sort: [0] },
{ name: 'skateboard', path: '/products/skateboard', sort: [0, 1] }
]
Tree
var result = data.tree(<query object>);
result.success(function (tree) { });
result.error(function (error) { });
Structure
{
id: 1,
name: 'snowboard',
path: '/snowboard',
type: 'product',
sort: [0],
children: [
{
id: 2,
name: 'tags',
path: '/snowboard/tags',
type: 'tags',
sort: [0, 0],
children: [
{
id: 3,
name: 'red',
path: '/snowboard/tags/red',
type: 'tag',
sort: [0, 0, 0]
}
]
}
]
}
Query object
{ id: 5}
{ path: /.*/ }
{ path: '.*' }
{ path: /.*/, id: 5 }