ts-logs
Version:
This package provide a skd for audit and manager logs in nodejs and express
197 lines • 7.28 kB
TypeScript
import { CatchError, CatchProps, EncryptStepOption, IMask, Locale, LocalOpt } from "../types";
import { Method, SProps, Steps, Type } from "../types";
export declare class Step implements Steps {
readonly uid: string;
readonly name: string;
readonly tags: Readonly<string[]>;
readonly url: string;
readonly stack: string;
readonly data: string | {};
readonly statusCode: number;
readonly message: string;
readonly type: Type;
readonly method: Method;
readonly createdAt: Date;
readonly additionalInfo: string | null;
readonly category: string;
private constructor();
/**
* @description Encrypt attributes.
* @param options object as EncryptStepOption.
* @returns instance of Step.
*/
encrypt(options: EncryptStepOption): Promise<Readonly<Steps>>;
/**
* @description Decrypt attributes.
* @param options object as EncryptStepOption.
* @returns instance of Step.
*/
decrypt(options: EncryptStepOption): Promise<Readonly<Steps>>;
/**
* @description Create an instance of Step type: error
* @param props as Object with SProps params
* @returns an instance of Step
*/
static error(props: Partial<SProps> & {
name: string;
message: string;
}): Readonly<Step>;
/**
* @description Create an instance of Step adding additional info.
* @param info as string.
* @returns an instance of Step
*/
setAdditionalInfo(info: string | null): Readonly<Steps>;
/**
* @description Create an instance of Step type: stack
* @param props as Object with SProps params
* @returns an instance of Step
*/
static stack(props: Partial<SProps> & {
name: string;
message: string;
stack: string;
}): Readonly<Step>;
/**
* @description Create an instance of Step type: debug
* @param props as Object with SProps params
* @returns an instance of Step
*/
static debug(props: Omit<SProps, 'type' | 'createdAt' | 'additionalInfo' | 'category'>): Readonly<Step>;
/**
* @description Create an instance of Step type: fatal
* @param props as Object with SProps params
* @returns an instance of Step
*/
static fatal(props: Omit<SProps, 'type' | 'createdAt' | 'additionalInfo' | 'category'>): Readonly<Step>;
/**
* @description Create an instance of Step type: info
* @param props as Object with SProps params
* @returns an instance of Step
*/
static info(props: Partial<SProps> & {
name: string;
message: string;
}): Readonly<Step>;
/**
* @description Create an instance of Step type: warn
* @param props as Object with SProps params
* @returns an instance of Step
*/
static warn(props: Partial<SProps> & {
name: string;
message: string;
}): Readonly<Step>;
/**
* @description Extract id from request body if exists.
* @param body as string or object
* @returns id or undefined
*/
private static extractId;
/**
* @description Extract tags from body if exists keys.
* @param body as string or object
* @returns tags as array of string or empty array.
*/
private static extractTagsFromData;
/**
* @description Create an instance of Step
* @param props as Object with SProps params
* @returns an instance of Step
*/
static create(props: Partial<SProps>): Readonly<Step>;
/**
* @description Create an step instance from error: Error from a try catch block.
* @param error as instance of Error from catch block.
* @param props object with CatchProps.
*/
static catch(error: Error | CatchError, props?: CatchProps): Readonly<Step>;
/**
* @description Create a new instance of Step with provided tags.
* @param tags as Array of Tags.
* @returns new instance of Step with tags.
*/
addTags(tags: string[]): Readonly<Step>;
/**
* @description Create a new instance of Step with provided tag.
* @param tag as Tag.
* @returns new instance of Step with tag.
*/
addTag(tag: string): Readonly<Step>;
/**
* @description Create a new instance of Step with provided name.
* @param name as string.
* @returns new instance of Step with provided name.
*/
setName(name: string): Steps;
/**
* @description Remove keys from body matching provided param.
* @param keys as array of string.
* @returns new instance of Step.
*/
remove(keys: string[]): Readonly<Step>;
/**
* @description Create a new instance of Step with provided method.
* @param method as Method.
* @returns new instance of Step with provided method.
*/
setMethod(method: Method): Steps;
/**
* @description Create a new instance of Step with provided stack.
* @param stack as Error stack as string.
* @returns new instance of Step with provided stack.
*/
setStack(stack: string): Readonly<Step>;
/**
* @description Create a new instance of Step with provided message.
* @param message as Error message or Info message as string.
* @returns new instance of Step with provided error or info message.
*/
setMessage(message: string): Readonly<Step>;
/**
* @description Create a new instance of Step with provided status code.
* @param code number representing http status code. 200, 404, 400, 500 ...
* @returns new instance of Step with provided status code.
*/
setStatusCode(code: number): Readonly<Step>;
/**
* @description Create a new instance of Step with provided data.
* @param data params or request body as string or object.
* @returns new instance of Step with provided data.
*/
setData(data: string | {}): Readonly<Step>;
/**
* @description Create a new instance of Step with uid.
* @param uid as unique id or any string representing log id.
* @returns new instance of Step with provided uid.
*/
setUid(uid: string): Readonly<Step>;
/**
* @description Create a new instance of Step with url.
* @param url as string.
* @returns new instance of Step with provided url.
*/
setURL(url: string): Readonly<Step>;
mask(attributes: IMask[]): Readonly<Step>;
/**
* @description Print single step on terminal.
* @param locales as LocalesArgument to format date.
* @param options as DateTimeFormatOptions to format date.
*/
print(locales?: Locale, options?: LocalOpt): void;
/**
* @description Create a formatted message as string to print on terminal.
* @param locales as LocalesArgument to format date.
* @param options as DateTimeFormatOptions to format date.
* @returns formatted message string based on unix code to print on terminal.
*/
getPrintableMsg(locales?: Locale, options?: LocalOpt): string;
/**
* @description Create a new instance of Step with provided category.
* @param category params as string.
* @returns new instance of Step with provided category.
*/
setCategory(category: string): Readonly<Steps>;
}
export default Step;
//# sourceMappingURL=step.d.ts.map