UNPKG

ngx-restful

Version:

AngularX module for easy integration with RESTful API.

1,028 lines (983 loc) 41.4 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs')) : typeof define === 'function' && define.amd ? define(['exports', 'rxjs'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.out = {}, global.rxjs)); })(this, (function (exports, rxjs) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends$1(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /** PURE_IMPORTS_START PURE_IMPORTS_END */ var errorObject = { e: {} }; /** PURE_IMPORTS_START _errorObject PURE_IMPORTS_END */ var tryCatchTarget; function tryCatcher() { try { return tryCatchTarget.apply(this, arguments); } catch (e) { errorObject.e = e; return errorObject; } } function tryCatch(fn) { tryCatchTarget = fn; return tryCatcher; } /** PURE_IMPORTS_START PURE_IMPORTS_END */ function isFunction(x) { return typeof x === 'function'; } /** PURE_IMPORTS_START PURE_IMPORTS_END */ var _enable_super_gross_mode_that_will_cause_bad_things = false; var config = { Promise: undefined, set useDeprecatedSynchronousErrorHandling(value) { if (value) { var error = /*@__PURE__*/ new Error(); /*@__PURE__*/ console.warn('DEPRECATED! RxJS was set to use deprecated synchronous error handling behavior by code at: \n' + error.stack); } _enable_super_gross_mode_that_will_cause_bad_things = value; }, get useDeprecatedSynchronousErrorHandling() { return _enable_super_gross_mode_that_will_cause_bad_things; }, }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ function hostReportError(err) { setTimeout(function () { throw err; }); } /** PURE_IMPORTS_START _config,_util_hostReportError PURE_IMPORTS_END */ var empty = { closed: true, next: function (value) { }, error: function (err) { if (config.useDeprecatedSynchronousErrorHandling) { throw err; } else { hostReportError(err); } }, complete: function () { } }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ var isArray = Array.isArray || (function (x) { return x && typeof x.length === 'number'; }); /** PURE_IMPORTS_START PURE_IMPORTS_END */ function isObject(x) { return x != null && typeof x === 'object'; } /** PURE_IMPORTS_START PURE_IMPORTS_END */ function UnsubscriptionErrorImpl(errors) { Error.call(this); this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : ''; this.name = 'UnsubscriptionError'; this.errors = errors; return this; } UnsubscriptionErrorImpl.prototype = /*@__PURE__*/ Object.create(Error.prototype); var UnsubscriptionError = UnsubscriptionErrorImpl; /** PURE_IMPORTS_START _util_isArray,_util_isObject,_util_isFunction,_util_tryCatch,_util_errorObject,_util_UnsubscriptionError PURE_IMPORTS_END */ var Subscription = /*@__PURE__*/ (function () { function Subscription(unsubscribe) { this.closed = false; this._parent = null; this._parents = null; this._subscriptions = null; if (unsubscribe) { this._unsubscribe = unsubscribe; } } Subscription.prototype.unsubscribe = function () { var hasErrors = false; var errors; if (this.closed) { return; } var _a = this, _parent = _a._parent, _parents = _a._parents, _unsubscribe = _a._unsubscribe, _subscriptions = _a._subscriptions; this.closed = true; this._parent = null; this._parents = null; this._subscriptions = null; var index = -1; var len = _parents ? _parents.length : 0; while (_parent) { _parent.remove(this); _parent = ++index < len && _parents[index] || null; } if (isFunction(_unsubscribe)) { var trial = tryCatch(_unsubscribe).call(this); if (trial === errorObject) { hasErrors = true; errors = errors || (errorObject.e instanceof UnsubscriptionError ? flattenUnsubscriptionErrors(errorObject.e.errors) : [errorObject.e]); } } if (isArray(_subscriptions)) { index = -1; len = _subscriptions.length; while (++index < len) { var sub = _subscriptions[index]; if (isObject(sub)) { var trial = tryCatch(sub.unsubscribe).call(sub); if (trial === errorObject) { hasErrors = true; errors = errors || []; var err = errorObject.e; if (err instanceof UnsubscriptionError) { errors = errors.concat(flattenUnsubscriptionErrors(err.errors)); } else { errors.push(err); } } } } } if (hasErrors) { throw new UnsubscriptionError(errors); } }; Subscription.prototype.add = function (teardown) { if (!teardown || (teardown === Subscription.EMPTY)) { return Subscription.EMPTY; } if (teardown === this) { return this; } var subscription = teardown; switch (typeof teardown) { case 'function': subscription = new Subscription(teardown); case 'object': if (subscription.closed || typeof subscription.unsubscribe !== 'function') { return subscription; } else if (this.closed) { subscription.unsubscribe(); return subscription; } else if (typeof subscription._addParent !== 'function') { var tmp = subscription; subscription = new Subscription(); subscription._subscriptions = [tmp]; } break; default: throw new Error('unrecognized teardown ' + teardown + ' added to Subscription.'); } var subscriptions = this._subscriptions || (this._subscriptions = []); subscriptions.push(subscription); subscription._addParent(this); return subscription; }; Subscription.prototype.remove = function (subscription) { var subscriptions = this._subscriptions; if (subscriptions) { var subscriptionIndex = subscriptions.indexOf(subscription); if (subscriptionIndex !== -1) { subscriptions.splice(subscriptionIndex, 1); } } }; Subscription.prototype._addParent = function (parent) { var _a = this, _parent = _a._parent, _parents = _a._parents; if (!_parent || _parent === parent) { this._parent = parent; } else if (!_parents) { this._parents = [parent]; } else if (_parents.indexOf(parent) === -1) { _parents.push(parent); } }; Subscription.EMPTY = (function (empty) { empty.closed = true; return empty; }(new Subscription())); return Subscription; }()); function flattenUnsubscriptionErrors(errors) { return errors.reduce(function (errs, err) { return errs.concat((err instanceof UnsubscriptionError) ? err.errors : err); }, []); } /** PURE_IMPORTS_START PURE_IMPORTS_END */ var rxSubscriber = typeof Symbol === 'function' ? /*@__PURE__*/ Symbol('rxSubscriber') : '@@rxSubscriber_' + /*@__PURE__*/ Math.random(); /** PURE_IMPORTS_START tslib,_util_isFunction,_Observer,_Subscription,_internal_symbol_rxSubscriber,_config,_util_hostReportError PURE_IMPORTS_END */ var Subscriber = /*@__PURE__*/ (function (_super) { __extends$1(Subscriber, _super); function Subscriber(destinationOrNext, error, complete) { var _this = _super.call(this) || this; _this.syncErrorValue = null; _this.syncErrorThrown = false; _this.syncErrorThrowable = false; _this.isStopped = false; _this._parentSubscription = null; switch (arguments.length) { case 0: _this.destination = empty; break; case 1: if (!destinationOrNext) { _this.destination = empty; break; } if (typeof destinationOrNext === 'object') { if (destinationOrNext instanceof Subscriber) { _this.syncErrorThrowable = destinationOrNext.syncErrorThrowable; _this.destination = destinationOrNext; destinationOrNext.add(_this); } else { _this.syncErrorThrowable = true; _this.destination = new SafeSubscriber(_this, destinationOrNext); } break; } default: _this.syncErrorThrowable = true; _this.destination = new SafeSubscriber(_this, destinationOrNext, error, complete); break; } return _this; } Subscriber.prototype[rxSubscriber] = function () { return this; }; Subscriber.create = function (next, error, complete) { var subscriber = new Subscriber(next, error, complete); subscriber.syncErrorThrowable = false; return subscriber; }; Subscriber.prototype.next = function (value) { if (!this.isStopped) { this._next(value); } }; Subscriber.prototype.error = function (err) { if (!this.isStopped) { this.isStopped = true; this._error(err); } }; Subscriber.prototype.complete = function () { if (!this.isStopped) { this.isStopped = true; this._complete(); } }; Subscriber.prototype.unsubscribe = function () { if (this.closed) { return; } this.isStopped = true; _super.prototype.unsubscribe.call(this); }; Subscriber.prototype._next = function (value) { this.destination.next(value); }; Subscriber.prototype._error = function (err) { this.destination.error(err); this.unsubscribe(); }; Subscriber.prototype._complete = function () { this.destination.complete(); this.unsubscribe(); }; Subscriber.prototype._unsubscribeAndRecycle = function () { var _a = this, _parent = _a._parent, _parents = _a._parents; this._parent = null; this._parents = null; this.unsubscribe(); this.closed = false; this.isStopped = false; this._parent = _parent; this._parents = _parents; this._parentSubscription = null; return this; }; return Subscriber; }(Subscription)); var SafeSubscriber = /*@__PURE__*/ (function (_super) { __extends$1(SafeSubscriber, _super); function SafeSubscriber(_parentSubscriber, observerOrNext, error, complete) { var _this = _super.call(this) || this; _this._parentSubscriber = _parentSubscriber; var next; var context = _this; if (isFunction(observerOrNext)) { next = observerOrNext; } else if (observerOrNext) { next = observerOrNext.next; error = observerOrNext.error; complete = observerOrNext.complete; if (observerOrNext !== empty) { context = Object.create(observerOrNext); if (isFunction(context.unsubscribe)) { _this.add(context.unsubscribe.bind(context)); } context.unsubscribe = _this.unsubscribe.bind(_this); } } _this._context = context; _this._next = next; _this._error = error; _this._complete = complete; return _this; } SafeSubscriber.prototype.next = function (value) { if (!this.isStopped && this._next) { var _parentSubscriber = this._parentSubscriber; if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._next, value); } else if (this.__tryOrSetError(_parentSubscriber, this._next, value)) { this.unsubscribe(); } } }; SafeSubscriber.prototype.error = function (err) { if (!this.isStopped) { var _parentSubscriber = this._parentSubscriber; var useDeprecatedSynchronousErrorHandling = config.useDeprecatedSynchronousErrorHandling; if (this._error) { if (!useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(this._error, err); this.unsubscribe(); } else { this.__tryOrSetError(_parentSubscriber, this._error, err); this.unsubscribe(); } } else if (!_parentSubscriber.syncErrorThrowable) { this.unsubscribe(); if (useDeprecatedSynchronousErrorHandling) { throw err; } hostReportError(err); } else { if (useDeprecatedSynchronousErrorHandling) { _parentSubscriber.syncErrorValue = err; _parentSubscriber.syncErrorThrown = true; } else { hostReportError(err); } this.unsubscribe(); } } }; SafeSubscriber.prototype.complete = function () { var _this = this; if (!this.isStopped) { var _parentSubscriber = this._parentSubscriber; if (this._complete) { var wrappedComplete = function () { return _this._complete.call(_this._context); }; if (!config.useDeprecatedSynchronousErrorHandling || !_parentSubscriber.syncErrorThrowable) { this.__tryOrUnsub(wrappedComplete); this.unsubscribe(); } else { this.__tryOrSetError(_parentSubscriber, wrappedComplete); this.unsubscribe(); } } else { this.unsubscribe(); } } }; SafeSubscriber.prototype.__tryOrUnsub = function (fn, value) { try { fn.call(this._context, value); } catch (err) { this.unsubscribe(); if (config.useDeprecatedSynchronousErrorHandling) { throw err; } else { hostReportError(err); } } }; SafeSubscriber.prototype.__tryOrSetError = function (parent, fn, value) { if (!config.useDeprecatedSynchronousErrorHandling) { throw new Error('bad call'); } try { fn.call(this._context, value); } catch (err) { if (config.useDeprecatedSynchronousErrorHandling) { parent.syncErrorValue = err; parent.syncErrorThrown = true; return true; } else { hostReportError(err); return true; } } return false; }; SafeSubscriber.prototype._unsubscribe = function () { var _parentSubscriber = this._parentSubscriber; this._context = null; this._parentSubscriber = null; _parentSubscriber.unsubscribe(); }; return SafeSubscriber; }(Subscriber)); /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */ var OuterSubscriber = /*@__PURE__*/ (function (_super) { __extends$1(OuterSubscriber, _super); function OuterSubscriber() { return _super !== null && _super.apply(this, arguments) || this; } OuterSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) { this.destination.next(innerValue); }; OuterSubscriber.prototype.notifyError = function (error, innerSub) { this.destination.error(error); }; OuterSubscriber.prototype.notifyComplete = function (innerSub) { this.destination.complete(); }; return OuterSubscriber; }(Subscriber)); /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */ var InnerSubscriber = /*@__PURE__*/ (function (_super) { __extends$1(InnerSubscriber, _super); function InnerSubscriber(parent, outerValue, outerIndex) { var _this = _super.call(this) || this; _this.parent = parent; _this.outerValue = outerValue; _this.outerIndex = outerIndex; _this.index = 0; return _this; } InnerSubscriber.prototype._next = function (value) { this.parent.notifyNext(this.outerValue, value, this.outerIndex, this.index++, this); }; InnerSubscriber.prototype._error = function (error) { this.parent.notifyError(error, this); this.unsubscribe(); }; InnerSubscriber.prototype._complete = function () { this.parent.notifyComplete(this); this.unsubscribe(); }; return InnerSubscriber; }(Subscriber)); /** PURE_IMPORTS_START _Subscriber PURE_IMPORTS_END */ function canReportError(observer) { while (observer) { var _a = observer, closed_1 = _a.closed, destination = _a.destination, isStopped = _a.isStopped; if (closed_1 || isStopped) { return false; } else if (destination && destination instanceof Subscriber) { observer = destination; } else { observer = null; } } return true; } /** PURE_IMPORTS_START _Subscriber,_symbol_rxSubscriber,_Observer PURE_IMPORTS_END */ function toSubscriber(nextOrObserver, error, complete) { if (nextOrObserver) { if (nextOrObserver instanceof Subscriber) { return nextOrObserver; } if (nextOrObserver[rxSubscriber]) { return nextOrObserver[rxSubscriber](); } } if (!nextOrObserver && !error && !complete) { return new Subscriber(empty); } return new Subscriber(nextOrObserver, error, complete); } /** PURE_IMPORTS_START PURE_IMPORTS_END */ var observable = typeof Symbol === 'function' && Symbol.observable || '@@observable'; /** PURE_IMPORTS_START PURE_IMPORTS_END */ function noop() { } /** PURE_IMPORTS_START _noop PURE_IMPORTS_END */ function pipeFromArray(fns) { if (!fns) { return noop; } if (fns.length === 1) { return fns[0]; } return function piped(input) { return fns.reduce(function (prev, fn) { return fn(prev); }, input); }; } /** PURE_IMPORTS_START _util_canReportError,_util_toSubscriber,_internal_symbol_observable,_util_pipe,_config PURE_IMPORTS_END */ var Observable = /*@__PURE__*/ (function () { function Observable(subscribe) { this._isScalar = false; if (subscribe) { this._subscribe = subscribe; } } Observable.prototype.lift = function (operator) { var observable = new Observable(); observable.source = this; observable.operator = operator; return observable; }; Observable.prototype.subscribe = function (observerOrNext, error, complete) { var operator = this.operator; var sink = toSubscriber(observerOrNext, error, complete); if (operator) { operator.call(sink, this.source); } else { sink.add(this.source || (config.useDeprecatedSynchronousErrorHandling && !sink.syncErrorThrowable) ? this._subscribe(sink) : this._trySubscribe(sink)); } if (config.useDeprecatedSynchronousErrorHandling) { if (sink.syncErrorThrowable) { sink.syncErrorThrowable = false; if (sink.syncErrorThrown) { throw sink.syncErrorValue; } } } return sink; }; Observable.prototype._trySubscribe = function (sink) { try { return this._subscribe(sink); } catch (err) { if (config.useDeprecatedSynchronousErrorHandling) { sink.syncErrorThrown = true; sink.syncErrorValue = err; } if (canReportError(sink)) { sink.error(err); } else { console.warn(err); } } }; Observable.prototype.forEach = function (next, promiseCtor) { var _this = this; promiseCtor = getPromiseCtor(promiseCtor); return new promiseCtor(function (resolve, reject) { var subscription; subscription = _this.subscribe(function (value) { try { next(value); } catch (err) { reject(err); if (subscription) { subscription.unsubscribe(); } } }, reject, resolve); }); }; Observable.prototype._subscribe = function (subscriber) { var source = this.source; return source && source.subscribe(subscriber); }; Observable.prototype[observable] = function () { return this; }; Observable.prototype.pipe = function () { var operations = []; for (var _i = 0; _i < arguments.length; _i++) { operations[_i] = arguments[_i]; } if (operations.length === 0) { return this; } return pipeFromArray(operations)(this); }; Observable.prototype.toPromise = function (promiseCtor) { var _this = this; promiseCtor = getPromiseCtor(promiseCtor); return new promiseCtor(function (resolve, reject) { var value; _this.subscribe(function (x) { return value = x; }, function (err) { return reject(err); }, function () { return resolve(value); }); }); }; Observable.create = function (subscribe) { return new Observable(subscribe); }; return Observable; }()); function getPromiseCtor(promiseCtor) { if (!promiseCtor) { promiseCtor = Promise; } if (!promiseCtor) { throw new Error('no Promise impl found'); } return promiseCtor; } /** PURE_IMPORTS_START PURE_IMPORTS_END */ var subscribeToArray = function (array) { return function (subscriber) { for (var i = 0, len = array.length; i < len && !subscriber.closed; i++) { subscriber.next(array[i]); } if (!subscriber.closed) { subscriber.complete(); } }; }; /** PURE_IMPORTS_START _hostReportError PURE_IMPORTS_END */ var subscribeToPromise = function (promise) { return function (subscriber) { promise.then(function (value) { if (!subscriber.closed) { subscriber.next(value); subscriber.complete(); } }, function (err) { return subscriber.error(err); }) .then(null, hostReportError); return subscriber; }; }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ function getSymbolIterator() { if (typeof Symbol !== 'function' || !Symbol.iterator) { return '@@iterator'; } return Symbol.iterator; } var iterator = /*@__PURE__*/ getSymbolIterator(); /** PURE_IMPORTS_START _symbol_iterator PURE_IMPORTS_END */ var subscribeToIterable = function (iterable) { return function (subscriber) { var iterator$1 = iterable[iterator](); do { var item = iterator$1.next(); if (item.done) { subscriber.complete(); break; } subscriber.next(item.value); if (subscriber.closed) { break; } } while (true); if (typeof iterator$1.return === 'function') { subscriber.add(function () { if (iterator$1.return) { iterator$1.return(); } }); } return subscriber; }; }; /** PURE_IMPORTS_START _symbol_observable PURE_IMPORTS_END */ var subscribeToObservable = function (obj) { return function (subscriber) { var obs = obj[observable](); if (typeof obs.subscribe !== 'function') { throw new TypeError('Provided object does not correctly implement Symbol.observable'); } else { return obs.subscribe(subscriber); } }; }; /** PURE_IMPORTS_START PURE_IMPORTS_END */ var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; }); /** PURE_IMPORTS_START PURE_IMPORTS_END */ function isPromise(value) { return value && typeof value.subscribe !== 'function' && typeof value.then === 'function'; } /** PURE_IMPORTS_START _Observable,_subscribeToArray,_subscribeToPromise,_subscribeToIterable,_subscribeToObservable,_isArrayLike,_isPromise,_isObject,_symbol_iterator,_symbol_observable PURE_IMPORTS_END */ var subscribeTo = function (result) { if (result instanceof Observable) { return function (subscriber) { if (result._isScalar) { subscriber.next(result.value); subscriber.complete(); return undefined; } else { return result.subscribe(subscriber); } }; } else if (result && typeof result[observable] === 'function') { return subscribeToObservable(result); } else if (isArrayLike(result)) { return subscribeToArray(result); } else if (isPromise(result)) { return subscribeToPromise(result); } else if (result && typeof result[iterator] === 'function') { return subscribeToIterable(result); } else { var value = isObject(result) ? 'an invalid object' : "'" + result + "'"; var msg = "You provided " + value + " where a stream was expected." + ' You can provide an Observable, Promise, Array, or Iterable.'; throw new TypeError(msg); } }; /** PURE_IMPORTS_START _InnerSubscriber,_subscribeTo PURE_IMPORTS_END */ function subscribeToResult(outerSubscriber, result, outerValue, outerIndex, destination) { if (destination === void 0) { destination = new InnerSubscriber(outerSubscriber, outerValue, outerIndex); } if (destination.closed) { return; } return subscribeTo(result)(destination); } /** PURE_IMPORTS_START tslib,_OuterSubscriber,_InnerSubscriber,_util_subscribeToResult PURE_IMPORTS_END */ function catchError(selector) { return function catchErrorOperatorFunction(source) { var operator = new CatchOperator(selector); var caught = source.lift(operator); return (operator.caught = caught); }; } var CatchOperator = /*@__PURE__*/ (function () { function CatchOperator(selector) { this.selector = selector; } CatchOperator.prototype.call = function (subscriber, source) { return source.subscribe(new CatchSubscriber(subscriber, this.selector, this.caught)); }; return CatchOperator; }()); var CatchSubscriber = /*@__PURE__*/ (function (_super) { __extends$1(CatchSubscriber, _super); function CatchSubscriber(destination, selector, caught) { var _this = _super.call(this, destination) || this; _this.selector = selector; _this.caught = caught; return _this; } CatchSubscriber.prototype.error = function (err) { if (!this.isStopped) { var result = void 0; try { result = this.selector(err, this.caught); } catch (err2) { _super.prototype.error.call(this, err2); return; } this._unsubscribeAndRecycle(); var innerSubscriber = new InnerSubscriber(this, undefined, undefined); this.add(innerSubscriber); subscribeToResult(this, result, undefined, undefined, innerSubscriber); } }; return CatchSubscriber; }(OuterSubscriber)); /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */ function map(project, thisArg) { return function mapOperation(source) { if (typeof project !== 'function') { throw new TypeError('argument is not a function. Are you looking for `mapTo()`?'); } return source.lift(new MapOperator(project, thisArg)); }; } var MapOperator = /*@__PURE__*/ (function () { function MapOperator(project, thisArg) { this.project = project; this.thisArg = thisArg; } MapOperator.prototype.call = function (subscriber, source) { return source.subscribe(new MapSubscriber(subscriber, this.project, this.thisArg)); }; return MapOperator; }()); var MapSubscriber = /*@__PURE__*/ (function (_super) { __extends$1(MapSubscriber, _super); function MapSubscriber(destination, project, thisArg) { var _this = _super.call(this, destination) || this; _this.project = project; _this.count = 0; _this.thisArg = thisArg || _this; return _this; } MapSubscriber.prototype._next = function (value) { var result; try { result = this.project.call(this.thisArg, value, this.count++); } catch (err) { this.destination.error(err); return; } this.destination.next(result); }; return MapSubscriber; }(Subscriber)); function __extends(d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var BaseService = /** @class */ (function () { function BaseService(http) { this.http = http; } BaseService.prototype.get = function (path, options) { if (options === void 0) { options = {}; } return this.http.get(path, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; BaseService.prototype.post = function (path, body, options) { if (options === void 0) { options = {}; } return this.http.post(path, body, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; BaseService.prototype.put = function (path, body, options) { if (options === void 0) { options = {}; } return this.http.put(path, body, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; BaseService.prototype.delete = function (path, options) { if (options === void 0) { options = {}; } return this.http.delete(path, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; BaseService.prototype.handleError = function (error) { return rxjs.throwError(error.message || error); }; return BaseService; }()); var RestService = /** @class */ (function (_super) { __extends(RestService, _super); function RestService(http) { var _this = _super.call(this, http) || this; _this.headers = { 'Content-Type': 'application/json' }; _this.http = http; return _this; } RestService.prototype.query = function (options, path) { if (options === void 0) { options = {}; } if (path === void 0) { path = null; } var finalPath = path != null ? path : this.getBaseUrlPath(); return this.http.get(finalPath, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; RestService.prototype.getResponse = function (options, path) { if (options === void 0) { options = {}; } if (path === void 0) { path = null; } var finalPath = path != null ? path : this.getBaseUrlPath(); options['observe'] = 'response'; return this.http.get(finalPath, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; RestService.prototype.getAll = function (path) { if (path === void 0) { path = null; } return this.query({}, path); }; RestService.prototype.getOne = function (id, options, path) { if (options === void 0) { options = {}; } if (path === void 0) { path = null; } var finalPath = path != null ? path : this.getBaseUrlPath(); var url = finalPath + (id != null ? '/' + id : ''); return this.http.get(url, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; RestService.prototype.createOne = function (model, options, path) { if (options === void 0) { options = { headers: this.headers }; } if (path === void 0) { path = null; } var finalPath = path != null ? path : this.getBaseUrlPath(); return this.http.post(finalPath, model, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; RestService.prototype.updateOne = function (model, options, path) { if (options === void 0) { options = { headers: this.headers }; } if (path === void 0) { path = null; } var finalPath = path != null ? path : this.getBaseUrlPath(); var url = finalPath + (model['id'] != null ? '/' + model['id'] : ''); return this.http.put(url, model, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; RestService.prototype.deleteOne = function (id, options, path) { if (options === void 0) { options = { headers: this.headers }; } if (path === void 0) { path = null; } var finalPath = path != null ? path : this.getBaseUrlPath(); var url = finalPath + (id != null ? '/' + id : ''); return this.http.delete(url, options) .pipe(map(function (response) { return response; }), catchError(this.handleError)); }; return RestService; }(BaseService)); var GenericResponse = /** @class */ (function () { function GenericResponse() { this.data = new Map(); } return GenericResponse; }()); var ResourceResponseBase = /** @class */ (function () { function ResourceResponseBase() { } return ResourceResponseBase; }()); var ResourceResponse = /** @class */ (function (_super) { __extends(ResourceResponse, _super); function ResourceResponse() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.data = null; return _this; } return ResourceResponse; }(ResourceResponseBase)); var ResourceResponseList = /** @class */ (function (_super) { __extends(ResourceResponseList, _super); function ResourceResponseList() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.data = []; return _this; } return ResourceResponseList; }(ResourceResponseBase)); exports.GenericResponse = GenericResponse; exports.ResourceResponse = ResourceResponse; exports.ResourceResponseList = ResourceResponseList; exports.RestService = RestService; Object.defineProperty(exports, '__esModule', { value: true }); }));