How to use the rambda.has function in rambda

To help you get started, we’ve selected a few rambda examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terascope / teraslice / packages / elasticsearch-store / src / utils / fp.ts View on Github external
R.path('msg'),
    ),
    R.defaultTo('Unknown Error'),
);

export const getErrorMessages: (errors: i.ErrorLike[]) => string = R.pipe(
    // @ts-ignore
    R.map(getErrorMessage),
    R.join(', '),
);

export const getErrorType = R.pathOr('', ['error', 'type']);

export const getStatusCode: (error: i.ErrorLike) => number = R.pipe(
    R.ifElse(
        R.has('statusCode'),
        R.path('statusCode'),
        R.path('status')
    ),
    R.defaultTo(500)
);

type Shard = { primary: boolean, stage: string };

export function shardsPath(index: string): (stats: any) => Shard[] {
    return R.pathOr([], [index, 'shards']);
}

export const verifyIndexShards: (shards: Shard[]) => boolean = R.pipe(
    // @ts-ignore
    R.filter((shard: Shard) => shard.primary),
    R.all((shard: Shard) => shard.stage === 'DONE')
github terascope / teraslice / packages / elasticsearch-store / src / utils / fp.ts View on Github external
import * as es from 'elasticsearch';
import * as i from './interfaces';

export const isNotNil = (input: any) => input != null;

export function getTimeByField(field: string = ''): (input: any) => number {
    return R.ifElse(
        R.has(field),
        R.pipe(R.path(field), (input: any) => new Date(input).getTime()),
        () => Date.now()
    );
}

export const getErrorMessage: (error: i.ErrorLike) => string = R.pipe(
    R.ifElse(
        R.has('message'),
        R.path('message'),
        R.path('msg'),
    ),
    R.defaultTo('Unknown Error'),
);

export const getErrorMessages: (errors: i.ErrorLike[]) => string = R.pipe(
    // @ts-ignore
    R.map(getErrorMessage),
    R.join(', '),
);

export const getErrorType = R.pathOr('', ['error', 'type']);

export const getStatusCode: (error: i.ErrorLike) => number = R.pipe(
    R.ifElse(
github terascope / teraslice / packages / elasticsearch-store / src / utils / validation.ts View on Github external
}

type indexFn = (config?: IndexSchema) => boolean;

export const isSimpleIndex: indexFn = R.both(
    isNotNil,
    R.both(
        R.has('mapping'),
        R.pipe(
            R.path(['template']),
            R.isNil
        )
    )
);

export const isTemplatedIndex: indexFn = R.both(isNotNil, R.both(R.has('mapping'), R.propEq('template', true)));

export const isTimeSeriesIndex: indexFn = R.both(isTemplatedIndex, R.propEq('timeseries', true));
github terascope / teraslice / packages / elasticsearch-store / src / utils / errors.ts View on Github external
export function getErrorMessage(err: ErrorLike): string {
    const defaultErrorMsg = 'Unknown Error';
    if (err && ts.isString(err)) {
        return err;
    }

    const message: string = R.path(['message'], err) || R.pathOr(defaultErrorMsg, ['msg'], err);
    const prefix = R.path(['dataPath'], err);

    return `${prefix ? `${prefix} ` : ''}${message}`;
}

export const getErrorType = R.pathOr('', ['error', 'type']);

export const getStatusCode: (error: ErrorLike) => number = R.pipe(
    R.ifElse(R.has('statusCode'), R.path(['statusCode']), R.path(['status'])),
    R.defaultTo(500)
);

export type ErrorLike =
    | {
        message?: string;
        msg?: string;
        statusCode?: number;
        status?: number;
    }
    | ajv.ErrorObject
    | string;
github terascope / teraslice / packages / elasticsearch-store / src / utils / fp.ts View on Github external
export function getTimeByField(field: string = ''): (input: any) => number {
    return R.ifElse(
        R.has(field),
        R.pipe(R.path(field), (input: any) => new Date(input).getTime()),
        () => Date.now()
    );
}
github terascope / teraslice / packages / elasticsearch-store / src / utils / elasticsearch.ts View on Github external
export function getTimeByField(field = ''): (input: any) => number {
    return R.ifElse(
        R.has(field),
        R.pipe(
            R.path(field as any),
            (input: any) => new Date(input).getTime()
        ),
        () => Date.now()
    );
}
github terascope / teraslice / packages / elasticsearch-store / src / utils / fp.ts View on Github external
export const getRolloverFrequency = R.pathOr('monthly', ['indexSchema', 'rollover_frequency']);

type indexFn = (config?: i.IndexSchema) => boolean;

export const isSimpleIndex: indexFn = R.both(
    isNotNil,
    R.both(
        R.has('mapping'),
        R.pipe(R.path('template'), R.isNil)
    )
);

export const isTemplatedIndex: indexFn = R.both(
    isNotNil,
    R.both(
        R.has('mapping'),
        R.propEq('template', true),
    )
);

export const isTimeSeriesIndex: indexFn = R.both(
    isTemplatedIndex,
    R.propEq('timeseries', true)
);

export function isValidClient(input: any): input is es.Client {
    if (input == null) return false;

    const reqKeys = [
        'indices',
        'index',
        'get',