Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mergeWhereClause(args, where) {
if (getType(where) !== 'Object') {
return args;
}
// Access control is a where clause type
return {
...args,
where: {
...args.where,
...where,
},
};
},
return mapKeys(_query, field => {
if (getType(field) !== 'Object' || !field.where) {
return field;
}
// recurse on object (ie; relationship) types
return graphQlQueryToMongoJoinQuery(field);
});
}
testListAccessControl({ access, listKey, operation, authentication }) {
// Either a boolean or an object describing a where clause
if (typeof access[operation] !== 'function') {
return access[operation];
}
const result = access[operation]({
authentication: authentication.item ? authentication : {}
});
const type = getType(result);
if (!['Object', 'Boolean'].includes(type)) {
throw new Error(`Must return an Object or Boolean from Imperative or Declarative access control function. Got ${type}`);
}
// Special case for 'create' permission
if (operation === 'create' && type === 'Object') {
throw new Error(`Expected a Boolean for ${listKey}.access.create(), but got Object. (NOTE: 'create' cannot have a Declarative access control config)`);
}
return result;
}
}
const parseAccess = ({ accessTypes, access, defaultAccess, onGranularParseError, validateGranularType }) => {
switch (getType(access)) {
case 'Boolean':
case 'Function':
return shorthandToObject(accessTypes, access);
case 'Object':
return parseGranularAccessConfig({ accessTypes, access, defaultAccess, onGranularParseError, validateGranularType });
default:
throw new Error('Shorthand access must be specified as either a boolean or a function.');
}
};
.map(([accessType, accessConfig]) => {
const type = getType(accessConfig);
return validationError(type, accessType);
})
.filter(error => !!error);
$search: value => {
if (!value || (getType(value) === 'String' && !value.trim())) {
return undefined;
}
return {
$match: {
name: new RegExp(`${escapeRegExp(value)}`, 'i'),
},
};
},