Repository URL to install this package:
|
Version:
4.0.4 ▾
|
/**
* @todo - should add .env logging
*/
import 'isomorphic-fetch';
import { HTTPCache } from 'apollo-datasource-rest';
import { RequestBody, Params, Method, Credentials, CommonChildren, OneRequestStore, OneRequestObj, HeadersObj, TransformParams, TransformResponse, OneRequestAdapter, OneRequestAsSerializedDebug, OneRequestContextBase } from './typings';
/**
* @todo add a way to set the adapter so we can specify for cases like viewbag?
*/
declare class OneRequest<Context extends OneRequestContextBase = OneRequestContextBase> {
static init(args?: OneRequestObj): OneRequest<OneRequestContextBase>;
store: OneRequestStore;
private _parent?;
private _children?;
constructor();
setUrl(url: string): this;
setMethod(method: Method): this;
setDefaultParams(params?: any): this;
setParamsTransform(): this;
setMock(mock?: any): this;
setFixture(mock?: any): this;
setData(data?: any): this;
toMock(data?: any): any;
toWretch(): import("wretch/dist/wretcher").Wretcher;
setDebug(shouldDebug?: boolean): this;
from(obj?: OneRequestObj): this;
named(named: string): this;
debug(shouldDebug: boolean): this;
toJSON(): OneRequestAsSerializedDebug;
parent(parent: OneRequest): this;
children(): CommonChildren;
child(childName: string): OneRequest<OneRequestContextBase>;
/**
* @todo validate url...
*/
url(absoluteUrl: string): this;
baseUrl(baseUrl: string): this;
path(path: string): this;
params(params: Params): this;
body(body: RequestBody): this;
tapRequestParams(tapParams: TransformParams): this;
tapResponseData(tapResponse: TransformResponse): this;
post(): this;
get(): this;
patch(): this;
delete(): this;
method(method: Method): this;
httpCache: HTTPCache;
context: Context;
cache(value: string | false): this;
/**
* @todo should weakmap this...
*/
toApollo(): import("./adapters/apollo").OneRequestApolloDataSource;
/**
* @see https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/runHttpQuery.ts#L343
*/
initialize(args: {
context: Context;
cache: HTTPCache;
}): this;
/**
* @protected
* @todo make it settable...
* @note - this has assign constants, which may be an issue
* if we are using .toRequest directly
* separately/instead of .doRequest
* - since this returns the `global.Request` for `fetch`
*/
toRequest(): Request | import("./adapters/apollo").OneRequestApolloDataSource;
/**
* same as () / .call() / .end() / .fetch() / send() / doRequest()
*/
doRequest<ResponseType = any>(): Promise<any>;
/**
* @alias to
* @todo pass in adapter here like `toFetch`, `toAxios`, `toApollo`
*/
as(adapter?: OneRequestAdapter): import("./typings").AdapterType;
correlationId(correlationIdArg?: string): this;
/**
* @protected
* @todo need typings for context which is in gql...
*/
forwardRequest(context: Context): this;
cookie(cookieToSet: string | string[]): this;
header(key: string, value: string): this;
headers(headers?: Headers | HeadersObj): this;
auth(credentials: Credentials): void;
jwt(token: string): this;
/**
* @todo split to dep?
*/
clone(): OneRequest<OneRequestContextBase>;
/**
* @todo should be @name .clear?
*/
reset(): this;
entries(): import("exotic/dist/types/obj/cast/fromCollectionToObj").CollectionAsObj<any>;
private _set;
private _get;
private _has;
private _delete;
}
export { OneRequest };
export { OneRequest as Request };