style(lint): re-format modules/@angular
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
import {ConnectionBackend, Connection} from '../interfaces';
|
||||
import {ReadyState, RequestMethod, ResponseType} from '../enums';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
import {ResponseOptions, BaseResponseOptions} from '../base_response_options';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BrowserJsonp} from './browser_jsonp';
|
||||
import {makeTypeError} from '../facade/exceptions';
|
||||
import {StringWrapper, isPresent} from '../facade/lang';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
|
||||
import {BaseResponseOptions, ResponseOptions} from '../base_response_options';
|
||||
import {ReadyState, RequestMethod, ResponseType} from '../enums';
|
||||
import {makeTypeError} from '../facade/exceptions';
|
||||
import {StringWrapper, isPresent} from '../facade/lang';
|
||||
import {Connection, ConnectionBackend} from '../interfaces';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
|
||||
import {BrowserJsonp} from './browser_jsonp';
|
||||
|
||||
const JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
|
||||
const JSONP_ERR_WRONG_METHOD = 'JSONP requests must use GET request method.';
|
||||
|
||||
@@ -45,8 +47,8 @@ export class JSONPConnection_ extends JSONPConnection {
|
||||
private _responseData: any;
|
||||
private _finished: boolean = false;
|
||||
|
||||
constructor(req: Request, private _dom: BrowserJsonp,
|
||||
private baseResponseOptions?: ResponseOptions) {
|
||||
constructor(
|
||||
req: Request, private _dom: BrowserJsonp, private baseResponseOptions?: ResponseOptions) {
|
||||
super();
|
||||
if (req.method !== RequestMethod.Get) {
|
||||
throw makeTypeError(JSONP_ERR_WRONG_METHOD);
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {__platform_browser_private__} from '@angular/platform-browser';
|
||||
|
||||
import {ConnectionBackend, Connection, XSRFStrategy} from '../interfaces';
|
||||
import {ReadyState, RequestMethod, ResponseType, ContentType} from '../enums';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
import {Headers} from '../headers';
|
||||
import {ResponseOptions} from '../base_response_options';
|
||||
import {BrowserXhr} from './browser_xhr';
|
||||
import {isPresent, isString} from '../facade/lang';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
import {isSuccess, getResponseURL} from '../http_utils';
|
||||
|
||||
import {ResponseOptions} from '../base_response_options';
|
||||
import {ContentType, ReadyState, RequestMethod, ResponseType} from '../enums';
|
||||
import {isPresent, isString} from '../facade/lang';
|
||||
import {Headers} from '../headers';
|
||||
import {getResponseURL, isSuccess} from '../http_utils';
|
||||
import {Connection, ConnectionBackend, XSRFStrategy} from '../interfaces';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
|
||||
import {BrowserXhr} from './browser_xhr';
|
||||
|
||||
const XSSI_PREFIX = /^\)\]\}',?\n/;
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import {isPresent, isString} from '../src/facade/lang';
|
||||
import {Headers} from './headers';
|
||||
import {RequestMethod} from './enums';
|
||||
import {RequestOptionsArgs} from './interfaces';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
|
||||
import {isPresent, isString} from '../src/facade/lang';
|
||||
|
||||
import {RequestMethod} from './enums';
|
||||
import {Headers} from './headers';
|
||||
import {normalizeMethodName} from './http_utils';
|
||||
import {RequestOptionsArgs} from './interfaces';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
|
||||
|
||||
/**
|
||||
* Creates a request options object to be optionally provided when instantiating a
|
||||
@@ -35,7 +38,7 @@ export class RequestOptions {
|
||||
* Http method with which to execute a {@link Request}.
|
||||
* Acceptable methods are defined in the {@link RequestMethod} enum.
|
||||
*/
|
||||
method: RequestMethod | string;
|
||||
method: RequestMethod|string;
|
||||
/**
|
||||
* {@link Headers} to be attached to a {@link Request}.
|
||||
*/
|
||||
@@ -61,9 +64,9 @@ export class RequestOptions {
|
||||
this.headers = isPresent(headers) ? headers : null;
|
||||
this.body = isPresent(body) ? body : null;
|
||||
this.url = isPresent(url) ? url : null;
|
||||
this.search = isPresent(search) ? (isString(search) ? new URLSearchParams(<string>(search)) :
|
||||
<URLSearchParams>(search)) :
|
||||
null;
|
||||
this.search = isPresent(search) ?
|
||||
(isString(search) ? new URLSearchParams(<string>(search)) : <URLSearchParams>(search)) :
|
||||
null;
|
||||
this.withCredentials = isPresent(withCredentials) ? withCredentials : null;
|
||||
}
|
||||
|
||||
@@ -99,12 +102,12 @@ export class RequestOptions {
|
||||
body: isPresent(options) && isPresent(options.body) ? options.body : this.body,
|
||||
url: isPresent(options) && isPresent(options.url) ? options.url : this.url,
|
||||
search: isPresent(options) && isPresent(options.search) ?
|
||||
(isString(options.search) ? new URLSearchParams(<string>(options.search)) :
|
||||
(<URLSearchParams>(options.search)).clone()) :
|
||||
this.search,
|
||||
(isString(options.search) ? new URLSearchParams(<string>(options.search)) :
|
||||
(<URLSearchParams>(options.search)).clone()) :
|
||||
this.search,
|
||||
withCredentials: isPresent(options) && isPresent(options.withCredentials) ?
|
||||
options.withCredentials :
|
||||
this.withCredentials
|
||||
options.withCredentials :
|
||||
this.withCredentials
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {isPresent, isJsObject} from '../src/facade/lang';
|
||||
import {Headers} from './headers';
|
||||
|
||||
import {isJsObject, isPresent} from '../src/facade/lang';
|
||||
|
||||
import {ResponseType} from './enums';
|
||||
import {Headers} from './headers';
|
||||
import {ResponseOptionsArgs} from './interfaces';
|
||||
|
||||
|
||||
/**
|
||||
* Creates a response options object to be optionally provided when instantiating a
|
||||
* {@link Response}.
|
||||
@@ -35,7 +38,7 @@ export class ResponseOptions {
|
||||
/**
|
||||
* String or Object representing the body of the {@link Response}.
|
||||
*/
|
||||
body: string | Object;
|
||||
body: string|Object;
|
||||
/**
|
||||
* Http {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html status code}
|
||||
* associated with the response.
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import {isBlank} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {
|
||||
isListLikeIterable,
|
||||
iterateListLike,
|
||||
Map,
|
||||
MapWrapper,
|
||||
StringMapWrapper,
|
||||
ListWrapper,
|
||||
} from '../src/facade/collection';
|
||||
import {isBlank} from '../src/facade/lang';
|
||||
|
||||
import {isListLikeIterable, iterateListLike, Map, MapWrapper, StringMapWrapper, ListWrapper,} from '../src/facade/collection';
|
||||
|
||||
/**
|
||||
* Polyfill for [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers), as
|
||||
@@ -38,7 +32,7 @@ import {
|
||||
export class Headers {
|
||||
/** @internal */
|
||||
_headersMap: Map<string, string[]>;
|
||||
constructor(headers?: Headers | {[key: string]: any}) {
|
||||
constructor(headers?: Headers|{[key: string]: any}) {
|
||||
if (headers instanceof Headers) {
|
||||
this._headersMap = (<Headers>headers)._headersMap;
|
||||
return;
|
||||
@@ -104,7 +98,7 @@ export class Headers {
|
||||
/**
|
||||
* Sets or overrides header value for given name.
|
||||
*/
|
||||
set(header: string, value: string | string[]): void {
|
||||
set(header: string, value: string|string[]): void {
|
||||
var list: string[] = [];
|
||||
|
||||
if (isListLikeIterable(value)) {
|
||||
@@ -130,7 +124,8 @@ export class Headers {
|
||||
this._headersMap.forEach((values: string[], name: string) => {
|
||||
let list: any[] /** TODO #9100 */ = [];
|
||||
|
||||
iterateListLike(values, (val: any /** TODO #9100 */) => list = ListWrapper.concat(list, val.split(',')));
|
||||
iterateListLike(
|
||||
values, (val: any /** TODO #9100 */) => list = ListWrapper.concat(list, val.split(',')));
|
||||
|
||||
(serializableHeaders as any /** TODO #9100 */)[name] = list;
|
||||
});
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
import {isString, isPresent} from '../src/facade/lang';
|
||||
import {makeTypeError} from '../src/facade/exceptions';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {RequestOptionsArgs, ConnectionBackend} from './interfaces';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
import {makeTypeError} from '../src/facade/exceptions';
|
||||
import {isPresent, isString} from '../src/facade/lang';
|
||||
|
||||
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||
import {RequestMethod} from './enums';
|
||||
import {ConnectionBackend, RequestOptionsArgs} from './interfaces';
|
||||
import {Request} from './static_request';
|
||||
import {Response} from './static_response';
|
||||
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
import {RequestMethod} from './enums';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
function httpRequest(backend: ConnectionBackend, request: Request): Observable<Response> {
|
||||
return backend.createConnection(request).response;
|
||||
}
|
||||
|
||||
function mergeOptions(defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs,
|
||||
method: RequestMethod, url: string): RequestOptions {
|
||||
function mergeOptions(
|
||||
defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs, method: RequestMethod,
|
||||
url: string): RequestOptions {
|
||||
var newOptions = defaultOpts;
|
||||
if (isPresent(providedOpts)) {
|
||||
// Hack so Dart can used named parameters
|
||||
@@ -103,7 +106,7 @@ export class Http {
|
||||
* object can be provided as the 2nd argument. The options object will be merged with the values
|
||||
* of {@link BaseRequestOptions} before performing the request.
|
||||
*/
|
||||
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
|
||||
request(url: string|Request, options?: RequestOptionsArgs): Observable<Response> {
|
||||
var responseObservable: any;
|
||||
if (isString(url)) {
|
||||
responseObservable = httpRequest(
|
||||
@@ -121,8 +124,9 @@ export class Http {
|
||||
* Performs a request with `get` http method.
|
||||
*/
|
||||
get(url: string, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethod.Get, url)));
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,9 +134,9 @@ export class Http {
|
||||
*/
|
||||
post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
options, RequestMethod.Post, url)));
|
||||
this._backend, new Request(mergeOptions(
|
||||
this._defaultOptions.merge(new RequestOptions({body: body})), options,
|
||||
RequestMethod.Post, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,17 +144,18 @@ export class Http {
|
||||
*/
|
||||
put(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
options, RequestMethod.Put, url)));
|
||||
this._backend, new Request(mergeOptions(
|
||||
this._defaultOptions.merge(new RequestOptions({body: body})), options,
|
||||
RequestMethod.Put, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a request with `delete` http method.
|
||||
*/
|
||||
delete (url: string, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethod.Delete, url)));
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Delete, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,17 +163,18 @@ export class Http {
|
||||
*/
|
||||
patch(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({body: body})),
|
||||
options, RequestMethod.Patch, url)));
|
||||
this._backend, new Request(mergeOptions(
|
||||
this._defaultOptions.merge(new RequestOptions({body: body})), options,
|
||||
RequestMethod.Patch, url)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a request with `head` http method.
|
||||
*/
|
||||
head(url: string, options?: RequestOptionsArgs): Observable<Response> {
|
||||
return httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options,
|
||||
RequestMethod.Head, url)));
|
||||
return httpRequest(
|
||||
this._backend,
|
||||
new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Head, url)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +190,7 @@ export class Jsonp extends Http {
|
||||
* object can be provided as the 2nd argument. The options object will be merged with the values
|
||||
* of {@link BaseRequestOptions} before performing the request.
|
||||
*/
|
||||
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
|
||||
request(url: string|Request, options?: RequestOptionsArgs): Observable<Response> {
|
||||
var responseObservable: any;
|
||||
if (isString(url)) {
|
||||
url =
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import {isString} from '../src/facade/lang';
|
||||
import {RequestMethod} from './enums';
|
||||
import {makeTypeError} from '../src/facade/exceptions';
|
||||
import {isString} from '../src/facade/lang';
|
||||
|
||||
import {RequestMethod} from './enums';
|
||||
|
||||
export function normalizeMethodName(method: string | RequestMethod): RequestMethod {
|
||||
if (isString(method)) {
|
||||
var originalMethod = method;
|
||||
method = (<string>method)
|
||||
.replace(/(\w)(\w*)/g, (g0: string, g1: string, g2: string) =>
|
||||
g1.toUpperCase() + g2.toLowerCase());
|
||||
.replace(
|
||||
/(\w)(\w*)/g,
|
||||
(g0: string, g1: string, g2: string) => g1.toUpperCase() + g2.toLowerCase());
|
||||
method = <number>(<{[key: string]: any}>RequestMethod)[method];
|
||||
if (typeof method !== 'number')
|
||||
throw makeTypeError(
|
||||
|
||||
@@ -21,9 +21,7 @@ export abstract class Connection {
|
||||
}
|
||||
|
||||
/** An XSRFStrategy configures XSRF protection (e.g. via headers) on an HTTP request. */
|
||||
export abstract class XSRFStrategy {
|
||||
abstract configureRequest(req: Request): void;
|
||||
}
|
||||
export abstract class XSRFStrategy { abstract configureRequest(req: Request): void; }
|
||||
|
||||
/**
|
||||
* Interface for options to construct a RequestOptions, based on
|
||||
@@ -31,8 +29,8 @@ export abstract class XSRFStrategy {
|
||||
*/
|
||||
export interface RequestOptionsArgs {
|
||||
url?: string;
|
||||
method?: string | RequestMethod;
|
||||
search?: string | URLSearchParams;
|
||||
method?: string|RequestMethod;
|
||||
search?: string|URLSearchParams;
|
||||
headers?: Headers;
|
||||
body?: any;
|
||||
withCredentials?: boolean;
|
||||
@@ -49,10 +47,7 @@ export interface RequestArgs extends RequestOptionsArgs { url: string; }
|
||||
*/
|
||||
export type ResponseOptionsArgs = {
|
||||
// TODO: Support Blob, ArrayBuffer, JSON
|
||||
body?: string | Object | FormData;
|
||||
status?: number;
|
||||
statusText?: string;
|
||||
headers?: Headers;
|
||||
body?: string | Object | FormData; status?: number; statusText?: string; headers?: Headers;
|
||||
type?: ResponseType;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import {StringWrapper, isPresent} from '../src/facade/lang';
|
||||
|
||||
import {ContentType, RequestMethod} from './enums';
|
||||
import {RequestArgs} from './interfaces';
|
||||
import {Headers} from './headers';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
import {normalizeMethodName} from './http_utils';
|
||||
import {isPresent, StringWrapper} from '../src/facade/lang';
|
||||
import {RequestArgs} from './interfaces';
|
||||
import {URLSearchParams} from './url_search_params';
|
||||
|
||||
|
||||
// TODO(jeffbcross): properly implement body accessors
|
||||
/**
|
||||
@@ -108,7 +110,7 @@ export class Request {
|
||||
*/
|
||||
arrayBuffer(): ArrayBuffer {
|
||||
if (this._body instanceof ArrayBuffer) return <ArrayBuffer>this._body;
|
||||
throw "The request body isn't an array buffer";
|
||||
throw 'The request body isn\'t an array buffer';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +120,7 @@ export class Request {
|
||||
blob(): Blob {
|
||||
if (this._body instanceof Blob) return <Blob>this._body;
|
||||
if (this._body instanceof ArrayBuffer) return new Blob([this._body]);
|
||||
throw "The request body isn't either a blob or an array buffer";
|
||||
throw 'The request body isn\'t either a blob or an array buffer';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +168,7 @@ export class Request {
|
||||
}
|
||||
}
|
||||
|
||||
const noop = function () {};
|
||||
const noop = function() {};
|
||||
const w = typeof window == 'object' ? window : noop;
|
||||
const FormData = (w as any /** TODO #9100 */)['FormData'] || noop;
|
||||
const Blob = (w as any /** TODO #9100 */)['Blob'] || noop;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import {ResponseType} from './enums';
|
||||
import {isString, Json} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {Headers} from './headers';
|
||||
import {Json, isString} from '../src/facade/lang';
|
||||
|
||||
import {ResponseOptions} from './base_response_options';
|
||||
import {ResponseType} from './enums';
|
||||
import {Headers} from './headers';
|
||||
import {isJsObject} from './http_utils';
|
||||
|
||||
|
||||
/**
|
||||
* Creates `Response` instances from provided values.
|
||||
*
|
||||
@@ -72,7 +74,7 @@ export class Response {
|
||||
*/
|
||||
headers: Headers;
|
||||
// TODO: Support ArrayBuffer, JSON, FormData, Blob
|
||||
private _body: string | Object;
|
||||
private _body: string|Object;
|
||||
constructor(responseOptions: ResponseOptions) {
|
||||
this._body = responseOptions.body;
|
||||
this.status = responseOptions.status;
|
||||
@@ -93,7 +95,7 @@ export class Response {
|
||||
* Attempts to return body as parsed `JSON` object, or raises an exception.
|
||||
*/
|
||||
json(): any {
|
||||
var jsonResponse: string | Object;
|
||||
var jsonResponse: string|Object;
|
||||
if (isJsObject(this._body)) {
|
||||
jsonResponse = this._body;
|
||||
} else if (isString(this._body)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {ListWrapper, Map, isListLikeIterable} from '../src/facade/collection';
|
||||
import {isPresent} from '../src/facade/lang';
|
||||
import {Map, ListWrapper, isListLikeIterable} from '../src/facade/collection';
|
||||
|
||||
function paramParser(rawParams: string = ''): Map<string, string[]> {
|
||||
var map = new Map<string, string[]>();
|
||||
|
||||
Reference in New Issue
Block a user