Skip to content
Snippets Groups Projects
index.js 8.81 MiB
Newer Older
  • Learn to ignore specific revisions
  • function gotAccum(accum) {
        this.accum = accum;
        this.array._gotAccum(accum);
        var value = tryConvertToPromise(this.value, this.array._promise);
        if (value instanceof Promise) {
            this.array._currentCancellable = value;
            return value._then(gotValue, undefined, undefined, this, undefined);
        } else {
            return gotValue.call(this, value);
    
    Romain CREY's avatar
    Romain CREY committed
        }
    
    function gotValue(value) {
        var array = this.array;
        var promise = array._promise;
        var fn = tryCatch(array._fn);
        promise._pushContext();
        var ret;
        if (array._eachValues !== undefined) {
            ret = fn.call(promise._boundValue(), value, this.index, this.length);
        } else {
            ret = fn.call(promise._boundValue(),
                                  this.accum, value, this.index, this.length);
    
        if (ret instanceof Promise) {
            array._currentCancellable = ret;
        }
        var promiseCreated = promise._popContext();
        debug.checkForgottenReturns(
            ret,
            promiseCreated,
            array._eachValues !== undefined ? "Promise.each" : "Promise.reduce",
            promise
        );
        return ret;
    
    Romain CREY's avatar
    Romain CREY committed
    };
    
    
    /***/ }),
    
    /* 35 */
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    Romain CREY's avatar
    Romain CREY committed
    
    "use strict";
    
    
    module.exports =
        function(Promise, PromiseArray, debug) {
    var PromiseInspection = Promise.PromiseInspection;
    var util = __webpack_require__(7);
    
    function SettledPromiseArray(values) {
        this.constructor$(values);
    }
    util.inherits(SettledPromiseArray, PromiseArray);
    
    SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
        this._values[index] = inspection;
        var totalResolved = ++this._totalResolved;
        if (totalResolved >= this._length) {
            this._resolve(this._values);
            return true;
        }
        return false;
    };
    
    SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
        var ret = new PromiseInspection();
        ret._bitField = 33554432;
        ret._settledValueField = value;
        return this._promiseResolved(index, ret);
    };
    SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
        var ret = new PromiseInspection();
        ret._bitField = 16777216;
        ret._settledValueField = reason;
        return this._promiseResolved(index, ret);
    };
    
    Promise.settle = function (promises) {
        debug.deprecated(".settle()", ".reflect()");
        return new SettledPromiseArray(promises).promise();
    };
    
    Promise.allSettled = function (promises) {
        return new SettledPromiseArray(promises).promise();
    };
    
    Promise.prototype.settle = function () {
        return Promise.settle(this);
    };
    };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    /***/ }),
    /* 36 */
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    module.exports =
    function(Promise, PromiseArray, apiRejection) {
    var util = __webpack_require__(7);
    
    var RangeError = (__webpack_require__(13).RangeError);
    var AggregateError = (__webpack_require__(13).AggregateError);
    
    var isArray = util.isArray;
    var CANCELLATION = {};
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    function SomePromiseArray(values) {
        this.constructor$(values);
        this._howMany = 0;
        this._unwrap = false;
        this._initialized = false;
    }
    util.inherits(SomePromiseArray, PromiseArray);
    
    SomePromiseArray.prototype._init = function () {
        if (!this._initialized) {
            return;
        }
        if (this._howMany === 0) {
            this._resolve([]);
            return;
        }
        this._init$(undefined, -5);
        var isArrayResolved = isArray(this._values);
        if (!this._isResolved() &&
            isArrayResolved &&
            this._howMany > this._canPossiblyFulfill()) {
            this._reject(this._getRangeError(this.length()));
        }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    SomePromiseArray.prototype.init = function () {
        this._initialized = true;
        this._init();
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    SomePromiseArray.prototype.setUnwrap = function () {
        this._unwrap = true;
    
    SomePromiseArray.prototype.howMany = function () {
        return this._howMany;
    
    SomePromiseArray.prototype.setHowMany = function (count) {
        this._howMany = count;
    
    SomePromiseArray.prototype._promiseFulfilled = function (value) {
        this._addFulfilled(value);
        if (this._fulfilled() === this.howMany()) {
            this._values.length = this.howMany();
            if (this.howMany() === 1 && this._unwrap) {
                this._resolve(this._values[0]);
            } else {
                this._resolve(this._values);
            }
            return true;
        }
        return false;
    
    };
    SomePromiseArray.prototype._promiseRejected = function (reason) {
        this._addRejected(reason);
        return this._checkOutcome();
    
    SomePromiseArray.prototype._promiseCancelled = function () {
        if (this._values instanceof Promise || this._values == null) {
            return this._cancel();
        }
        this._addRejected(CANCELLATION);
        return this._checkOutcome();
    
    SomePromiseArray.prototype._checkOutcome = function() {
        if (this.howMany() > this._canPossiblyFulfill()) {
            var e = new AggregateError();
            for (var i = this.length(); i < this._values.length; ++i) {
                if (this._values[i] !== CANCELLATION) {
                    e.push(this._values[i]);
                }
            }
            if (e.length > 0) {
                this._reject(e);
            } else {
                this._cancel();
            }
            return true;
    
    SomePromiseArray.prototype._fulfilled = function () {
        return this._totalResolved;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    SomePromiseArray.prototype._rejected = function () {
        return this._values.length - this.length();
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    SomePromiseArray.prototype._addRejected = function (reason) {
        this._values.push(reason);
    
    SomePromiseArray.prototype._addFulfilled = function (value) {
        this._values[this._totalResolved++] = value;
    
    SomePromiseArray.prototype._canPossiblyFulfill = function () {
        return this.length() - this._rejected();
    
    SomePromiseArray.prototype._getRangeError = function (count) {
        var message = "Input array must contain at least " +
                this._howMany + " items but contains only " + count + " items";
        return new RangeError(message);
    
    SomePromiseArray.prototype._resolveEmptyArray = function () {
        this._reject(this._getRangeError(0));
    };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    function some(promises, howMany) {
        if ((howMany | 0) !== howMany || howMany < 0) {
            return apiRejection("expecting a positive integer\u000a\u000a    See http://goo.gl/MqrFmX\u000a");
    
        var ret = new SomePromiseArray(promises);
        var promise = ret.promise();
        ret.setHowMany(howMany);
        ret.init();
        return promise;
    }
    
    Promise.some = function (promises, howMany) {
        return some(promises, howMany);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Promise.prototype.some = function (howMany) {
        return some(this, howMany);
    };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Promise._SomePromiseArray = SomePromiseArray;
    };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    /***/ }),
    /* 37 */
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    module.exports = function(Promise, INTERNAL, debug) {
    var util = __webpack_require__(7);
    var TimeoutError = Promise.TimeoutError;
    
    function HandleWrapper(handle)  {
        this.handle = handle;
    }
    
    HandleWrapper.prototype._resultCancelled = function() {
        clearTimeout(this.handle);
    
    var afterValue = function(value) { return delay(+this).thenReturn(value); };
    var delay = Promise.delay = function (ms, value) {
        var ret;
        var handle;
        if (value !== undefined) {
            ret = Promise.resolve(value)
                    ._then(afterValue, null, null, ms, undefined);
            if (debug.cancellation() && value instanceof Promise) {
                ret._setOnCancel(value);
    
        } else {
            ret = new Promise(INTERNAL);
            handle = setTimeout(function() { ret._fulfill(); }, +ms);
            if (debug.cancellation()) {
                ret._setOnCancel(new HandleWrapper(handle));
    
            ret._captureStackTrace();
    
        ret._setAsyncGuaranteed();
        return ret;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Promise.prototype.delay = function (ms) {
        return delay(ms, this);
    
    var afterTimeout = function (promise, message, parent) {
        var err;
        if (typeof message !== "string") {
            if (message instanceof Error) {
                err = message;
    
            } else {
    
                err = new TimeoutError("operation timed out");
    
        } else {
    
            err = new TimeoutError(message);
    
        util.markAsOriginatingFromRejection(err);
        promise._attachExtraTrace(err);
        promise._reject(err);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        if (parent != null) {
            parent.cancel();
        }
    };
    
    function successClear(value) {
        clearTimeout(this.handle);
        return value;
    
    function failureClear(reason) {
        clearTimeout(this.handle);
        throw reason;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Promise.prototype.timeout = function (ms, message) {
        ms = +ms;
        var ret, parent;
    
        var handleWrapper = new HandleWrapper(setTimeout(function timeoutTimeout() {
            if (ret.isPending()) {
                afterTimeout(ret, message, parent);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        if (debug.cancellation()) {
            parent = this.then();
            ret = parent._then(successClear, failureClear,
                                undefined, handleWrapper, undefined);
            ret._setOnCancel(handleWrapper);
        } else {
            ret = this._then(successClear, failureClear,
                                undefined, handleWrapper, undefined);
    
        return ret;
    
    /***/ }),
    /* 38 */
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    module.exports = function (Promise, apiRejection, tryConvertToPromise,
        createContext, INTERNAL, debug) {
        var util = __webpack_require__(7);
    
        var TypeError = (__webpack_require__(13).TypeError);
        var inherits = (__webpack_require__(7).inherits);
    
        var errorObj = util.errorObj;
        var tryCatch = util.tryCatch;
        var NULL = {};
    
        function thrower(e) {
            setTimeout(function(){throw e;}, 0);
        }
    
        function castPreservingDisposable(thenable) {
            var maybePromise = tryConvertToPromise(thenable);
            if (maybePromise !== thenable &&
                typeof thenable._isDisposable === "function" &&
                typeof thenable._getDisposer === "function" &&
                thenable._isDisposable()) {
                maybePromise._setDisposable(thenable._getDisposer());
            }
            return maybePromise;
        }
        function dispose(resources, inspection) {
            var i = 0;
            var len = resources.length;
            var ret = new Promise(INTERNAL);
            function iterator() {
                if (i >= len) return ret._fulfill();
                var maybePromise = castPreservingDisposable(resources[i++]);
                if (maybePromise instanceof Promise &&
                    maybePromise._isDisposable()) {
                    try {
                        maybePromise = tryConvertToPromise(
                            maybePromise._getDisposer().tryDispose(inspection),
                            resources.promise);
                    } catch (e) {
                        return thrower(e);
                    }
                    if (maybePromise instanceof Promise) {
                        return maybePromise._then(iterator, thrower,
                                                  null, null, null);
    
            iterator();
            return ret;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        function Disposer(data, promise, context) {
            this._data = data;
            this._promise = promise;
            this._context = context;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        Disposer.prototype.data = function () {
            return this._data;
        };
    
        Disposer.prototype.promise = function () {
            return this._promise;
        };
    
        Disposer.prototype.resource = function () {
            if (this.promise().isFulfilled()) {
                return this.promise().value();
    
        Disposer.prototype.tryDispose = function(inspection) {
            var resource = this.resource();
            var context = this._context;
            if (context !== undefined) context._pushContext();
            var ret = resource !== NULL
                ? this.doDispose(resource, inspection) : null;
            if (context !== undefined) context._popContext();
            this._promise._unsetDisposable();
            this._data = null;
            return ret;
        };
    
        Disposer.isDisposer = function (d) {
            return (d != null &&
                    typeof d.resource === "function" &&
                    typeof d.tryDispose === "function");
        };
    
        function FunctionDisposer(fn, promise, context) {
            this.constructor$(fn, promise, context);
    
        inherits(FunctionDisposer, Disposer);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        FunctionDisposer.prototype.doDispose = function (resource, inspection) {
            var fn = this.data();
            return fn.call(resource, resource, inspection);
        };
    
        function maybeUnwrapDisposer(value) {
            if (Disposer.isDisposer(value)) {
                this.resources[this.index]._setDisposable(value);
                return value.promise();
    
    
        function ResourceList(length) {
            this.length = length;
            this.promise = null;
            this[length-1] = null;
    
        ResourceList.prototype._resultCancelled = function() {
            var len = this.length;
            for (var i = 0; i < len; ++i) {
                var item = this[i];
                if (item instanceof Promise) {
                    item.cancel();
                }
            }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        Promise.using = function () {
            var len = arguments.length;
            if (len < 2) return apiRejection(
                            "you must pass at least 2 arguments to Promise.using");
            var fn = arguments[len - 1];
            if (typeof fn !== "function") {
                return apiRejection("expecting a function but got " + util.classString(fn));
            }
            var input;
            var spreadArgs = true;
            if (len === 2 && Array.isArray(arguments[0])) {
                input = arguments[0];
                len = input.length;
                spreadArgs = false;
    
            } else {
    
                input = arguments;
                len--;
    
            var resources = new ResourceList(len);
            for (var i = 0; i < len; ++i) {
                var resource = input[i];
                if (Disposer.isDisposer(resource)) {
                    var disposer = resource;
                    resource = resource.promise();
                    resource._setDisposable(disposer);
                } else {
                    var maybePromise = tryConvertToPromise(resource);
                    if (maybePromise instanceof Promise) {
                        resource =
                            maybePromise._then(maybeUnwrapDisposer, null, null, {
                                resources: resources,
                                index: i
                        }, undefined);
                    }
                }
                resources[i] = resource;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            var reflectedResources = new Array(resources.length);
            for (var i = 0; i < reflectedResources.length; ++i) {
                reflectedResources[i] = Promise.resolve(resources[i]).reflect();
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            var resultPromise = Promise.all(reflectedResources)
                .then(function(inspections) {
                    for (var i = 0; i < inspections.length; ++i) {
                        var inspection = inspections[i];
                        if (inspection.isRejected()) {
                            errorObj.e = inspection.error();
                            return errorObj;
                        } else if (!inspection.isFulfilled()) {
                            resultPromise.cancel();
                            return;
                        }
                        inspections[i] = inspection.value();
                    }
                    promise._pushContext();
    
    Romain CREY's avatar
    Romain CREY committed
    
    
                    fn = tryCatch(fn);
                    var ret = spreadArgs
                        ? fn.apply(undefined, inspections) : fn(inspections);
                    var promiseCreated = promise._popContext();
                    debug.checkForgottenReturns(
                        ret, promiseCreated, "Promise.using", promise);
                    return ret;
                });
    
            var promise = resultPromise.lastly(function() {
                var inspection = new Promise.PromiseInspection(resultPromise);
                return dispose(resources, inspection);
            });
            resources.promise = promise;
            promise._setOnCancel(resources);
            return promise;
        };
    
        Promise.prototype._setDisposable = function (disposer) {
            this._bitField = this._bitField | 131072;
            this._disposer = disposer;
        };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        Promise.prototype._isDisposable = function () {
            return (this._bitField & 131072) > 0;
    
        Promise.prototype._getDisposer = function () {
            return this._disposer;
        };
    
        Promise.prototype._unsetDisposable = function () {
            this._bitField = this._bitField & (~131072);
            this._disposer = undefined;
        };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        Promise.prototype.disposer = function (fn) {
            if (typeof fn === "function") {
                return new FunctionDisposer(fn, this, createContext());
    
            throw new TypeError();
        };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    /***/ }),
    /* 39 */
    /***/ ((module) => {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    module.exports = function(Promise) {
    var SomePromiseArray = Promise._SomePromiseArray;
    function any(promises) {
        var ret = new SomePromiseArray(promises);
        var promise = ret.promise();
        ret.setHowMany(1);
        ret.setUnwrap();
        ret.init();
        return promise;
    }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Promise.any = function (promises) {
        return any(promises);
    };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Promise.prototype.any = function () {
        return any(this);
    };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    /***/ }),
    /* 40 */
    /***/ ((module) => {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    module.exports = function(Promise, INTERNAL) {
    var PromiseReduce = Promise.reduce;
    var PromiseAll = Promise.all;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    function promiseAllThis() {
        return PromiseAll(this);
    }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    function PromiseMapSeries(promises, fn) {
        return PromiseReduce(promises, fn, INTERNAL, INTERNAL);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Promise.prototype.each = function (fn) {
        return PromiseReduce(this, fn, INTERNAL, 0)
                  ._then(promiseAllThis, undefined, undefined, this, undefined);
    
    Promise.prototype.mapSeries = function (fn) {
        return PromiseReduce(this, fn, INTERNAL, INTERNAL);
    };
    
    Promise.each = function (promises, fn) {
        return PromiseReduce(promises, fn, INTERNAL, 0)
                  ._then(promiseAllThis, undefined, undefined, promises, undefined);
    
    
    Promise.mapSeries = PromiseMapSeries;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    Romain CREY's avatar
    Romain CREY committed
    /***/ }),
    
    /* 41 */
    /***/ ((module) => {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    "use strict";
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    module.exports = function(Promise, INTERNAL) {
    var PromiseMap = Promise.map;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Promise.prototype.filter = function (fn, options) {
        return PromiseMap(this, fn, options, INTERNAL);
    };
    
    Promise.filter = function (promises, fn, options) {
        return PromiseMap(promises, fn, options, INTERNAL);
    };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    /***/ }),
    /* 42 */
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    var core = __webpack_require__(43),
        isArray = __webpack_require__(55),
        isFunction = __webpack_require__(45),
        isObjectLike = __webpack_require__(53);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    module.exports = function (options) {
    
        var errorText = 'Please verify options'; // For better minification because this string is repeating
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        if (!isObjectLike(options)) {
            throw new TypeError(errorText);
        }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        if (!isFunction(options.request)) {
            throw new TypeError(errorText + '.request');
        }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        if (!isArray(options.expose) || options.expose.length === 0) {
            throw new TypeError(errorText + '.expose');
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
        var plumbing = core({
            PromiseImpl: options.PromiseImpl,
            constructorMixin: options.constructorMixin
        });
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
        // Intercepting Request's init method
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        var originalInit = options.request.Request.prototype.init;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        options.request.Request.prototype.init = function RP$initInterceptor(requestOptions) {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            // Init may be called again - currently in case of redirects
            if (isObjectLike(requestOptions) && !this._callback && !this._rp_promise) {
    
                plumbing.init.call(this, requestOptions);
    
            return originalInit.apply(this, arguments);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        // Exposing the Promise capabilities
    
        var thenExposed = false;
        for ( var i = 0; i < options.expose.length; i+=1 ) {
    
            var method = options.expose[i];
    
            plumbing[ method === 'promise' ? 'exposePromise' : 'exposePromiseMethod' ](
                options.request.Request.prototype,
                null,
                '_rp_promise',
                method
            );
    
            if (method === 'then') {
                thenExposed = true;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        if (!thenExposed) {
            throw new Error('Please expose "then"');
        }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    /***/ }),
    
    /* 43 */
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    "use strict";
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    var errors = __webpack_require__(44),
        isFunction = __webpack_require__(45),
        isObjectLike = __webpack_require__(53),
        isString = __webpack_require__(54),
        isUndefined = __webpack_require__(56);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
    module.exports = function (options) {
    
        var errorText = 'Please verify options'; // For better minification because this string is repeating
    
        if (!isObjectLike(options)) {
            throw new TypeError(errorText);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        if (!isFunction(options.PromiseImpl)) {
            throw new TypeError(errorText + '.PromiseImpl');
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        if (!isUndefined(options.constructorMixin) && !isFunction(options.constructorMixin)) {
            throw new TypeError(errorText + '.PromiseImpl');
        }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        var PromiseImpl = options.PromiseImpl;
        var constructorMixin = options.constructorMixin;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    
        var plumbing = {};
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        plumbing.init = function (requestOptions) {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            var self = this;
    
            self._rp_promise = new PromiseImpl(function (resolve, reject) {
                self._rp_resolve = resolve;
                self._rp_reject = reject;
                if (constructorMixin) {
                    constructorMixin.apply(self, arguments); // Using arguments since specific Promise libraries may pass additional parameters
                }
            });
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            self._rp_callbackOrig = requestOptions.callback;
            requestOptions.callback = self.callback = function RP$callback(err, response, body) {
                plumbing.callback.call(self, err, response, body);
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            if (isString(requestOptions.method)) {
                requestOptions.method = requestOptions.method.toUpperCase();
            }
    
            requestOptions.transform = requestOptions.transform || plumbing.defaultTransformations[requestOptions.method];
    
            self._rp_options = requestOptions;
            self._rp_options.simple = requestOptions.simple !== false;
            self._rp_options.resolveWithFullResponse = requestOptions.resolveWithFullResponse === true;
            self._rp_options.transform2xxOnly = requestOptions.transform2xxOnly === true;
    
        plumbing.defaultTransformations = {
            HEAD: function (body, response, resolveWithFullResponse) {
                return resolveWithFullResponse ? response : response.headers;
            }
        };
    
    Romain CREY's avatar
    Romain CREY committed
    
    
        plumbing.callback = function (err, response, body) {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            var self = this;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            var origCallbackThrewException = false, thrownException = null;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            if (isFunction(self._rp_callbackOrig)) {
                try {
                    self._rp_callbackOrig.apply(self, arguments); // TODO: Apply to self mimics behavior of request@2. Is that also right for request@next?
                } catch (e) {
                    origCallbackThrewException = true;
                    thrownException = e;
    
            var is2xx = !err && /^2/.test('' + response.statusCode);
    
            if (err) {
    
                self._rp_reject(new errors.RequestError(err, self._rp_options, response));
    
            } else if (self._rp_options.simple && !is2xx) {
    
                if (isFunction(self._rp_options.transform) && self._rp_options.transform2xxOnly === false) {
    
                    (new PromiseImpl(function (resolve) {
                        resolve(self._rp_options.transform(body, response, self._rp_options.resolveWithFullResponse)); // transform may return a Promise
                    }))
                        .then(function (transformedResponse) {
                            self._rp_reject(new errors.StatusCodeError(response.statusCode, body, self._rp_options, transformedResponse));
                        })
                        .catch(function (transformErr) {
                            self._rp_reject(new errors.TransformError(transformErr, self._rp_options, response));
                        });
    
    
                } else {
    
                    self._rp_reject(new errors.StatusCodeError(response.statusCode, body, self._rp_options, response));
    
            } else {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
                if (isFunction(self._rp_options.transform) && (is2xx || self._rp_options.transform2xxOnly === false)) {
    
    Romain CREY's avatar
    Romain CREY committed
    
    
                    (new PromiseImpl(function (resolve) {
                        resolve(self._rp_options.transform(body, response, self._rp_options.resolveWithFullResponse)); // transform may return a Promise
                    }))
                        .then(function (transformedResponse) {
                            self._rp_resolve(transformedResponse);
                        })
                        .catch(function (transformErr) {
                            self._rp_reject(new errors.TransformError(transformErr, self._rp_options, response));
                        });
    
                } else if (self._rp_options.resolveWithFullResponse) {
                    self._rp_resolve(response);
                } else {
                    self._rp_resolve(body);
                }
    
    Romain CREY's avatar
    Romain CREY committed
    
    
            if (origCallbackThrewException) {
                throw thrownException;
            }
    
        plumbing.exposePromiseMethod = function (exposeTo, bindTo, promisePropertyKey, methodToExpose, exposeAs) {
    
            exposeAs = exposeAs || methodToExpose;
    
            if (exposeAs in exposeTo) {
                throw new Error('Unable to expose method "' + exposeAs + '"');
            }
    
            exposeTo[exposeAs] = function RP$exposed() {
                var self = bindTo || this;
                return self[promisePropertyKey][methodToExpose].apply(self[promisePropertyKey], arguments);
            };
    
        };
    
        plumbing.exposePromise = function (exposeTo, bindTo, promisePropertyKey, exposeAs) {
    
            exposeAs = exposeAs || 'promise';
    
            if (exposeAs in exposeTo) {
                throw new Error('Unable to expose method "' + exposeAs + '"');
    
            exposeTo[exposeAs] = function RP$promise() {
                var self = bindTo || this;
                return self[promisePropertyKey];
            };
    
        return plumbing;
    
    /* 44 */
    
    /***/ ((module) => {
    
    function RequestError(cause, options, response) {
    
        this.name = 'RequestError';
        this.message = String(cause);
        this.cause = cause;
        this.error = cause; // legacy attribute
        this.options = options;
        this.response = response;
    
        if (Error.captureStackTrace) { // required for non-V8 environments
            Error.captureStackTrace(this);
    
    }
    RequestError.prototype = Object.create(Error.prototype);
    RequestError.prototype.constructor = RequestError;
    
    function StatusCodeError(statusCode, body, options, response) {
    
        this.name = 'StatusCodeError';
        this.statusCode = statusCode;
        this.message = statusCode + ' - ' + (JSON && JSON.stringify ? JSON.stringify(body) : body);
        this.error = body; // legacy attribute
        this.options = options;
        this.response = response;
    
        if (Error.captureStackTrace) { // required for non-V8 environments
            Error.captureStackTrace(this);
    
    StatusCodeError.prototype = Object.create(Error.prototype);
    StatusCodeError.prototype.constructor = StatusCodeError;
    
    function TransformError(cause, options, response) {
    
        this.name = 'TransformError';
        this.message = String(cause);
        this.cause = cause;
        this.error = cause; // legacy attribute
        this.options = options;
        this.response = response;
    
        if (Error.captureStackTrace) { // required for non-V8 environments
            Error.captureStackTrace(this);
    
    }
    TransformError.prototype = Object.create(Error.prototype);
    TransformError.prototype.constructor = TransformError;
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    module.exports = {
        RequestError: RequestError,
        StatusCodeError: StatusCodeError,
        TransformError: TransformError
    
    Romain CREY's avatar
    Romain CREY committed
    
    
    /***/ }),
    /* 45 */
    /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
    
    var baseGetTag = __webpack_require__(46),
        isObject = __webpack_require__(52);
    
    /** `Object#toString` result references. */
    var asyncTag = '[object AsyncFunction]',
        funcTag = '[object Function]',
        genTag = '[object GeneratorFunction]',