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.
srap/src/mutation-api/simulation.js

78 lines
1.8 KiB
JavaScript

"use strict";
const Promise = require("bluebird");
const chalk = require("chalk");
const util = require("util");
function logCall(methodName, args) {
console.log(`${chalk.bold.yellow.bgBlack(`${methodName} (simulated):`)} ${util.inspect(args, { colors: true, depth: null })}`);
}
module.exports = function (state) {
const queries = require("../queries")(state);
return function createSimulationMutationAPI({ tx, item, taskVersion }) {
return {
createItem: function (options) {
logCall("createItem", {
... options,
update: (options.update != null)
? options.update(item.data)
: undefined
});
},
renameItem: function (options) {
logCall("renameItem", {
... options
});
},
mergeItem: function (options) {
// FIXME: Visualize merges
logCall("createItem", {
... options
});
},
deleteItem: function (options) {
logCall("deleteItem", {
... options
});
},
createAlias: function (options) {
logCall("createAlias", {
... options
});
},
deleteAlias: function (from) {
logCall("deleteAlias", {
from: from
});
},
updateData: function (options) {
logCall("updateData", {
... options,
update: (options.update != null)
? options.update(item.data)
: undefined
});
},
updateMetadata: function (options) {
return Promise.try(() => {
return queries.getItem(tx, id);
}).then((item) => {
// FIXME: Visualize metadata update, actually merge with the correct thing
// MARKER: Expose taskResults as an object mapping instead of an array, somehow
logCall("updateMetadata", {
... options,
update: (options.update != null)
? options.update(item.data)
: undefined
});
});
},
expire: function (options) {
return queries.expire(tx, options);
}
};
};
};