import { Requestor } from "../requestor"; import { ResponseContext } from "./response-context"; export declare type RequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; export declare type RequestCredentials = "include" | "omit" | "same-origin" | boolean; export declare type Similar = "abort" | "wait-done"; export declare type RequestSimilar = Similar | ((requestContext: RequestContext) => [string, Similar]); export declare type RequestContextTap = (requestContext: RequestContext) => T; export declare type ResponseContextTap = (responseContext: ResponseContext) => T; export declare type ContextTap = RequestContextTap | RequestContextTap> | RequestContextTap>> | RequestContextTap>> | RequestContextTap>>>; export declare type ModelConstructor = { new (...args: any[]): T; }; export declare function createRequestContext(requestContextPlain?: RequestContextPlain): RequestContext; export interface RequestContextPlain { /** 请求基础URL */ baseUrl?: string; /** 请求路径 */ path?: string; /** 请求方法 */ method?: RequestMethod; /** 请求头 */ headers?: Record; /** * 是否允许携带跨域cookies * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Request/credentials */ credentials?: RequestCredentials; /** 请求路径参数 */ params?: Record; /** 请求查询参数 */ query?: Record; /** 请求体参数 */ body?: Record; /** 表单参数 */ formData?: FormData; /** * 模拟数据模板 * @see https://github.com/nuysoft/Mock/wiki/Mock.mock() */ mock?: any; /** 响应对象模型 */ model?: ModelConstructor; /** 类似请求处理方式 */ similar?: RequestSimilar; /** 需要传递给引擎的其他参数 */ others?: any; /** 请求上下文与响应上下文监听回调函数 */ contextTap?: ContextTap; } export declare class RequestContext { /** 请求基础URL */ baseUrl?: string; /** 请求路径 */ path?: string; /** 请求方法 */ method: RequestMethod; /** 请求头 */ headers?: Record; /** * 是否允许携带跨域cookies * @see https://developer.mozilla.org/zh-CN/docs/Web/API/Request/credentials */ credentials?: RequestCredentials; /** 请求路径参数 */ params?: Record; /** 请求查询参数 */ query?: Record; /** 请求体参数 */ body?: Record; /** 表单参数 */ formData?: FormData; /** * 模拟数据模板 * @see https://github.com/nuysoft/Mock/wiki/Mock.mock() */ mock?: any; /** 响应对象模型 */ model?: ModelConstructor; /** 类似请求处理方式 */ similar?: RequestSimilar; /** 需要传递给引擎的其他参数 */ others?: any; /** 请求上下文与响应上下文监听回调函数 */ contextTap?: ContextTap; /** 请求完整路径 */ get fullpath(): string; /** 请求完整URL */ get url(): string; /** 查询字符串 */ get queryString(): string | undefined; /** 带查询字符串的请求完整URL */ get queryUrl(): string; /** 设置请求基础URL */ setBaseUrl(baseUrl: RequestContext["baseUrl"]): this; /** 设置请求路径 */ setPath(path: RequestContext["path"]): this; /** 设置请求方法 */ setMethod(method: RequestContext["method"]): this; /** 设置请求头 */ setHeaders(headers: RequestContext["headers"]): this; /** 设置是否允许携带跨域cookies */ setCredentials(credentials: RequestContext["credentials"]): this; /** 设置请求路径参数 */ setParams(params: RequestContext["params"]): this; /** 设置请求查询参数 */ setQuery(query: RequestContext["query"]): this; /** 设置请求体参数 */ setBody(body: RequestContext["body"]): this; /** 设置表单参数 */ setFormData(formData: RequestContext["formData"]): this; /** 设置模拟数据模板 */ setMock(mock: RequestContext["mock"]): this; /** 设置响应对象模型 */ setModel(model: RequestContext["model"]): this; /** 设置类似请求处理方式 */ setSimilar(similar: RequestContext["similar"]): this; /** 设置需要传递给引擎的其他参数 */ setOthers(others: RequestContext["others"]): this; /** 设置请求上下文与响应上下文监听 */ setContextTap(contextTap: RequestContext["contextTap"]): this; /** 发送请求 */ send(requestor: Requestor): Promise>; /** 合并请求上下文 */ merge(source: RequestContext): RequestContext; }