Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var putPVar = function(ldb, key_prefix, query, val, callback){
query = ktypes.isNull(query) ? [] : query;
query = ktypes.isArray(query) ? query : [query];
// do this before toKeyPath b/c it will convert all parts to stings
var isArrayIndex = _.isInteger(query[0]) && query[0] >= 0;
var path = toKeyPath(query);
if(_.size(path) > 0){
var subkeyPrefix = key_prefix.concat(["value", path[0]]);
var subPath = _.tail(path);
ldb.get(key_prefix, function(err, oldRoot){
if(err && ! err.notFound){
callback(err);
return;
}
var ops = [];
var type = oldRoot && oldRoot.type;
if(type !== "Map" && type !== "Array"){
type = isArrayIndex ? "Array" : "Map";
}
function toPairs (v) {
if (ktypes.isArray(v)) {
var pairs = []
var i
for (i = 0; i < v.length; i++) {
pairs.push([i, v[i]])
}
return pairs
}
return _.toPairs(v)
}
var normalizeId = function (domain, id) {
if (domain !== 'ent' && domain !== 'app') {
return ktypes.toString(id)
}
if (_.has(id, 'key') && ktypes.isString(id.key)) {
return {
var_name: id.key,
query: ktypes.isArray(id.path)
? id.path
: [id.path]
}
}
return {
var_name: ktypes.toString(id),
query: []
}
}
var toKeyPath = function(path){
if(!ktypes.isArray(path)){
path = [path];
}
return _.map(path, function(key){
return ktypes.toString(key);
});
};
], async function (ctx, args) {
if (!_.has(args, 'rid')) {
throw new Error('engine:uninstallRuleset needs a rid string or array')
}
let picoId = picoArgOrCtxPico('uninstallRuleset', ctx, args)
picoId = await core.db.assertPicoID(picoId)
let ridIsString = ktypes.isString(args.rid)
if (!ridIsString && !ktypes.isArray(args.rid)) {
throw new TypeError('engine:uninstallRuleset was given ' + ktypes.toString(args.rid) + ' instead of a rid string or array')
}
if (ridIsString) {
await core.uninstallRuleset(picoId, args.rid)
return
}
let rids = _.uniq(args.rid)
for (let rid of rids) {
if (!ktypes.isString(rid)) {
throw new TypeError('engine:uninstallRuleset was given a rid array containing a non-string (' + ktypes.toString(rid) + ')')
}
}
for (let rid of rids) {
await core.uninstallRuleset(picoId, rid)