You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const wrapValueAsOption = require("@validatem/wrap-value-as-option");
|
|
const required = require("@validatem/required");
|
|
const isString = require("@validatem/is-string");
|
|
const defaultTo = require("@validatem/default-to");
|
|
const validateOptions = require("@validatem/core/src/api/validate-options");
|
|
const isFunction = require("@validatem/is-function");
|
|
|
|
// FIXME: Remaining validators
|
|
|
|
module.exports = function wrapMutationAPI({ item, task }, api) {
|
|
return {
|
|
createItem: function (options) {
|
|
return api.createItem(options);
|
|
},
|
|
renameItem: function (_options) {
|
|
let options = validateOptions(arguments, [
|
|
wrapValueAsOption("to"), {
|
|
to: [ required, isString ],
|
|
from: [ defaultTo(item.id), isString ]
|
|
}
|
|
]);
|
|
|
|
return api.renameItem(options);
|
|
},
|
|
mergeItem: function (options) {
|
|
return api.mergeItem(options);
|
|
},
|
|
deleteItem: function (options = {}) {
|
|
return api.deleteItem(options);
|
|
},
|
|
createAlias: function (options) {
|
|
// TODO: Single-parameter variant?
|
|
return api.createAlias(options);
|
|
},
|
|
deleteAlias: function (from) {
|
|
// FIXME: options wrapper
|
|
return api.deleteAlias(from);
|
|
},
|
|
updateData: function (_options) {
|
|
let options = validateOptions(arguments, [
|
|
wrapValueAsOption("update"), {
|
|
id: [ defaultTo(item.id), isString ],
|
|
update: [ required, isFunction ]
|
|
}
|
|
]);
|
|
|
|
return api.updateData(options);
|
|
},
|
|
updateMetadata: function (_options) {
|
|
let options = validateOptions(arguments, [
|
|
wrapValueAsOption("update"), {
|
|
id: [ defaultTo(item.id), isString ],
|
|
taskName: [ defaultTo(task), isString ],
|
|
update: [ required, isFunction ]
|
|
}
|
|
]);
|
|
|
|
return api.updateMetadata(options);
|
|
},
|
|
expire: function (_options) {
|
|
let options = validateOptions(arguments, [
|
|
defaultTo({}), {
|
|
id: [ defaultTo(item.id), isString ],
|
|
taskName: [ defaultTo(task), isString ]
|
|
}
|
|
]);
|
|
|
|
return api.expire(options);
|
|
}
|
|
};
|
|
};
|