Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')
);
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 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(
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 function shardsPath(index: string): (stats: any) => i.Shard[] {
return R.pathOr([], [index, 'shards']);
}
import * as R from 'rambda';
export const isNotNil = (input: any) => input != null;
export function getFirstValue(input: { [key: string]: T }): T | undefined {
return Object.values(input)[0];
}
export function getFirstKey(input: T): (keyof T) | undefined {
return Object.keys(input)[0] as keyof T;
}
export const getIndexMapping = R.path(['index_schema', 'mapping']);
export const getRolloverFrequency = R.pathOr('monthly', ['index_schema', 'rollover_frequency']);
export const getSchemaVersion = R.pathOr(1, ['index_schema', 'version']);
export const getSchemaVersionStr: (config: any) => string = R.pipe(
getSchemaVersion,
R.toString as any,
R.prepend('s')
) as any;
export const getDataVersion = R.pathOr(1, ['version']);
export const getDataVersionStr: (config: any) => string = R.pipe(
getDataVersion,
R.toString as any,
R.prepend('v')
) as any;
export const formatIndexName: (strs: (string | undefined)[]) => string = R.pipe(
export function getFirstKey(input: T): (keyof T) | undefined {
return Object.keys(input)[0] as keyof T;
}
export const getIndexMapping = R.path(['index_schema', 'mapping']);
export const getRolloverFrequency = R.pathOr('monthly', ['index_schema', 'rollover_frequency']);
export const getSchemaVersion = R.pathOr(1, ['index_schema', 'version']);
export const getSchemaVersionStr: (config: any) => string = R.pipe(
getSchemaVersion,
R.toString as any,
R.prepend('s')
) as any;
export const getDataVersion = R.pathOr(1, ['version']);
export const getDataVersionStr: (config: any) => string = R.pipe(
getDataVersion,
R.toString as any,
R.prepend('v')
) as any;
export const formatIndexName: (strs: (string | undefined)[]) => string = R.pipe(
R.reject((v: string) => !v) as any,
R.map(R.trim),
R.join('-')
);
export const buildNestPath: (paths: (string | undefined)[]) => string = R.pipe(
R.reject((v: string) => !v) as any,
R.map(R.trim),
R.join('.')
throw error;
}
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;
export function shardsPath(index: string): (stats: any) => Shard[] {
return R.pathOr([], [index, 'shards']);
}
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}`;
}
import * as R from 'rambda';
export const isNotNil = (input: any) => input != null;
export function getFirstValue(input: { [key: string]: T }): T | undefined {
return Object.values(input)[0];
}
export function getFirstKey(input: T): (keyof T) | undefined {
return Object.keys(input)[0] as keyof T;
}
export const getIndexMapping = R.path(['index_schema', 'mapping']);
export const getRolloverFrequency = R.pathOr('monthly', ['index_schema', 'rollover_frequency']);
export const getSchemaVersion = R.pathOr(1, ['index_schema', 'version']);
export const getSchemaVersionStr: (config: any) => string = R.pipe(
getSchemaVersion,
R.toString as any,
R.prepend('s')
) as any;
export const getDataVersion = R.pathOr(1, ['version']);
export const getDataVersionStr: (config: any) => string = R.pipe(
getDataVersion,
R.toString as any,
R.prepend('v')
) as any;
export const formatIndexName: (strs: (string | undefined)[]) => string = R.pipe(
R.reject((v: string) => !v) as any,
R.map(R.trim),