'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (_ref) {
var client = _ref.client,
filterQuery = _ref.filterQuery,
mustContain = _ref.mustContain,
busy = _ref.busy,
encodeQueryAsString = _ref.encodeQueryAsString;
return {
listCollections: function listCollections() {
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var expected = ['text', 'limit', 'offset', 'sort', 'sortdir'];
var params = filterQuery.apply(undefined, [query].concat(expected));
return client._.get('/collection', { params: params });
},
createCollection: function createCollection(collection) {
var expected = ['name', 'description', 'public'];
var params = filterQuery.apply(undefined, [collection].concat(expected));
var _mustContain = mustContain.apply(undefined, [params].concat(expected)),
missingKeys = _mustContain.missingKeys,
promise = _mustContain.promise;
return missingKeys ? promise : busy(client._.post('/collection' + encodeQueryAsString(params)));
},
deleteCollection: function deleteCollection(id) {
return busy(client._.delete('/collection/' + id));
},
getCollection: function getCollection(id) {
return busy(client._.get('/collection/' + id));
},
editCollection: function editCollection() {
var collection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var expected = ['name', 'description'];
var params = filterQuery.apply(undefined, [collection].concat(expected));
var _mustContain2 = mustContain(collection, '_id'),
missingKeys = _mustContain2.missingKeys,
promise = _mustContain2.promise;
return missingKeys ? promise : busy(client._.put('/collection/' + collection._id + encodeQueryAsString(params)));
},
getCollectionAccess: function getCollectionAccess(id) {
return busy(client._.get('/collection/' + id + '/access'));
},
editCollectionAccess: function editCollectionAccess(collection) {
var expected = ['access', 'public'];
var params = filterQuery.apply(undefined, [collection].concat(expected));
var _mustContain3 = mustContain(collection, '_id'),
missingKeys = _mustContain3.missingKeys,
promise = _mustContain3.promise;
return missingKeys ? promise : busy(client._.put('/collection/' + collection._id + '/access' + encodeQueryAsString(params)));
}
};
};
|