From 338f080d826dadb390d2f0041bacd9fa7b1796a6 Mon Sep 17 00:00:00 2001 From: Julien Elbaz Date: Thu, 14 Sep 2017 01:48:44 +0200 Subject: [PATCH] :fire: Remove source maps --- dist/wretch.js | 3 +-- dist/wretch.js.map | 1 - package.json | 4 ++-- test/mock.js | 6 +++--- webpack.config.js | 1 - 5 files changed, 6 insertions(+), 9 deletions(-) delete mode 100644 dist/wretch.js.map diff --git a/dist/wretch.js b/dist/wretch.js index e279206..d7f5d55 100644 --- a/dist/wretch.js +++ b/dist/wretch.js @@ -1,2 +1 @@ -!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("url")):"function"==typeof define&&define.amd?define(["url"],r):"object"==typeof exports?exports.wretch=r(require("url")):t.wretch=r(t.url)}(this,function(t){return function(t){function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var n={};return r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:e})},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=0)}([function(t,r,n){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),function(t){n.d(r,"Wretcher",function(){return c});var e=n(2),o=this&&this.__assign||Object.assign||function(t){for(var r,n=1,e=arguments.length;n new Wretcher(url, opts)\n\n// Default options\nlet defaults = {}\nlet errorType = null\n\n/**\n * The Wretcher class used to perform easy fetch requests.\n *\n * Almost every method of this class return a fresh Wretcher object.\n */\nexport class Wretcher {\n\n constructor(\n private _url: string,\n private _options = {}) {}\n\n /**\n * Sets the default fetch options used for every subsequent fetch call.\n * @param opts New default options\n */\n defaults(opts) {\n defaults = opts\n return this\n }\n\n /**\n * Mixins the default fetch options used for every subsequent fetch calls.\n * @param opts Options to mixin with the current default options\n */\n mixdefaults(opts) {\n defaults = mix(defaults, opts)\n return this\n }\n\n /**\n * Sets the method (text, json ...) used to parse the data contained in the response body in case of an HTTP error.\n *\n * Persists for every subsequent requests.\n *\n * Default is \"text\".\n */\n errorType(method) {\n errorType = method\n return this\n }\n\n /**\n * Returns a new Wretcher object with the url specified and the same options.\n * @param url String url\n */\n url(url: string) {\n return new Wretcher(url, this._options)\n }\n\n /**\n * Returns a new Wretcher object with the same url and new options.\n * @param options New options\n */\n options(options: Object) {\n return new Wretcher(this._url, options)\n }\n\n /**\n * Converts a javascript object to query parameters,\n * then appends this query string to the current url.\n *\n * ```\n * let w = wretch(\"http://example.com\") // url is http://example.com\n * w = w.query({ a: 1, b : 2 }) // url is now http://example.com?a=1&b=2\n * ```\n *\n * @param qp An object which will be converted.\n */\n query(qp: Object) {\n return new Wretcher(appendQueryParams(this._url, qp), this._options)\n }\n\n /**\n * Shortcut to set the \"Accept\" header.\n * @param what Header value\n */\n accept(what: string) {\n return new Wretcher(this._url, mix(this._options, { headers: { \"Accept\" : what }}))\n }\n\n /**\n * Performs a get request.\n */\n get(opts = {}) {\n return doFetch(this._url)(mix(opts, this._options))\n }\n /**\n * Performs a delete request.\n */\n delete(opts = {}) {\n return doFetch(this._url)({ ...mix(opts, this._options), method: \"DELETE\" })\n }\n /**\n * Performs a put request.\n */\n put(opts = {}) {\n return doFetch(this._url)({ ...mix(opts, this._options), method: \"PUT\" })\n }\n /**\n * Performs a post request.\n */\n post(opts = {}) {\n return doFetch(this._url)({ ...mix(opts, this._options), method: \"POST\" })\n }\n /**\n * Performs a patch request.\n */\n patch(opts = {}) {\n return doFetch(this._url)({ ...mix(opts, this._options), method: \"PATCH\" })\n }\n\n /**\n * Sets the content type header, stringifies an object and sets the request body.\n * @param obj An object\n */\n json(jsObject) {\n return new Wretcher(this._url,\n { \n ...this._options,\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(jsObject)\n })\n }\n /**\n * Converts the javascript object to a FormData and sets the request body.\n * @param obj An object\n */\n formData(obj) {\n const formData = new FormData()\n for(const key in obj) {\n if(obj[key] instanceof Array) {\n for(const item of obj[key])\n formData.append(key + \"[]\", item)\n } else {\n formData.append(key, obj[key])\n }\n }\n\n return new Wretcher(this._url,\n { \n ...this._options,\n body: formData\n })\n }\n}\n\n// Internal helpers\n\nconst appendQueryParams = (url: string, qp: Object) => {\n const usp = new URLSearchParams()\n const index = url.indexOf(\"?\")\n for(const key in qp) {\n usp.append(key, qp[key])\n }\n return ~index ?\n `${url.substring(0, index)}?${usp.toString()}` :\n `${url}?${usp.toString()}`\n}\n\nconst doFetch = url => (opts = {}) => {\n const req = fetch(url, mix(defaults, opts))\n let wrapper : Promise = req.then(response => {\n if (!response.ok) {\n return response[errorType || \"text\"]().then(_ => {\n const err = new Error(_)\n err[errorType] = _\n err[\"status\"] = response.status\n err[\"response\"] = response\n throw err\n })\n }\n return response\n })\n let catchers = []\n const doCatch = req => catchers.reduce((accumulator, catcher) => accumulator.catch(catcher), req)\n const responseTypes = {\n /**\n * Retrieves the raw result as a promise.\n */\n res: () => doCatch(wrapper),\n /**\n * Retrieves the result as a parsed JSON object.\n */\n json: () => doCatch(wrapper.then(_ => _ && _.json())),\n /**\n * Retrieves the result as a Blob object.\n */\n blob: () => doCatch(wrapper.then(_ => _ && _.blob())),\n /**\n * Retrieves the result as a FormData object.\n */\n formData: () => doCatch(wrapper.then(_ => _ && _.formData())),\n /**\n * Retrieves the result as an ArrayBuffer object.\n */\n arrayBuffer: () => doCatch(wrapper.then(_ => _ && _.arrayBuffer())),\n /**\n * Retrieves the result as a string.\n */\n text: () => doCatch(wrapper.then(_ => _ && _.text())),\n /**\n * Catches an http response with a specific error code and performs a callback.\n */\n error: (code: number, cb) => {\n catchers.push(err => {\n if(err.status === code) cb(err)\n else throw err\n })\n return responseTypes\n },\n /**\n * Catches a bad request (http code 400) and performs a callback.\n */\n badRequest: cb => responseTypes.error(400, cb),\n /**\n * Catches an unauthorized request (http code 401) and performs a callback.\n */\n unauthorized: cb => responseTypes.error(401, cb),\n /**\n * Catches a forbidden request (http code 403) and performs a callback.\n */\n forbidden: cb => responseTypes.error(403, cb),\n /**\n * Catches a \"not found\" request (http code 404) and performs a callback.\n */\n notFound: cb => responseTypes.error(404, cb),\n /**\n * Catches a timeout (http code 408) and performs a callback.\n */\n timeout: cb => responseTypes.error(408, cb),\n /**\n * Catches an internal server error (http code 500) and performs a callback.\n */\n internalError: cb => responseTypes.error(500, cb)\n }\n\n return responseTypes\n}\n\n\n// WEBPACK FOOTER //\n// ./src/index.ts","var g;\r\n\r\n// This works in non-strict mode\r\ng = (function() {\r\n\treturn this;\r\n})();\r\n\r\ntry {\r\n\t// This works if eval is allowed (see CSP)\r\n\tg = g || Function(\"return this\")() || (1,eval)(\"this\");\r\n} catch(e) {\r\n\t// This works if the window reference is available\r\n\tif(typeof window === \"object\")\r\n\t\tg = window;\r\n}\r\n\r\n// g can still be undefined, but nothing to do about it...\r\n// We return undefined, instead of nothing here, so it's\r\n// easier to handle this case. if(!global) { ...}\r\n\r\nmodule.exports = g;\r\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// (webpack)/buildin/global.js\n// module id = 1\n// module chunks = 0","export const mix = function(one: Object, two: Object, mergeArrays: boolean = false) {\n if(!one || !two || typeof one !== \"object\" || typeof two !== \"object\")\n return one\n\n const clone = { ...one, ...two }\n for(const prop in two) {\n if(two.hasOwnProperty(prop)) {\n if(two[prop] instanceof Array && one[prop] instanceof Array) {\n clone[prop] = mergeArrays ? [ ...one[prop], ...two[prop] ] : clone[prop] = two[prop]\n } else if(typeof two[prop] === \"object\" && typeof one[prop] === \"object\") {\n clone[prop] = mix(one[prop], two[prop], mergeArrays)\n }\n }\n }\n\n return clone\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/mix.ts","module.exports = __WEBPACK_EXTERNAL_MODULE_3__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"url\"\n// module id = 3\n// module chunks = 0"],"sourceRoot":""} \ No newline at end of file diff --git a/package.json b/package.json index 97d46d9..eb72bc7 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,8 @@ }, "nyc": { "reporter": [ - "html", - "text" + "text", + "html" ] } } diff --git a/test/mock.js b/test/mock.js index 059314d..f550a4d 100644 --- a/test/mock.js +++ b/test/mock.js @@ -9,7 +9,7 @@ const preload = { const mockServer = { launch: port => { const server = restify.createServer() - mockServer.server = server + mockServer["server"] = server server.use(restify.plugins.queryParser()) server.use(restify.plugins.bodyParser()) @@ -56,7 +56,7 @@ const mockServer = { server.listen(port) }, stop: () => { - mockServer.server.close() + mockServer["server"].close() } } @@ -72,7 +72,7 @@ const imgReply = (req, res) => { } const binaryReply = (req, res) => { res.setHeader("content-type", "application/octet-stream") - const binaryData = new Buffer.from([ 0x00, 0x01, 0x02, 0x03 ]) + const binaryData = Buffer.from([ 0x00, 0x01, 0x02, 0x03 ]) res.send(binaryData) } diff --git a/webpack.config.js b/webpack.config.js index 31184e9..854b1c8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,7 +13,6 @@ module.exports = { resolve: { extensions: [".ts"] }, - devtool: "source-map", module: { loaders: [{ test: /\.tsx?$/,