lemon-core
Version:
Lemon Serverless Micro-Service Platform
90 lines (89 loc) • 3.41 kB
TypeScript
import { NextContext } from 'lemon-model';
import { SlackPostBody, MetricPostBody, CallbackData } from '../common/types';
import * as $lambda from 'aws-lambda';
declare type Context = $lambda.Context;
declare type RequestContext = $lambda.APIGatewayEventRequestContext;
/**
* find ARN('lemon-hello-sns') via context information or environment.
*
* @param context the current running context
* @param NS namespace to log
*/
export declare const getHelloArn: (context?: Context | RequestContext | NextContext, NS?: string) => string;
/**
* report error via `lemon-hello-sns`.
*
* @param e Error
* @param context Lambda Context
* @param event Origin Event Object.
* @param data Optinal Data(body).
*/
export declare const doReportError: (e: Error, context?: any, event?: any, data?: any) => Promise<string>;
/**
* send callback data via web-hook endpoint.
*
* TODO - improve function identity.!! @191212.
*
* @param data payload
*/
export declare const doReportCallback: (data: CallbackData, service?: string, context?: any) => Promise<string>;
/**
* report slack message via `lemon-hello-sns`.
*
* @param channel channel of slack
* @param body slack body
* @param context current running context.
*/
export declare const doReportSlack: (channel: string, body: SlackPostBody, context?: any) => Promise<string>;
/**
* report metric-data like chart/graph to record via `lemon-metrics-sns`.
*
* @param ns namespace like `[a-zA-Z][a-zA-Z0-9]+`
* @param id id value like `[a-zA-Z0-9][a-zA-Z0-9_:\-]+`
* @param body any body data
* @param context current running context.
*/
export declare const doReportMetric: (ns: string, id: string, body: MetricPostBody, context?: any) => Promise<string>;
/** ****************************************************************************************************************
* Common functions.
** ****************************************************************************************************************/
export interface ParrallelParam<T> {
list: T[];
context?: any;
event?: any;
message?: string;
reportError?: boolean;
ignoreError?: boolean;
}
export interface ParrallelCallback<T, U> {
(node: T, index: number): U;
}
/**
* parrallel actions in list (in batch-size = 10)
*
* **TODO** - improve return types by refering callback.
*
* @param param any list
* @param callback (item)=>any | Promise<any>
* @param size (optional) size of parrallel (default 10)
* @param pos (optional) current pos (default 0)
* @param result (optional) result set in stacked.
*/
export declare const do_parrallel: <T, U>(param: ParrallelParam<T> | T[], callback: ParrallelCallback<T, U>, size?: number, pos?: number, result?: (Error | U)[]) => Promise<(Error | U)[]>;
export declare const DEFAULT_TIME_ZONE = 9;
export declare const convDate: (dt: string | number | Date) => Date;
/**
* Convert input to time value (in number)
*
* @param {*} dt see `conv_date()`
* @param {*} name name of property
*/
export declare const convDateToTime: (dt: string | number | Date) => number;
/**
* Convert input (Date) to time-stamp (YYYY-MM-DD hh:mm:ss)
* - consider with current time-zone.
*
* @param {*} dt
*/
export declare const convDateToTS: (dt: string | number | Date) => string;
export {};