fetch-plus
Advanced tools
Comparing version 3.6.1 to 3.6.3
@@ -1,1 +0,472 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["fetch-plus"]=t():e["fetch-plus"]=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function u(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function i(e){return e.toString().replace(/(^\/+|\/+$)/g,"")}function a(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=arguments.length<=2||void 0===arguments[2]?[]:arguments[2],r={url:e,options:t,middlewares:{}};return r.browse=l.bind(null,r),r.read=g.bind(null,r),r.edit=p.bind(null,r),r.replace=h.bind(null,r),r.add=v.bind(null,r),r.destroy=y.bind(null,r),r.addMiddleware=c.bind(null,r),r.removeMiddleware=d.bind(null,r),n.length&&n.forEach(r.addMiddleware),r}function c(e,t){return t._middlewareId||(t._middlewareId=O++),e.middlewares[t._middlewareId]=t,e}function d(e,t){return t._middlewareId?(e.middlewares[t._middlewareId]&&delete e.middlewares[t._middlewareId],e):void 0}function s(e){var t=arguments.length<=1||void 0===arguments[1]?"":arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=arguments.length<=3||void 0===arguments[3]?[]:arguments[3],a=[],c=[],d=void 0;return new Promise(function(r,o){var u=i((0,x.compute)(e.url));if(t=(0,x.compute)(t),t instanceof Array||(t=[t]),t=i(t.map(x.compute).map(encodeURI).join("/")),t&&(t="/"+t),"function"==typeof n.fetch)d=n.fetch;else if("function"==typeof e.options.fetch)d=e.options.fetch;else{if("function"!=typeof fetch)throw new TypeError("fetch() function not available");d=fetch}n=w({headers:{}},(0,x.computeObject)(e.options),(0,x.computeObject)(n)),r({url:u,path:t,options:n})}).then(function(t){var n=[];Object.keys(e.middlewares).forEach(function(t){n.push(e.middlewares[t])}),[].concat(n,u(r)).forEach(function(e){var n=e(t);if("function"==typeof n)a.push(n);else if("object"===("undefined"==typeof n?"undefined":o(n))){var r=n.after,u=void 0===r?null:r,i=n.error,d=void 0===i?null:i;"function"==typeof u&&a.push(u),"function"==typeof d&&c.push(d)}});var i=t.options.query||"";return"object"===("undefined"==typeof i?"undefined":o(i))?i="?"+encodeURI(E["default"].stringify((0,x.computeObject)(i))):""!==i&&(i="?"+(0,x.compute)(i)),d(t.url+t.path+i,t.options)}).then(function(e){if(!e.ok)throw e;if(!a.length)return e;var t=Promise.resolve(e)["catch"](function(e){throw e});return a.forEach(function(e){t=t.then(e)}),t})["catch"](function(e){if(!c.length)throw e;var t=c.some(function(t){try{return t(e),!0}catch(n){e=n}});if(!t)throw e})}function f(e){if(e=(0,x.compute)(e),e instanceof Array&&e.length%2!==0)throw new RangeError("Expected even array");return e}function m(e){if(e=(0,x.compute)(e),e instanceof Array&&e.length%2!==1)throw new RangeError("Expected odd array");return e}function l(e,t){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=arguments.length<=3||void 0===arguments[3]?[]:arguments[3];return s(e,function(){return m(t)},w({action:"browse",method:"GET"},n),r)}function g(e,t){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=arguments.length<=3||void 0===arguments[3]?[]:arguments[3];return s(e,function(){return f(t)},w({action:"read",method:"GET"},n),r)}function p(e,t){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=arguments.length<=3||void 0===arguments[3]?[]:arguments[3];return s(e,function(){return f(t)},w({action:"edit",method:"PATCH"},n),r)}function h(e,t){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=arguments.length<=3||void 0===arguments[3]?[]:arguments[3];return s(e,function(){return f(t)},w({action:"replace",method:"PUT"},n),r)}function v(e,t){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=arguments.length<=3||void 0===arguments[3]?[]:arguments[3];return s(e,function(){return m(t)},w({action:"add",method:"POST"},n),r)}function y(e,t){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=arguments.length<=3||void 0===arguments[3]?[]:arguments[3];return s(e,function(){return f(t)},w({action:"destroy",method:"DELETE"},n),r)}function b(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];return s({url:e,options:t,middlewares:{}},"",{},n)}var w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},j=n(2),E=r(j),x=n(1),O=23e3;e.exports={connectEndpoint:a,addMiddleware:c,removeMiddleware:d,fetch:b,browse:l,read:g,edit:p,add:v,destroy:y,compute:x.compute,computeObject:x.computeObject}},function(e,t){"use strict";function n(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function r(e){return"function"==typeof e?e():e}function o(e){var t={};return e=r(e),Object.keys(e).forEach(function(u){var i=e[u];t[u]="object"===("undefined"==typeof i?"undefined":n(i))?o(i):r(i)}),t}e.exports={compute:r,computeObject:o}},function(e,t,n){"use strict";var r=n(3);t.extract=function(e){return e.split("?")[1]||""},t.parse=function(e){return"string"!=typeof e?{}:(e=e.trim().replace(/^(\?|#|&)/,""),e?e.split("&").reduce(function(e,t){var n=t.replace(/\+/g," ").split("="),r=n.shift(),o=n.length>0?n.join("="):void 0;return r=decodeURIComponent(r),o=void 0===o?null:decodeURIComponent(o),e.hasOwnProperty(r)?Array.isArray(e[r])?e[r].push(o):e[r]=[e[r],o]:e[r]=o,e},{}):{})},t.stringify=function(e){return e?Object.keys(e).sort().map(function(t){var n=e[t];return void 0===n?"":null===n?t:Array.isArray(n)?n.sort().map(function(e){return r(t)+"="+r(e)}).join("&"):r(t)+"="+r(n)}).filter(function(e){return e.length>0}).join("&"):""}},function(e,t){"use strict";e.exports=function(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16)})}}])}); | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(); | ||
else if(typeof define === 'function' && define.amd) | ||
define([], factory); | ||
else if(typeof exports === 'object') | ||
exports["fetch-plus"] = factory(); | ||
else | ||
root["fetch-plus"] = factory(); | ||
})(this, function() { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
/******/ // The module cache | ||
/******/ var installedModules = {}; | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ // Check if module is in cache | ||
/******/ if(installedModules[moduleId]) | ||
/******/ return installedModules[moduleId].exports; | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = installedModules[moduleId] = { | ||
/******/ exports: {}, | ||
/******/ id: moduleId, | ||
/******/ loaded: false | ||
/******/ }; | ||
/******/ // Execute the module function | ||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||
/******/ // Flag the module as loaded | ||
/******/ module.loaded = true; | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = modules; | ||
/******/ // expose the module cache | ||
/******/ __webpack_require__.c = installedModules; | ||
/******/ // __webpack_public_path__ | ||
/******/ __webpack_require__.p = ""; | ||
/******/ // Load entry module and return exports | ||
/******/ return __webpack_require__(0); | ||
/******/ }) | ||
/************************************************************************/ | ||
/******/ ([ | ||
/* 0 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
"use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** | ||
* @copyright © 2015, Rick Wong. All rights reserved. | ||
*/ | ||
var _queryString = __webpack_require__(2); | ||
var _queryString2 = _interopRequireDefault(_queryString); | ||
var _compute = __webpack_require__(1); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _trimSlashes(string) { | ||
return string.toString().replace(/(^\/+|\/+$)/g, ""); | ||
} | ||
function connectEndpoint(url) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var middlewares = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; | ||
var endpoint = { | ||
url: url, | ||
options: options, | ||
middlewares: {} | ||
}; | ||
endpoint.browse = browse.bind(null, endpoint); | ||
endpoint.read = read.bind(null, endpoint); | ||
endpoint.edit = edit.bind(null, endpoint); | ||
endpoint.replace = replace.bind(null, endpoint); | ||
endpoint.add = add.bind(null, endpoint); | ||
endpoint.destroy = destroy.bind(null, endpoint); | ||
endpoint.addMiddleware = addMiddleware.bind(null, endpoint); | ||
endpoint.removeMiddleware = removeMiddleware.bind(null, endpoint); | ||
if (middlewares.length) { | ||
middlewares.forEach(endpoint.addMiddleware); | ||
} | ||
return endpoint; | ||
} | ||
var middlewareId = 23000; | ||
function addMiddleware(_endpoint, middleware) { | ||
if (!middleware._middlewareId) { | ||
middleware._middlewareId = middlewareId++; | ||
} | ||
_endpoint.middlewares[middleware._middlewareId] = middleware; | ||
return _endpoint; | ||
} | ||
function removeMiddleware(_endpoint, middleware) { | ||
if (!middleware._middlewareId) { | ||
return; | ||
} | ||
if (_endpoint.middlewares[middleware._middlewareId]) { | ||
delete _endpoint.middlewares[middleware._middlewareId]; | ||
} | ||
return _endpoint; | ||
} | ||
function _callFetch(endpoint) { | ||
var path = arguments.length <= 1 || arguments[1] === undefined ? "" : arguments[1]; | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var middlewares = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3]; | ||
var afterMiddlewares = []; | ||
var errorMiddlewares = []; | ||
var fetchFunc = undefined; | ||
return new Promise(function (resolve, reject) { | ||
var url = _trimSlashes((0, _compute.compute)(endpoint.url)); | ||
path = (0, _compute.compute)(path); | ||
if (!(path instanceof Array)) { | ||
path = [path]; | ||
} | ||
path = _trimSlashes(path.map(_compute.compute).map(encodeURI).join("/")); | ||
if (path) { | ||
path = "/" + path; | ||
} | ||
if (typeof options.fetch === "function") { | ||
fetchFunc = options.fetch; | ||
} else if (typeof endpoint.options.fetch === "function") { | ||
fetchFunc = endpoint.options.fetch; | ||
} else if (typeof fetch === "function") { | ||
fetchFunc = fetch; | ||
} else { | ||
throw new TypeError("fetch() function not available"); | ||
} | ||
options = _extends({ | ||
headers: {} | ||
}, (0, _compute.computeObject)(endpoint.options), (0, _compute.computeObject)(options)); | ||
resolve({ url: url, path: path, options: options }); | ||
}).then(function (request) { | ||
var endpointMiddlewares = []; | ||
Object.keys(endpoint.middlewares).forEach(function (key) { | ||
endpointMiddlewares.push(endpoint.middlewares[key]); | ||
}); | ||
[].concat(endpointMiddlewares, _toConsumableArray(middlewares)).forEach(function (before) { | ||
var result = before(request); | ||
if (typeof result === "function") { | ||
afterMiddlewares.push(result); | ||
} else if ((typeof result === "undefined" ? "undefined" : _typeof(result)) === "object") { | ||
var _result$after = result.after; | ||
var after = _result$after === undefined ? null : _result$after; | ||
var _result$error = result.error; | ||
var error = _result$error === undefined ? null : _result$error; | ||
if (typeof after === "function") { | ||
afterMiddlewares.push(after); | ||
} | ||
if (typeof error === "function") { | ||
errorMiddlewares.push(error); | ||
} | ||
} | ||
}); | ||
var query = request.options.query || ""; | ||
if ((typeof query === "undefined" ? "undefined" : _typeof(query)) === "object") { | ||
query = "?" + encodeURI(_queryString2.default.stringify((0, _compute.computeObject)(query))); | ||
} else if (query !== "") { | ||
query = "?" + (0, _compute.compute)(query); | ||
} | ||
return fetchFunc(request.url + request.path + query, request.options); | ||
}).then(function (response) { | ||
if (!response.ok) { | ||
throw response; | ||
} | ||
if (!afterMiddlewares.length) { | ||
return response; | ||
} | ||
var promise = Promise.resolve(response).catch(function (error) { | ||
throw error; | ||
}); | ||
afterMiddlewares.forEach(function (after) { | ||
promise = promise.then(after); | ||
}); | ||
return promise; | ||
}).catch(function (error) { | ||
if (!errorMiddlewares.length) { | ||
throw error; | ||
} | ||
var caught = errorMiddlewares.some(function (errorMiddleware) { | ||
try { | ||
errorMiddleware(error); | ||
return true; | ||
} catch (e) { | ||
error = e; | ||
} | ||
}); | ||
if (!caught) { | ||
throw error; | ||
} | ||
}); | ||
} | ||
function _expectEven(array) { | ||
array = (0, _compute.compute)(array); | ||
if (array instanceof Array && array.length % 2 !== 0) { | ||
throw new RangeError("Expected even array"); | ||
} | ||
return array; | ||
} | ||
function _expectOdd(array) { | ||
array = (0, _compute.compute)(array); | ||
if (array instanceof Array && array.length % 2 !== 1) { | ||
throw new RangeError("Expected odd array"); | ||
} | ||
return array; | ||
} | ||
function browse(_endpoint, path) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var middlewares = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3]; | ||
return _callFetch(_endpoint, function () { | ||
return _expectOdd(path); | ||
}, _extends({ action: "browse", method: "GET" }, options), middlewares); | ||
} | ||
function read(_endpoint, path) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var middlewares = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3]; | ||
return _callFetch(_endpoint, function () { | ||
return _expectEven(path); | ||
}, _extends({ action: "read", method: "GET" }, options), middlewares); | ||
} | ||
function edit(_endpoint, path) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var middlewares = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3]; | ||
return _callFetch(_endpoint, function () { | ||
return _expectEven(path); | ||
}, _extends({ action: "edit", method: "PATCH" }, options), middlewares); | ||
} | ||
function replace(_endpoint, path) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var middlewares = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3]; | ||
return _callFetch(_endpoint, function () { | ||
return _expectEven(path); | ||
}, _extends({ action: "replace", method: "PUT" }, options), middlewares); | ||
} | ||
function add(_endpoint, path) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var middlewares = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3]; | ||
return _callFetch(_endpoint, function () { | ||
return _expectOdd(path); | ||
}, _extends({ action: "add", method: "POST" }, options), middlewares); | ||
} | ||
function destroy(_endpoint, path) { | ||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
var middlewares = arguments.length <= 3 || arguments[3] === undefined ? [] : arguments[3]; | ||
return _callFetch(_endpoint, function () { | ||
return _expectEven(path); | ||
}, _extends({ action: "destroy", method: "DELETE" }, options), middlewares); | ||
} | ||
function _dropInFetch(url) { | ||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var middlewares = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; | ||
return _callFetch({ | ||
url: url, | ||
options: options, | ||
middlewares: {} | ||
}, "", {}, middlewares); | ||
} | ||
module.exports = { | ||
connectEndpoint: connectEndpoint, | ||
addMiddleware: addMiddleware, | ||
removeMiddleware: removeMiddleware, | ||
fetch: _dropInFetch, | ||
browse: browse, | ||
read: read, | ||
edit: edit, | ||
add: add, | ||
destroy: destroy, | ||
list: browse, | ||
update: edit, | ||
create: add, | ||
compute: _compute.compute, | ||
computeObject: _compute.computeObject | ||
}; | ||
/***/ }, | ||
/* 1 */ | ||
/***/ function(module, exports) { | ||
"use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
/** | ||
* @copyright © 2015, Rick Wong. All rights reserved. | ||
*/ | ||
function compute(value) { | ||
return typeof value === "function" ? value() : value; | ||
} | ||
function computeObject(object) { | ||
var mapped = {}; | ||
object = compute(object); | ||
Object.keys(object).forEach(function (key) { | ||
var value = object[key]; | ||
if (value === null) { | ||
mapped[key] = null; | ||
} else { | ||
mapped[key] = (typeof value === "undefined" ? "undefined" : _typeof(value)) === "object" ? computeObject(value) : compute(value); | ||
} | ||
}); | ||
return mapped; | ||
} | ||
module.exports = { | ||
compute: compute, | ||
computeObject: computeObject | ||
}; | ||
/***/ }, | ||
/* 2 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
var strictUriEncode = __webpack_require__(3); | ||
exports.extract = function (str) { | ||
return str.split('?')[1] || ''; | ||
}; | ||
exports.parse = function (str) { | ||
if (typeof str !== 'string') { | ||
return {}; | ||
} | ||
str = str.trim().replace(/^(\?|#|&)/, ''); | ||
if (!str) { | ||
return {}; | ||
} | ||
return str.split('&').reduce(function (ret, param) { | ||
var parts = param.replace(/\+/g, ' ').split('='); | ||
// Firefox (pre 40) decodes `%3D` to `=` | ||
// https://github.com/sindresorhus/query-string/pull/37 | ||
var key = parts.shift(); | ||
var val = parts.length > 0 ? parts.join('=') : undefined; | ||
key = decodeURIComponent(key); | ||
// missing `=` should be `null`: | ||
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters | ||
val = val === undefined ? null : decodeURIComponent(val); | ||
if (!ret.hasOwnProperty(key)) { | ||
ret[key] = val; | ||
} else if (Array.isArray(ret[key])) { | ||
ret[key].push(val); | ||
} else { | ||
ret[key] = [ret[key], val]; | ||
} | ||
return ret; | ||
}, {}); | ||
}; | ||
exports.stringify = function (obj) { | ||
return obj ? Object.keys(obj).sort().map(function (key) { | ||
var val = obj[key]; | ||
if (val === undefined) { | ||
return ''; | ||
} | ||
if (val === null) { | ||
return key; | ||
} | ||
if (Array.isArray(val)) { | ||
return val.sort().map(function (val2) { | ||
return strictUriEncode(key) + '=' + strictUriEncode(val2); | ||
}).join('&'); | ||
} | ||
return strictUriEncode(key) + '=' + strictUriEncode(val); | ||
}).filter(function (x) { | ||
return x.length > 0; | ||
}).join('&') : ''; | ||
}; | ||
/***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
module.exports = function (str) { | ||
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { | ||
return '%' + c.charCodeAt(0).toString(16); | ||
}); | ||
}; | ||
/***/ } | ||
/******/ ]) | ||
}); | ||
; |
{ | ||
"name": "fetch-plus", | ||
"description": "A convenient Fetch API library with first-class middleware support", | ||
"version": "3.6.1", | ||
"version": "3.6.3", | ||
"license": "BSD-3-Clause", | ||
@@ -6,0 +6,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
14959
361