2015-08-25 10:27:59 +02:00
|
|
|
import {ReadyStates, RequestMethods, ResponseTypes} from './enums';
|
2015-04-28 23:07:55 -07:00
|
|
|
import {Headers} from './headers';
|
2015-09-10 15:25:36 -07:00
|
|
|
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
|
2015-08-20 14:28:25 -07:00
|
|
|
import {EventEmitter} from 'angular2/src/core/facade/async';
|
2015-06-19 12:14:12 -07:00
|
|
|
import {Request} from './static_request';
|
2015-07-13 14:47:10 -04:00
|
|
|
import {URLSearchParamsUnionFixer, URLSearchParams} from './url_search_params';
|
|
|
|
|
|
|
|
// Work around Dartanalyzer problem :(
|
|
|
|
const URLSearchParams_UnionFixer = URLSearchParamsUnionFixer;
|
2015-06-19 12:14:12 -07:00
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Abstract class from which real backends are derived.
|
|
|
|
*
|
|
|
|
* The primary purpose of a `ConnectionBackend` is to create new connections to fulfill a given
|
|
|
|
* {@link Request}.
|
|
|
|
*/
|
2015-06-19 12:14:12 -07:00
|
|
|
export class ConnectionBackend {
|
|
|
|
constructor() {}
|
|
|
|
createConnection(request: any): Connection { throw new BaseException('Abstract!'); }
|
|
|
|
}
|
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Abstract class from which real connections are derived.
|
|
|
|
*/
|
2015-06-19 12:14:12 -07:00
|
|
|
export class Connection {
|
|
|
|
readyState: ReadyStates;
|
|
|
|
request: Request;
|
2015-06-24 00:27:07 -07:00
|
|
|
response: EventEmitter; // TODO: generic of <Response>;
|
2015-06-19 12:14:12 -07:00
|
|
|
}
|
2015-04-28 23:07:55 -07:00
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Interface for options to construct a Request, based on
|
|
|
|
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
|
|
|
|
*/
|
2015-09-06 22:14:19 -07:00
|
|
|
export type RequestOptionsArgs = {
|
2015-06-19 12:14:12 -07:00
|
|
|
url?: string;
|
2015-04-28 23:07:55 -07:00
|
|
|
method?: RequestMethods;
|
2015-07-13 14:47:10 -04:00
|
|
|
search?: string | URLSearchParams;
|
2015-04-28 23:07:55 -07:00
|
|
|
headers?: Headers;
|
2015-06-19 12:14:12 -07:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON, URLSearchParams, FormData
|
|
|
|
body?: string;
|
2015-04-28 23:07:55 -07:00
|
|
|
}
|
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Interface for options to construct a Response, based on
|
|
|
|
* [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) from the Fetch spec.
|
|
|
|
*/
|
2015-09-06 22:14:19 -07:00
|
|
|
export type ResponseOptionsArgs = {
|
2015-06-19 12:14:12 -07:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON
|
|
|
|
body?: string | Object | FormData;
|
2015-04-28 23:07:55 -07:00
|
|
|
status?: number;
|
|
|
|
statusText?: string;
|
2015-06-24 00:27:07 -07:00
|
|
|
headers?: Headers;
|
2015-04-28 23:07:55 -07:00
|
|
|
type?: ResponseTypes;
|
|
|
|
url?: string;
|
|
|
|
}
|