Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function handleBeforeValidation(fieldValue, handler) {
if (is.function(handler)) {
return handler(fieldValue);
}
/* eslint no-console: 0 */
console.warn(`[Veasy]: Expect beforeValidation to be a function \
while the value is ${handler}`);
return fieldValue;
}
var value = b;
this._asserts.headers[_name2] = value;
return this;
}
// status code
if (arguments.length === 1 && is.number(a)) {
this._asserts.statusCode = a;
return this;
}
// function
if (arguments.length === 1 && is['function'](a)) {
this._assertFn = a;
return this;
}
// plain body
if (arguments.length === 1 && is.string(a)) {
this._asserts.body = a;
return this;
}
// JSON body
if (arguments.length === 1 && is.object(a)) {
this._asserts.body = stringify(a);
advertise(options, added, removed) {
let advertising = { key: this.options.secret };
if (is.object(options)) advertising = Object.assign(advertising, options);
if (is.object(this.options.discover))
advertising = Object.assign(advertising, this.options.discover);
this.ad = discover(advertising);
if (is.function(added)) this.ad.on('added', added);
if (is.function(removed)) this.ad.on('removed', removed);
}
function handleBeforeValidation(
fieldValue: mixed,
handler: BeforeValidationHandler
) {
if (is.function(handler)) {
return handler(fieldValue);
}
return fieldValue;
}
export default function* isLoggedIn(checkPermissions = null) {
let hasPermission = false;
if (is.function(checkPermissions)) {
hasPermission = yield select(checkPermissions);
} else {
hasPermission = yield select(isAuthenticated);
}
if (!hasPermission) {
const error = new Error('Permission denied.');
error.statusCode = 403;
throw error;
}
}
_fixServiceName(service) {
if (is.function(service) && is.function(service._name)) return service._name();
return `${ service.name.charAt(0).toLowerCase() }${ service.name.slice(1) }`;
}
handle(event, fn) {
if (is.function(event)) {
fn = event;
event = 'message';
}
if (is.not.function(fn)) throw new EventHandlerError(event, fn);
this._socket.on(event, fn);
}
static __fixServiceName(service) {
if (is.not.function(service)) throw new ServiceError(service);
if (service.hasOwnProperty('_name') && is.function(service._name))
return service._name();
return `${ service.name.charAt(0).toLowerCase() }${ service.name.slice(1) }`;
}
}
_configureService(service) {
let configure = is.function(service) && is.function(service._configure) ? service._configure() : {};
if (is.not.object(configure) || is.array(configure)) configure = {};
for (let cfg of Object.keys(configure)) {
if (cfg.startsWith('_') || is.not.function(service[cfg])) delete configure[cfg];
if (is.not.array(configure[cfg])) delete configure[cfg];
else if (is.string(configure[cfg][0]))
configure[cfg] = [ [ configure[cfg][0], configure[cfg][1] || Base._unCamelCase(cfg) ] ];
}
for (let method of Object.getOwnPropertyNames(service)) {
if (!method || method.startsWith('_') || this._ignoredProperties.includes(method)) continue;
if (is.not.function(service[method]) || is.array(configure[method])) continue;
configure[method] = [ [ '*', `/${ method }` ] ];
}
return configure;
}