Socket
Socket
Sign inDemoInstall

fetch-actions

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-actions - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

es/handleRequestTransformerActions.js

151

dist/fetch-actions.js

@@ -874,2 +874,3 @@ (function (global, factory) {

fetch = _ref.fetch,
finallyHandler = _ref.finally,
_ref$requestCreator = _ref.requestCreator,

@@ -892,3 +893,3 @@ requestCreator = _ref$requestCreator === void 0 ? identityRequestCreator : _ref$requestCreator,

regenerator.mark(function _callee(action) {
var type, request, response, newResponse, data, result, _result;
var type, errored, request, response, newResponse, data, result, _result;

@@ -901,21 +902,22 @@ return regenerator.wrap(function _callee$(_context) {

!(type !== undefined || typeof type.toString !== 'function') ? invariant(false, '@@fetch-actions/createFetchAction action type must be defined. It is recommended that action be a valid flux-standard-action (https://github.com/acdlite/flux-standard-action)') : void 0;
_context.prev = 2;
_context.next = 5;
errored = false;
_context.prev = 3;
_context.next = 6;
return requestCreator(action);
case 5:
case 6:
request = _context.sent;
if (!request) {
_context.next = 10;
_context.next = 11;
break;
}
_context.next = 9;
_context.next = 10;
return requestTransformer(request, action);
case 9:
case 10:
request = _context.sent;
case 10:
case 11:
if (typeof responder !== 'function' || fetch) {

@@ -930,13 +932,13 @@ !(typeof fetch === 'function') ? invariant(false, '@@fetch-actions/createFetchAction fetch should be a function. createFetchAction requires either fetch or responder to be a function') : void 0;

if (!responder) {
_context.next = 16;
_context.next = 17;
break;
}
_context.next = 15;
_context.next = 16;
return responder(request, action);
case 15:
case 16:
response = _context.sent;
case 16:
case 17:
if (responder && (!fetch || !request)) {

@@ -947,18 +949,18 @@ !response ? invariant(false, "@@fetch-actions/createFetchAction responder must always return a valid (non-falsey) response when ".concat(fetch ? "request is ".concat(request) : 'fetch is undefined')) : void 0;

if (response) {
_context.next = 21;
_context.next = 22;
break;
}
_context.next = 20;
_context.next = 21;
return fetch(request);
case 20:
case 21:
response = _context.sent;
case 21:
case 22:
!(typeof response.json === 'function') ? invariant(false, '@@fetch-actions/createFetchAction fetch or responder must always return a valid response with a json method') : void 0;
_context.next = 24;
_context.next = 25;
return responseHandler(response, action);
case 24:
case 25:
newResponse = _context.sent;

@@ -969,33 +971,33 @@ // TODO: is this the right assumption?

!(typeof newResponse.json === 'function') ? invariant(false, '@@fetch-actions/createFetchAction responseHandler must always return a valid response with a json method') : void 0;
_context.next = 28;
_context.next = 29;
return newResponse.json();
case 28:
case 29:
data = _context.sent;
_context.next = 31;
_context.next = 32;
return transformer(data, action);
case 31:
case 32:
result = _context.sent;
return _context.abrupt("return", result);
case 35:
_context.prev = 35;
_context.t0 = _context["catch"](2);
case 36:
_context.prev = 36;
_context.t0 = _context["catch"](3);
warning(!!fatalHandler, "@@fetch-actions/createFetchAction uncaught fatal error. ".concat(_context.t0.toString(), ". Define a fatalHandler to capture these in your application.")) ;
if (!fatalHandler) {
_context.next = 42;
_context.next = 43;
break;
}
_context.next = 41;
_context.next = 42;
return fatalHandler(_context.t0, action);
case 41:
case 42:
_result = _context.sent;
case 42:
case 43:
if (!(_result !== undefined)) {
_context.next = 44;
_context.next = 45;
break;

@@ -1006,6 +1008,21 @@ }

case 44:
case 45:
errored = true;
throw _context.t0;
case 45:
case 47:
_context.prev = 47;
if (!finallyHandler) {
_context.next = 51;
break;
}
_context.next = 51;
return finallyHandler(action, errored);
case 51:
return _context.finish(47);
case 52:
case "end":

@@ -1015,3 +1032,3 @@ return _context.stop();

}
}, _callee, null, [[2, 35]]);
}, _callee, null, [[3, 36, 47, 52]]);
}));

@@ -1026,3 +1043,20 @@

var DEFAULT_HANDLER = '@@fetch-actions/handleRequestCreatorActions/DEFAULT_HANDLER';
var DEFAULT_HANDLER = '@@fetch-actions/handleRequestTransformerActions/DEFAULT_HANDLER';
var handleRequestTransformerActions = function handleRequestTransformerActions(map) {
return function (request, action) {
var type = selectActionType(action);
var handler = map[type] || map[DEFAULT_HANDLER];
!(type !== undefined) ? invariant(false, '@@fetch-actions/handleRequestTransformerActions action type must be defined. It is recommended that action be a valid flux-standard-action (https://github.com/acdlite/flux-standard-action)') : void 0;
!map ? invariant(false, '@@fetch-actions/handleRequestTransformerActions map must be defined') : void 0;
if (!handler) {
warning(handler, "@@fetch-actions/handleRequestTransformerActions No handler matched action.type of ".concat(type, ". Using identityHandler which simply returns the request unmodified.")) ;
return identityHandler(request);
}
return handler(request, action);
};
};
var DEFAULT_HANDLER$1 = '@@fetch-actions/handleRequestCreatorActions/DEFAULT_HANDLER';
var makeRequest = function makeRequest(request) {

@@ -1048,3 +1082,3 @@ if (typeof request.then === 'function') {

var type = selectActionType(action);
var handler = map[type] || map[DEFAULT_HANDLER];
var handler = map[type] || map[DEFAULT_HANDLER$1];
!(type !== undefined) ? invariant(false, '@@fetch-actions/handleRequestCreatorActions action type must be defined. It is recommended that action be a valid flux-standard-action (https://github.com/acdlite/flux-standard-action)') : void 0;

@@ -1062,3 +1096,3 @@ !map ? invariant(false, '@@fetch-actions/handleRequestCreatorActions map must be defined') : void 0;

var DEFAULT_HANDLER$1 = '@@fetch-actions/handleResponderActions/DEFAULT_HANDLER';
var DEFAULT_HANDLER$2 = '@@fetch-actions/handleResponderActions/DEFAULT_HANDLER';

@@ -1102,3 +1136,3 @@ var isEmpty = function isEmpty(obj) {

!map ? invariant(false, '@@fetch-actions/handleResponderActions map must be defined') : void 0;
var handler = map[type] || map[DEFAULT_HANDLER$1];
var handler = map[type] || map[DEFAULT_HANDLER$2];

@@ -1115,3 +1149,3 @@ if (!handler) {

var DEFAULT_HANDLER$2 = '@@fetch-actions/handleResponseActions/DEFAULT_HANDLER'; // handle thenables and Response objects
var DEFAULT_HANDLER$3 = '@@fetch-actions/handleResponseActions/DEFAULT_HANDLER'; // handle thenables and Response objects

@@ -1135,3 +1169,3 @@ var makeResponse$1 = function makeResponse(response) {

!map ? invariant(false, '@@fetch-actions/handleResponseActions map must be defined') : void 0;
var handler = map[type] || map[DEFAULT_HANDLER$2];
var handler = map[type] || map[DEFAULT_HANDLER$3];

@@ -1176,7 +1210,7 @@ if (!handler) {

var DEFAULT_HANDLER$3 = '@@fetch-actions/handleFatalActions/DEFAULT_HANDLER';
var DEFAULT_HANDLER$4 = '@@fetch-actions/handleFatalActions/DEFAULT_HANDLER';
var handleFatalActions = function handleFatalActions(map) {
return function (error, action) {
var type = selectActionType(action);
var handler = map[type] || map[DEFAULT_HANDLER$3];
var handler = map[type] || map[DEFAULT_HANDLER$4];
!(type !== undefined) ? invariant(false, '@@fetch-actions/handleFatalActions action type must be defined. It is recommended that action be a valid flux-standard-action (https://github.com/acdlite/flux-standard-action)') : void 0;

@@ -1246,2 +1280,5 @@ !map ? invariant(false, '@@fetch-actions/handleFatalActions map must be defined') : void 0;

fetch: fetch,
finally: reduceFinallies.apply(void 0, _toConsumableArray(configs.map(function (c) {
return c.finally;
}).filter(Boolean))),
requestCreator: someRequestCreators.apply(void 0, _toConsumableArray(configs.map(function (c) {

@@ -1269,5 +1306,22 @@ return c.requestCreator;

var reduceFinallies = function reduceFinallies() {
for (var _len5 = arguments.length, finallies = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
finallies[_key5] = arguments[_key5];
}
return function (action, errored) {
return finallies.reduce(function (promise, handler) {
if (isPromise(promise)) {
return promise.then(function () {
return handler(action, errored);
});
}
return handler(action, errored);
}, undefined);
};
};
var reduceHandlers = function reduceHandlers() {
for (var _len5 = arguments.length, handlers = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
handlers[_key5] = arguments[_key5];
for (var _len6 = arguments.length, handlers = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
handlers[_key6] = arguments[_key6];
}

@@ -1288,6 +1342,7 @@

exports.DEFAULT_FATAL_HANDLER = DEFAULT_HANDLER$3;
exports.DEFAULT_REQUEST_CREATOR = DEFAULT_HANDLER;
exports.DEFAULT_REQUEST_HANDLER = DEFAULT_HANDLER$1;
exports.DEFAULT_RESPONSE_HANDLER = DEFAULT_HANDLER$2;
exports.DEFAULT_FATAL_HANDLER = DEFAULT_HANDLER$4;
exports.DEFAULT_REQUEST_CREATOR = DEFAULT_HANDLER$1;
exports.DEFAULT_REQUEST_HANDLER = DEFAULT_HANDLER$2;
exports.DEFAULT_REQUEST_TRANSFORMER = DEFAULT_HANDLER;
exports.DEFAULT_RESPONSE_HANDLER = DEFAULT_HANDLER$3;
exports.DEFAULT_TRANSFORMER = DEFAULT_TRANSFORMER;

@@ -1297,2 +1352,3 @@ exports.createFetchAction = createFetchAction;

exports.handleRequestCreatorActions = handleRequestCreatorActions;
exports.handleRequestTransformerActions = handleRequestTransformerActions;
exports.handleResponderActions = handleResponderActions;

@@ -1309,2 +1365,3 @@ exports.handleResponseActions = handleResponseActions;

exports.reduceConfigs = reduceConfigs;
exports.reduceFinallies = reduceFinallies;
exports.reduceHandlers = reduceHandlers;

@@ -1311,0 +1368,0 @@ exports.someFatalHandlers = someFatalHandlers;

@@ -1,1 +0,1 @@

!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t=t||self).FetchActions={})}(this,(function(t){"use strict";var r=function(t,r){return t(r={exports:{}},r.exports),r.exports}((function(t){var r=function(t){var r,e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,r,e,n){var o=Object.create((r&&r.prototype instanceof v?r:v).prototype),i=new T(n||[]);return o._invoke=function(t,r,e){var n=s;return function(o,i){if(n===h)throw Error("Generator is already running");if(n===p){if("throw"===o)throw i;return F()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=b(a,e);if(u){if(u===y)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===s)throw n=p,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=h;var c=f(t,r,e);if("normal"===c.type){if(n=e.done?p:l,c.arg===y)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n=p,e.method="throw",e.arg=c.arg)}}}(t,e,i),o}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var s="suspendedStart",l="suspendedYield",h="executing",p="completed",y={};function v(){}function d(){}function m(){}var g={};g[i]=function(){return this};var w=Object.getPrototypeOf,A=w&&w(w(j([])));A&&A!==e&&n.call(A,i)&&(g=A);var E=m.prototype=v.prototype=Object.create(g);function x(t){["next","throw","return"].forEach((function(r){t[r]=function(t){return this._invoke(r,t)}}))}function L(t){var r;this._invoke=function(e,o){function i(){return new Promise((function(r,i){!function r(e,o,i,a){var u=f(t[e],t,o);if("throw"!==u.type){var c=u.arg,s=c.value;return s&&"object"==typeof s&&n.call(s,"__await")?Promise.resolve(s.__await).then((function(t){r("next",t,i,a)}),(function(t){r("throw",t,i,a)})):Promise.resolve(s).then((function(t){c.value=t,i(c)}),(function(t){return r("throw",t,i,a)}))}a(u.arg)}(e,o,r,i)}))}return r=r?r.then(i,i):i()}}function b(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,b(t,e),"throw"===e.method))return y;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,y;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,y):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function R(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function _(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(R,this),this.reset(!0)}function j(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function e(){for(;++o<t.length;)if(n.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=r,e.done=!0,e};return a.next=a}}return{next:F}}function F(){return{value:r,done:!0}}return d.prototype=E.constructor=m,m.constructor=d,m[u]=d.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===d||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,u in t||(t[u]="GeneratorFunction")),t.prototype=Object.create(E),t},t.awrap=function(t){return{__await:t}},x(L.prototype),L.prototype[a]=function(){return this},t.AsyncIterator=L,t.async=function(r,e,n,o){var i=new L(c(r,e,n,o));return t.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(E),E[u]="Generator",E[i]=function(){return this},E.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=j,T.prototype={constructor:T,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(_),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function o(n,o){return u.type="throw",u.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(this.prev>=a.tryLoc){var c=n.call(a,"catchLoc"),f=n.call(a,"finallyLoc");if(c&&f){if(a.catchLoc>this.prev)return o(a.catchLoc,!0);if(a.finallyLoc>this.prev)return o(a.finallyLoc)}else if(c){if(a.catchLoc>this.prev)return o(a.catchLoc,!0)}else{if(!f)throw Error("try statement without catch or finally");if(a.finallyLoc>this.prev)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(this.prev>=o.tryLoc&&n.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}!i||"break"!==t&&"continue"!==t||i.tryLoc>r||r>i.finallyLoc||(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),_(e),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;_(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:j(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),y}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}}));function e(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function n(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)}))}}function o(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){if(!(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)))return;var e=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(e.push(a.value),!r||e.length!==r);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return e}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function i(t){return function(t){if(Array.isArray(t)){for(var r=0,e=Array(t.length);t.length>r;r++)e[r]=t[r];return e}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var a="Invariant failed";function u(t,r){if(!t)throw Error(a)}var c=function(t){return new Request("")},f=function(t,r){},s=function(t,r){return t},l=function(t){return e="type",(r=t)&&void 0!==r[e]?r[e]:n;var r,e,n},h="@@fetch-actions/handleRequestCreatorActions/DEFAULT_HANDLER",p=function t(r){if("function"==typeof r.then)return r.then((function(r){return t(r)}));if("string"==typeof r.url)return r;if(Array.isArray(r)&&2===r.length){var e=o(r,2);return new Request(e[0],e[1])}return new Request(r)},y="@@fetch-actions/handleResponderActions/DEFAULT_HANDLER",v=function(t){return JSON.stringify(t)},d=function t(r){if("function"==typeof r.then)return r.then((function(r){return t(r)}));if("function"==typeof r.json)return r;if(Array.isArray(r)&&2===r.length){var e=o(r,2),n=e[0],i=e[1];return!i||0===Object.keys(a=i).length&&a.constructor===Object||i.status||i.statusText||i.headers||(n=r,i=void 0),new Response(v(n),i)}return new Response(v(r));var a},m="@@fetch-actions/handleResponseActions/DEFAULT_HANDLER",g=function t(r){return"function"==typeof r.then?r.then((function(r){return t(r)})):"function"==typeof r.json?r:void 0},w="@@fetch-actions/handleTransformerActions/DEFAULT_TRANSFORMER",A=function t(r){return"function"==typeof r.then?r.then((function(r){return t(r)})):"function"==typeof r.json?r.json():r},E=function(){for(var t=arguments.length,r=Array(t),e=0;t>e;e++)r[e]=arguments[e];return function(t,e){var n;return r.some((function(r){return void 0!==(n=r(t,e))})),n}},x=function(){for(var t=arguments.length,r=Array(t),e=0;t>e;e++)r[e]=arguments[e];return function(t){var e;return r.some((function(r){return!!(e=r(t))})),e}},L=function(){for(var t=arguments.length,r=Array(t),e=0;t>e;e++)r[e]=arguments[e];return function(t,e){var n;return r.some((function(r){return!!(n=r(t,e))})),n}},b=function(t){return"object"==typeof t&&!!t&&"function"==typeof t.then},R=function(){for(var t=arguments.length,r=Array(t),e=0;t>e;e++)r[e]=arguments[e];return function(t,e){return r.reduce((function(t,r){return b(t)?t.then((function(t){return r(t,e)})):r(t,e)}),t)}};t.DEFAULT_FATAL_HANDLER="@@fetch-actions/handleFatalActions/DEFAULT_HANDLER",t.DEFAULT_REQUEST_CREATOR=h,t.DEFAULT_REQUEST_HANDLER=y,t.DEFAULT_RESPONSE_HANDLER=m,t.DEFAULT_TRANSFORMER=w,t.createFetchAction=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.fetch,o=t.requestCreator,i=void 0===o?c:o,a=t.requestTransformer,f=void 0===a?s:a,h=t.responder,p=t.responseHandler,y=void 0===p?s:p,v=t.transformer,d=void 0===v?s:v,m=t.fatalHandler;return function(){var t=n(r.mark((function t(n){var o,a,c,s,p,v;return r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===(o=l(n))&&"function"==typeof o.toString&&u(!1),t.prev=2,t.next=5,i(n);case 5:if(!(a=t.sent)){t.next=10;break}return t.next=9,f(a,n);case 9:a=t.sent;case 10:if(("function"!=typeof h||e)&&"function"!=typeof e&&u(!1),(h||"function"!=typeof e)&&"function"!=typeof h&&u(!1),!h){t.next=16;break}return t.next=15,h(a,n);case 15:c=t.sent;case 16:if(!h||e&&a||c||u(!1),c){t.next=21;break}return t.next=20,e(a);case 20:c=t.sent;case 21:return"function"!=typeof c.json&&u(!1),t.next=24,y(c,n);case 24:return"function"!=typeof(s=t.sent).json&&u(!1),t.next=28,s.json();case 28:return p=t.sent,t.next=31,d(p,n);case 31:return t.abrupt("return",t.sent);case 35:if(t.prev=35,t.t0=t.catch(2),!m){t.next=42;break}return t.next=41,m(t.t0,n);case 41:v=t.sent;case 42:if(void 0===v){t.next=44;break}return t.abrupt("return",v);case 44:throw t.t0;case 45:case"end":return t.stop()}}),t,null,[[2,35]])})));return function(r){return t.apply(this,arguments)}}()},t.handleFatalActions=function(t){return function(r,e){var n=l(e),o=t[n]||t["@@fetch-actions/handleFatalActions/DEFAULT_HANDLER"];if(void 0===n&&u(!1),t||u(!1),o)return o(r,e)}},t.handleRequestCreatorActions=function(t){return function(r){var e=l(r),n=t[e]||t[h];return void 0===e&&u(!1),t||u(!1),n?p(n(r)):c()}},t.handleResponderActions=function(t){return function(r,e){var n=l(e);void 0===n&&u(!1),t||u(!1);var o=t[n]||t[y];if(o){var i=o(r,e);return d(i)}}},t.handleResponseActions=function(t){return function(r,e){var n=l(e);void 0===n&&u(!1),t||u(!1);var o=t[n]||t[m];return o?g(o(r,e)):s(r)}},t.handleTransformerActions=function(t){return function(r,e){var n=l(e);void 0===n&&u(!1),t||u(!1);var o=t[n]||t[w];return o?A(o(r,e)):s(r)}},t.identityHandler=s,t.identityRequestCreator=c,t.identityResponder=f,t.makeJson=A,t.makeRequest=p,t.makeRequestResponse=d,t.makeResponse=g,t.reduceConfigs=function(t){for(var r=arguments.length,e=Array(r>1?r-1:0),n=1;r>n;n++)e[n-1]=arguments[n];return{fatalHandler:E.apply(void 0,i(e.map((function(t){return t.fatalHandler})).filter(Boolean))),fetch:t,requestCreator:x.apply(void 0,i(e.map((function(t){return t.requestCreator})).filter(Boolean))),requestTransformer:R.apply(void 0,i(e.map((function(t){return t.requestTransformer})).filter(Boolean))),responder:L.apply(void 0,i(e.map((function(t){return t.responder})).filter(Boolean))),responseHandler:R.apply(void 0,i(e.map((function(t){return t.responseHandler})).filter(Boolean))),transformer:R.apply(void 0,i(e.map((function(t){return t.transformer})).filter(Boolean)))}},t.reduceHandlers=R,t.someFatalHandlers=E,t.someRequestCreators=x,t.someResponders=L,Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t=t||self).FetchActions={})}(this,(function(t){"use strict";var r=function(t,r){return t(r={exports:{}},r.exports),r.exports}((function(t){var r=function(t){var r,n=Object.prototype,e=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,r,n,e){var o=Object.create((r&&r.prototype instanceof v?r:v).prototype),i=new _(e||[]);return o._invoke=function(t,r,n){var e=s;return function(o,i){if(e===h)throw Error("Generator is already running");if(e===p){if("throw"===o)throw i;return j()}for(n.method=o,n.arg=i;;){var a=n.delegate;if(a){var u=R(a,n);if(u){if(u===y)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(e===s)throw e=p,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);e=h;var c=f(t,r,n);if("normal"===c.type){if(e=n.done?p:l,c.arg===y)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(e=p,n.method="throw",n.arg=c.arg)}}}(t,n,i),o}function f(t,r,n){try{return{type:"normal",arg:t.call(r,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var s="suspendedStart",l="suspendedYield",h="executing",p="completed",y={};function v(){}function d(){}function m(){}var g={};g[i]=function(){return this};var A=Object.getPrototypeOf,E=A&&A(A(F([])));E&&E!==n&&e.call(E,i)&&(g=E);var w=m.prototype=v.prototype=Object.create(g);function x(t){["next","throw","return"].forEach((function(r){t[r]=function(t){return this._invoke(r,t)}}))}function L(t){var r;this._invoke=function(n,o){function i(){return new Promise((function(r,i){!function r(n,o,i,a){var u=f(t[n],t,o);if("throw"!==u.type){var c=u.arg,s=c.value;return s&&"object"==typeof s&&e.call(s,"__await")?Promise.resolve(s.__await).then((function(t){r("next",t,i,a)}),(function(t){r("throw",t,i,a)})):Promise.resolve(s).then((function(t){c.value=t,i(c)}),(function(t){return r("throw",t,i,a)}))}a(u.arg)}(n,o,r,i)}))}return r=r?r.then(i,i):i()}}function R(t,n){var e=t.iterator[n.method];if(e===r){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=r,R(t,n),"throw"===n.method))return y;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=f(e,t.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,y;var i=o.arg;return i?i.done?(n[t.resultName]=i.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=r),n.delegate=null,y):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,y)}function b(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function T(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function F(t){if(t){var n=t[i];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function n(){for(;++o<t.length;)if(e.call(t,o))return n.value=t[o],n.done=!1,n;return n.value=r,n.done=!0,n};return a.next=a}}return{next:j}}function j(){return{value:r,done:!0}}return d.prototype=w.constructor=m,m.constructor=d,m[u]=d.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===d||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,u in t||(t[u]="GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(L.prototype),L.prototype[a]=function(){return this},t.AsyncIterator=L,t.async=function(r,n,e,o){var i=new L(c(r,n,e,o));return t.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(w),w[u]="Generator",w[i]=function(){return this},w.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var n in t)r.push(n);return r.reverse(),function n(){for(;r.length;){var e=r.pop();if(e in t)return n.value=e,n.done=!1,n}return n.done=!0,n}},t.values=F,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(T),!t)for(var n in this)"t"===n.charAt(0)&&e.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function o(e,o){return u.type="throw",u.arg=t,n.next=e,o&&(n.method="next",n.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(this.prev>=a.tryLoc){var c=e.call(a,"catchLoc"),f=e.call(a,"finallyLoc");if(c&&f){if(a.catchLoc>this.prev)return o(a.catchLoc,!0);if(a.finallyLoc>this.prev)return o(a.finallyLoc)}else if(c){if(a.catchLoc>this.prev)return o(a.catchLoc,!0)}else{if(!f)throw Error("try statement without catch or finally");if(a.finallyLoc>this.prev)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(this.prev>=o.tryLoc&&e.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}!i||"break"!==t&&"continue"!==t||i.tryLoc>r||r>i.finallyLoc||(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),T(n),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc===t){var e=n.completion;if("throw"===e.type){var o=e.arg;T(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,e){return this.delegate={iterator:F(t),resultName:n,nextLoc:e},"next"===this.method&&(this.arg=r),y}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}}));function n(t,r,n,e,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void n(t)}u.done?r(c):Promise.resolve(c).then(e,o)}function e(t){return function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function u(t){n(a,o,i,u,c,"next",t)}function c(t){n(a,o,i,u,c,"throw",t)}u(void 0)}))}}function o(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){if(!(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)))return;var n=[],e=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(e=(a=u.next()).done)&&(n.push(a.value),!r||n.length!==r);e=!0);}catch(t){o=!0,i=t}finally{try{e||null==u.return||u.return()}finally{if(o)throw i}}return n}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function i(t){return function(t){if(Array.isArray(t)){for(var r=0,n=Array(t.length);t.length>r;r++)n[r]=t[r];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var a="Invariant failed";function u(t,r){if(!t)throw Error(a)}var c=function(t){return new Request("")},f=function(t,r){},s=function(t,r){return t},l=function(t){return n="type",(r=t)&&void 0!==r[n]?r[n]:e;var r,n,e},h="@@fetch-actions/handleRequestTransformerActions/DEFAULT_HANDLER",p="@@fetch-actions/handleRequestCreatorActions/DEFAULT_HANDLER",y=function t(r){if("function"==typeof r.then)return r.then((function(r){return t(r)}));if("string"==typeof r.url)return r;if(Array.isArray(r)&&2===r.length){var n=o(r,2);return new Request(n[0],n[1])}return new Request(r)},v="@@fetch-actions/handleResponderActions/DEFAULT_HANDLER",d=function(t){return JSON.stringify(t)},m=function t(r){if("function"==typeof r.then)return r.then((function(r){return t(r)}));if("function"==typeof r.json)return r;if(Array.isArray(r)&&2===r.length){var n=o(r,2),e=n[0],i=n[1];return!i||0===Object.keys(a=i).length&&a.constructor===Object||i.status||i.statusText||i.headers||(e=r,i=void 0),new Response(d(e),i)}return new Response(d(r));var a},g="@@fetch-actions/handleResponseActions/DEFAULT_HANDLER",A=function t(r){return"function"==typeof r.then?r.then((function(r){return t(r)})):"function"==typeof r.json?r:void 0},E="@@fetch-actions/handleTransformerActions/DEFAULT_TRANSFORMER",w=function t(r){return"function"==typeof r.then?r.then((function(r){return t(r)})):"function"==typeof r.json?r.json():r},x=function(){for(var t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];return function(t,n){var e;return r.some((function(r){return void 0!==(e=r(t,n))})),e}},L=function(){for(var t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];return function(t){var n;return r.some((function(r){return!!(n=r(t))})),n}},R=function(){for(var t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];return function(t,n){var e;return r.some((function(r){return!!(e=r(t,n))})),e}},b=function(t){return"object"==typeof t&&!!t&&"function"==typeof t.then},T=function(){for(var t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];return function(t,n){return r.reduce((function(r,e){return b(r)?r.then((function(){return e(t,n)})):e(t,n)}),void 0)}},_=function(){for(var t=arguments.length,r=Array(t),n=0;t>n;n++)r[n]=arguments[n];return function(t,n){return r.reduce((function(t,r){return b(t)?t.then((function(t){return r(t,n)})):r(t,n)}),t)}};t.DEFAULT_FATAL_HANDLER="@@fetch-actions/handleFatalActions/DEFAULT_HANDLER",t.DEFAULT_REQUEST_CREATOR=p,t.DEFAULT_REQUEST_HANDLER=v,t.DEFAULT_REQUEST_TRANSFORMER=h,t.DEFAULT_RESPONSE_HANDLER=g,t.DEFAULT_TRANSFORMER=E,t.createFetchAction=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.fetch,o=t.finally,i=t.requestCreator,a=void 0===i?c:i,f=t.requestTransformer,h=void 0===f?s:f,p=t.responder,y=t.responseHandler,v=void 0===y?s:y,d=t.transformer,m=void 0===d?s:d,g=t.fatalHandler;return(function(){var t=e(r.mark((function t(e){var i,c,f,s,y,d,A;return r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===(i=l(e))&&"function"==typeof i.toString&&u(!1),c=!1,t.prev=3,t.next=6,a(e);case 6:if(!(f=t.sent)){t.next=11;break}return t.next=10,h(f,e);case 10:f=t.sent;case 11:if(("function"!=typeof p||n)&&"function"!=typeof n&&u(!1),(p||"function"!=typeof n)&&"function"!=typeof p&&u(!1),!p){t.next=17;break}return t.next=16,p(f,e);case 16:s=t.sent;case 17:if(!p||n&&f||s||u(!1),s){t.next=22;break}return t.next=21,n(f);case 21:s=t.sent;case 22:return"function"!=typeof s.json&&u(!1),t.next=25,v(s,e);case 25:return"function"!=typeof(y=t.sent).json&&u(!1),t.next=29,y.json();case 29:return d=t.sent,t.next=32,m(d,e);case 32:return t.abrupt("return",t.sent);case 36:if(t.prev=36,t.t0=t.catch(3),!g){t.next=43;break}return t.next=42,g(t.t0,e);case 42:A=t.sent;case 43:if(void 0===A){t.next=45;break}return t.abrupt("return",A);case 45:throw c=!0,t.t0;case 47:if(t.prev=47,!o){t.next=51;break}return t.next=51,o(e,c);case 51:return t.finish(47);case 52:case"end":return t.stop()}}),t,null,[[3,36,47,52]])})));return function(r){return t.apply(this,arguments)}}())},t.handleFatalActions=function(t){return function(r,n){var e=l(n),o=t[e]||t["@@fetch-actions/handleFatalActions/DEFAULT_HANDLER"];if(void 0===e&&u(!1),t||u(!1),o)return o(r,n)}},t.handleRequestCreatorActions=function(t){return function(r){var n=l(r),e=t[n]||t[p];return void 0===n&&u(!1),t||u(!1),e?y(e(r)):c()}},t.handleRequestTransformerActions=function(t){return function(r,n){var e=l(n),o=t[e]||t[h];return void 0===e&&u(!1),t||u(!1),o?o(r,n):s(r)}},t.handleResponderActions=function(t){return function(r,n){var e=l(n);void 0===e&&u(!1),t||u(!1);var o=t[e]||t[v];if(o){var i=o(r,n);return m(i)}}},t.handleResponseActions=function(t){return function(r,n){var e=l(n);void 0===e&&u(!1),t||u(!1);var o=t[e]||t[g];return o?A(o(r,n)):s(r)}},t.handleTransformerActions=function(t){return function(r,n){var e=l(n);void 0===e&&u(!1),t||u(!1);var o=t[e]||t[E];return o?w(o(r,n)):s(r)}},t.identityHandler=s,t.identityRequestCreator=c,t.identityResponder=f,t.makeJson=w,t.makeRequest=y,t.makeRequestResponse=m,t.makeResponse=A,t.reduceConfigs=function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),e=1;r>e;e++)n[e-1]=arguments[e];return{fatalHandler:x.apply(void 0,i(n.map((function(t){return t.fatalHandler})).filter(Boolean))),fetch:t,finally:T.apply(void 0,i(n.map((function(t){return t.finally})).filter(Boolean))),requestCreator:L.apply(void 0,i(n.map((function(t){return t.requestCreator})).filter(Boolean))),requestTransformer:_.apply(void 0,i(n.map((function(t){return t.requestTransformer})).filter(Boolean))),responder:R.apply(void 0,i(n.map((function(t){return t.responder})).filter(Boolean))),responseHandler:_.apply(void 0,i(n.map((function(t){return t.responseHandler})).filter(Boolean))),transformer:_.apply(void 0,i(n.map((function(t){return t.transformer})).filter(Boolean)))}},t.reduceFinallies=T,t.reduceHandlers=_,t.someFatalHandlers=x,t.someRequestCreators=L,t.someResponders=R,Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -9,2 +9,3 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

fetch = _ref.fetch,
finallyHandler = _ref.finally,
_ref$requestCreator = _ref.requestCreator,

@@ -27,2 +28,3 @@ requestCreator = _ref$requestCreator === void 0 ? identityRequestCreator : _ref$requestCreator,

!(type !== undefined || typeof type.toString !== 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, '@@fetch-actions/createFetchAction action type must be defined. It is recommended that action be a valid flux-standard-action (https://github.com/acdlite/flux-standard-action)') : invariant(false) : void 0;
var errored = false;

@@ -80,3 +82,8 @@ try {

errored = true;
throw error;
} finally {
if (finallyHandler) {
yield finallyHandler(action, errored);
}
}

@@ -83,0 +90,0 @@ });

export { createFetchAction } from "./createFetchAction";
export { handleRequestTransformerActions, DEFAULT_HANDLER as DEFAULT_REQUEST_TRANSFORMER } from "./handleRequestTransformerActions";
export { handleRequestCreatorActions, DEFAULT_HANDLER as DEFAULT_REQUEST_CREATOR, makeRequest } from "./handleRequestCreatorActions";

@@ -7,3 +8,3 @@ export { handleResponderActions, DEFAULT_HANDLER as DEFAULT_REQUEST_HANDLER, makeResponse as makeRequestResponse } from "./handleResponderActions";

export { handleFatalActions, DEFAULT_HANDLER as DEFAULT_FATAL_HANDLER } from "./handleFatalActions";
export { reduceHandlers, reduceConfigs, someFatalHandlers, someRequestCreators, someResponders } from "./reduceHandlers";
export { reduceHandlers, reduceConfigs, reduceFinallies, someFatalHandlers, someRequestCreators, someResponders } from "./reduceHandlers";
export { identityRequestCreator, identityResponder, identityHandler } from "./identityHandlers";

@@ -51,2 +51,3 @@ export var someFatalHandlers = function someFatalHandlers() {

fetch,
finally: reduceFinallies(...configs.map(c => c.finally).filter(Boolean)),
requestCreator: someRequestCreators(...configs.map(c => c.requestCreator).filter(Boolean)),

@@ -64,5 +65,20 @@ requestTransformer: reduceHandlers(...configs.map(c => c.requestTransformer).filter(Boolean)),

export var reduceFinallies = function reduceFinallies() {
for (var _len5 = arguments.length, finallies = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
finallies[_key5] = arguments[_key5];
}
return (action, errored) => {
return finallies.reduce((promise, handler) => {
if (isPromise(promise)) {
return promise.then(() => handler(action, errored));
}
return handler(action, errored);
}, undefined);
};
};
export var reduceHandlers = function reduceHandlers() {
for (var _len5 = arguments.length, handlers = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
handlers[_key5] = arguments[_key5];
for (var _len6 = arguments.length, handlers = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
handlers[_key6] = arguments[_key6];
}

@@ -69,0 +85,0 @@

export const DEFAULT_FATAL_HANDLER: '@@fetch-actions/handleFatalActions/DEFAULT_HANDLER'
export const DEFAULT_REQUEST_CREATOR: '@@fetch-actions/handleRequestCreatorActions/DEFAULT_HANDLER'
export const DEFAULT_REQUEST_TRANSFORMER: '@@fetch-actions/handleRequestTransformerActions/DEFAULT_HANDLER'
export const DEFAULT_REQUEST_HANDLER: '@@fetch-actions/handleResponderActions/DEFAULT_HANDLER'

@@ -60,4 +61,9 @@ export const DEFAULT_RESPONSE_HANDLER: '@@fetch-actions/handleResponseActions/DEFAULT_HANDLER'

export interface Finally<ActionTypes extends AnyAction> {
(action: ActionTypes, errored: boolean): MaybePromise<void>
}
export interface CreateFetchActionConfig<ActionTypes extends AnyAction> {
fetch?: typeof fetch
finally?: Finally<ActionTypes>
requestCreator?: RequestCreator<ActionTypes>

@@ -182,2 +188,18 @@ requestTransformer?: RequestTransformer<ActionTypes>

export type RequestTransformerMap<ActionTypes extends AnyAction> = Partial<
{
readonly [K in ActionTypes['type']]: RequestTransformer<
NarrowedAction<ActionTypes, K>
>
} & {
readonly [DEFAULT_REQUEST_TRANSFORMER]: RequestTransformer<ActionTypes>
}
>
export interface HandleRequestTransformerActions {
<ActionTypes extends AnyAction>(
requestTransformerMap: RequestTransformerMap<ActionTypes>
): RequestTransformer<ActionTypes>
}
export type TransformerMap<ActionTypes extends AnyAction> = Partial<

@@ -206,2 +228,8 @@ {

export interface ReduceFinallies {
<ActionTypes extends AnyAction>(
...finallies: ReadonlyArray<Finally<ActionTypes>>
): Finally<ActionTypes>
}
export interface ReduceHandlers {

@@ -255,2 +283,3 @@ <State, ActionTypes extends AnyAction, Result>(

export const handleRequestCreatorActions: HandleRequestCreatorActions
export const handleRequestTransformerActions: HandleRequestTransformerActions
export const handleResponderActions: HandleResponderActions

@@ -267,2 +296,3 @@ export const handleResponseActions: HandleResponseActions

export const reduceConfigs: ReduceConfigs
export const reduceFinallies: ReduceFinallies
export const reduceHandlers: ReduceHandlers

@@ -269,0 +299,0 @@ export const someFatalHandlers: SomeFatalHandlers

@@ -20,2 +20,3 @@ "use strict";

fetch,
finally: finallyHandler,
requestCreator = _identityHandlers.identityRequestCreator,

@@ -30,2 +31,3 @@ requestTransformer = _identityHandlers.identityHandler,

!(type !== undefined || typeof type.toString !== 'function') ? process.env.NODE_ENV !== "production" ? (0, _tinyInvariant.default)(false, '@@fetch-actions/createFetchAction action type must be defined. It is recommended that action be a valid flux-standard-action (https://github.com/acdlite/flux-standard-action)') : invariant(false) : void 0;
let errored = false;

@@ -82,3 +84,8 @@ try {

errored = true;
throw error;
} finally {
if (finallyHandler) {
await finallyHandler(action, errored);
}
}

@@ -85,0 +92,0 @@ };

@@ -12,2 +12,14 @@ "use strict";

});
Object.defineProperty(exports, "handleRequestTransformerActions", {
enumerable: true,
get: function () {
return _handleRequestTransformerActions.handleRequestTransformerActions;
}
});
Object.defineProperty(exports, "DEFAULT_REQUEST_TRANSFORMER", {
enumerable: true,
get: function () {
return _handleRequestTransformerActions.DEFAULT_HANDLER;
}
});
Object.defineProperty(exports, "handleRequestCreatorActions", {

@@ -109,2 +121,8 @@ enumerable: true,

});
Object.defineProperty(exports, "reduceFinallies", {
enumerable: true,
get: function () {
return _reduceHandlers.reduceFinallies;
}
});
Object.defineProperty(exports, "someFatalHandlers", {

@@ -149,2 +167,4 @@ enumerable: true,

var _handleRequestTransformerActions = require("./handleRequestTransformerActions");
var _handleRequestCreatorActions = require("./handleRequestCreatorActions");

@@ -151,0 +171,0 @@

@@ -6,3 +6,3 @@ "use strict";

});
exports.reduceHandlers = exports.reduceConfigs = exports.someResponders = exports.someRequestCreators = exports.someFatalHandlers = void 0;
exports.reduceHandlers = exports.reduceFinallies = exports.reduceConfigs = exports.someResponders = exports.someRequestCreators = exports.someFatalHandlers = void 0;

@@ -52,2 +52,3 @@ const someFatalHandlers = (...handlers) => {

fetch,
finally: reduceFinallies(...configs.map(c => c.finally).filter(Boolean)),
requestCreator: someRequestCreators(...configs.map(c => c.requestCreator).filter(Boolean)),

@@ -67,2 +68,16 @@ requestTransformer: reduceHandlers(...configs.map(c => c.requestTransformer).filter(Boolean)),

const reduceFinallies = (...finallies) => {
return (action, errored) => {
return finallies.reduce((promise, handler) => {
if (isPromise(promise)) {
return promise.then(() => handler(action, errored));
}
return handler(action, errored);
}, undefined);
};
};
exports.reduceFinallies = reduceFinallies;
const reduceHandlers = (...handlers) => {

@@ -69,0 +84,0 @@ return (state, action) => handlers.reduce((state, handler) => {

{
"name": "fetch-actions",
"version": "0.4.1",
"version": "0.5.0",
"description": "Manage fetch with flux-standard-actions dispatched from a saga or thunk.",

@@ -54,2 +54,3 @@ "main": "lib/index.js",

"dependencies": {
"@babel/runtime": "^7.0.0",
"tiny-invariant": "^1.0.6",

@@ -59,6 +60,6 @@ "tiny-warning": "^1.0.3"

"devDependencies": {
"@babel/cli": "^7.6.2",
"@babel/core": "^7.6.2",
"@typescript-eslint/eslint-plugin": "^2.3.0",
"@typescript-eslint/parser": "^2.3.0",
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@typescript-eslint/eslint-plugin": "^2.5.0",
"@typescript-eslint/parser": "^2.5.0",
"@zumper/babel-preset-react-app": "^9.0.2-zumper.18",

@@ -68,6 +69,6 @@ "babel-eslint": "^10.0.3",

"babel-plugin-module-resolver": "^3.2.0",
"cross-env": "^6.0.0",
"cross-env": "^6.0.3",
"cross-fetch": "^3.0.4",
"eslint": "^6.4.0",
"eslint-config-prettier": "^6.3.0",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-config-react-app": "^5.0.2",

@@ -78,3 +79,3 @@ "eslint-config-standard": "^14.1.0",

"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.17.0",
"eslint-plugin-jest": "^22.19.0",
"eslint-plugin-jsx-a11y": "^6.2.3",

@@ -85,4 +86,4 @@ "eslint-plugin-markdown": "^1.0.0",

"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^2.0.1",
"eslint-plugin-react": "^7.16.0",
"eslint-plugin-react-hooks": "^2.1.2",
"eslint-plugin-simple-import-sort": "^4.0.0",

@@ -95,3 +96,3 @@ "eslint-plugin-standard": "^4.0.1",

"rimraf": "^3.0.0",
"rollup": "^1.21.4",
"rollup": "^1.25.1",
"rollup-plugin-babel": "^4.3.3",

@@ -102,3 +103,3 @@ "rollup-plugin-commonjs": "^10.1.0",

"rollup-plugin-terser": "^5.1.2",
"typescript": "^3.6.3"
"typescript": "^3.6.4"
},

@@ -105,0 +106,0 @@ "npmName": "fetch-actions",

@@ -9,2 +9,3 @@ import invariant from 'tiny-invariant'

fetch,
finally: finallyHandler,
requestCreator = identityRequestCreator,

@@ -22,2 +23,3 @@ requestTransformer = identityHandler,

)
let errored = false
try {

@@ -82,4 +84,9 @@ let request = await requestCreator(action)

}
errored = true
throw error
} finally {
if (finallyHandler) {
await finallyHandler(action, errored)
}
}
}
export { createFetchAction } from './createFetchAction'
export {
handleRequestTransformerActions,
DEFAULT_HANDLER as DEFAULT_REQUEST_TRANSFORMER,
} from './handleRequestTransformerActions'
export {
handleRequestCreatorActions,

@@ -35,2 +40,3 @@ DEFAULT_HANDLER as DEFAULT_REQUEST_CREATOR,

reduceConfigs,
reduceFinallies,
someFatalHandlers,

@@ -37,0 +43,0 @@ someRequestCreators,

@@ -40,2 +40,3 @@ export const someFatalHandlers = (...handlers) => {

fetch,
finally: reduceFinallies(...configs.map((c) => c.finally).filter(Boolean)),
requestCreator: someRequestCreators(

@@ -67,2 +68,13 @@ ...configs.map((c) => c.requestCreator).filter(Boolean)

export const reduceFinallies = (...finallies) => {
return (action, errored) => {
return finallies.reduce((promise, handler) => {
if (isPromise(promise)) {
return promise.then(() => handler(action, errored))
}
return handler(action, errored)
}, undefined)
}
}
export const reduceHandlers = (...handlers) => {

@@ -69,0 +81,0 @@ return (state, action) =>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc