UNPKG

ts-api-core

Version:

Nodejs api framework core

72 lines (71 loc) 3.1 kB
import { BaseObject } from '../context/base.object'; import { RequestContext } from '../context/request.context'; import { ClassType } from '../base/type'; import { AxiosResponseType } from '../utils/access/http.access'; import { ApiCheckResult } from './api.base'; import { ApiBasePc } from './api.base.pc'; /** * 数据加工基类 */ export declare class BaseWrapper<CONTEXT extends RequestContext> extends ApiBasePc<CONTEXT> { constructor(context: CONTEXT); private services; /** 获取指定 Service */ protected getService<T extends BaseObject<any>>(target: ClassType<T>): T; /** * 并行执行异步任务 * 某步出错不影响其他步骤执行 * 程序执行时间为最长的那个时间 * @param promises * @returns * @author yangyxd */ protected executeParaller<T, E = Error>(promises: Promise<T>[]): Promise<[E | undefined, (T | undefined)[] | undefined]>; /** * 调用Http请求,如果传入一个列表,则并发请求 * @param requestList 请求列表或单个请求 * @returns [响应数据数组,ReqID] * @description * 需要拿 ReqId 建议使用此函数。 * 如果所有请求成功, * 如果请求是数组,则返回一个数组,返回的响应数据数组依次对应请求列表,ReqID为所有请求组合成的ActionName和ReqID */ requestApi(requestList?: (HttpApi | undefined)[] | HttpApi): Promise<[(any | undefined)[] | any, string | undefined]>; protected getActionName(actionPath: string): string; /** 获取当前时间戳(毫秒) */ protected get currentTimeMillis(): number; /** 获取当前时间戳(秒) */ protected get curentTimestamp(): number; } export declare class HttpApiCallback { /** 检查响应结果,返回`true`代表请求成功 */ checkResult?: ApiCheckResult; /** 响应结果解析器,返回真实的data给后续处理(默认取 `RetObject` 字段) */ parser?: (resp: any) => any | undefined; /** 成功回调事件 */ success?: (resp: any, data: any) => void; } export declare abstract class HttpApi { isGet: boolean; actionPath: string; params?: any | undefined; body?: any | undefined; actionName: string; callback?: HttpApiCallback; respType?: AxiosResponseType; constructor(isGet: boolean, actionPath: string, actionName?: string, params?: any | undefined, body?: any | undefined, callback?: HttpApiCallback); } export declare class HttpGet extends HttpApi { constructor(actionPath: string, params?: any | undefined, actionName?: string, callback?: HttpApiCallback, respType?: AxiosResponseType); } export declare class HttpPost extends HttpApi { constructor(actionPath: string, body?: any | undefined, params?: any | undefined, actionName?: string, callback?: HttpApiCallback, respType?: AxiosResponseType); } /** * WrapperResult */ export declare class WrapperResult<T> { data: T; reqId?: string; constructor(data: T, reqId?: string); }