UNPKG

ng-http-interceptor

Version:
86 lines 2.61 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ import { Injectable } from "@angular/core"; import { Observable } from "rxjs/Observable"; import { InterceptableStoreFactory, DEFAULT_URL_STORE } from "./interceptable-store"; export class HttpInterceptorService { /** * @param {?} store */ constructor(store) { this.store = store; this._requestStore = this.store.createStore(); this._responseStore = this.store.createStore(); } /** * @param {?} res * @return {?} */ static wrapInObservable(res) { return res instanceof Observable ? res : Observable.of(res); } /** * @param {?=} url * @return {?} */ request(url = DEFAULT_URL_STORE) { return this._requestStore.setActiveStore(url); } /** * @param {?=} url * @return {?} */ response(url = DEFAULT_URL_STORE) { return this._responseStore.setActiveStore(url); } /** * @param {?} url * @param {?} method * @param {?} data * @param {?=} context * @return {?} */ _interceptRequest(url, method, data, context) { return this._requestStore.getMatchedStores(url).reduce((o, i) => o.flatMap(d => { if (!d) { return Observable.of(d); } return HttpInterceptorService.wrapInObservable(i(d, method, context)); }), Observable.of(data)); } /** * @param {?} url * @param {?} method * @param {?} response * @param {?=} context * @return {?} */ _interceptResponse(url, method, response, context) { return this._responseStore.getMatchedStores(url).reduce((o, i) => i(o, method, context), response); } } HttpInterceptorService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ HttpInterceptorService.ctorParameters = () => [ { type: InterceptableStoreFactory, }, ]; function HttpInterceptorService_tsickle_Closure_declarations() { /** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */ HttpInterceptorService.decorators; /** * @nocollapse * @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>} */ HttpInterceptorService.ctorParameters; /** @type {?} */ HttpInterceptorService.prototype._requestStore; /** @type {?} */ HttpInterceptorService.prototype._responseStore; /** @type {?} */ HttpInterceptorService.prototype.store; } //# sourceMappingURL=http-interceptor.service.js.map