Comparing version 1.3.1 to 1.3.2
@@ -345,3 +345,2 @@ 'use strict'; | ||
if (!(res.status >= 400)) return [3 /*break*/, 1]; | ||
this.config.onError(this, res); | ||
throw res; | ||
@@ -373,2 +372,3 @@ case 1: | ||
ex_1 = _a.sent(); | ||
this.config.onError(this, ex_1); | ||
throw ex_1; | ||
@@ -437,2 +437,3 @@ case 4: | ||
ex_4 = _a.sent(); | ||
this.config.onError(this, ex_4); | ||
throw ex_4; | ||
@@ -439,0 +440,0 @@ case 3: |
@@ -341,3 +341,2 @@ /*! ***************************************************************************** | ||
if (!(res.status >= 400)) return [3 /*break*/, 1]; | ||
this.config.onError(this, res); | ||
throw res; | ||
@@ -369,2 +368,3 @@ case 1: | ||
ex_1 = _a.sent(); | ||
this.config.onError(this, ex_1); | ||
throw ex_1; | ||
@@ -433,2 +433,3 @@ case 4: | ||
ex_4 = _a.sent(); | ||
this.config.onError(this, ex_4); | ||
throw ex_4; | ||
@@ -435,0 +436,0 @@ case 3: |
@@ -347,3 +347,2 @@ (function (global, factory) { | ||
if (!(res.status >= 400)) return [3 /*break*/, 1]; | ||
this.config.onError(this, res); | ||
throw res; | ||
@@ -375,2 +374,3 @@ case 1: | ||
ex_1 = _a.sent(); | ||
this.config.onError(this, ex_1); | ||
throw ex_1; | ||
@@ -439,2 +439,3 @@ case 4: | ||
ex_4 = _a.sent(); | ||
this.config.onError(this, ex_4); | ||
throw ex_4; | ||
@@ -441,0 +442,0 @@ case 3: |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):(t=t||self,e(t.odata={}))}(this,function(t){"use strict";function e(t,e,n,r){return new(n||(n=Promise))(function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function h(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(s,h)}u((r=r.apply(t,e||[])).next())})}function n(t,e){function n(t){return function(e){return r([t,e])}}function r(n){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,o&&(s=2&n[0]?o.return:n[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,n[1])).done)return s;switch(o=0,s&&(n=[2&n[0],s.value]),n[0]){case 0:case 1:s=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,o=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(s=u.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3])){u.label=n[1];break}if(6===n[0]&&u.label<s[1]){u.label=s[1],s=n;break}if(s&&u.label<s[2]){u.label=s[2],u.ops.push(n);break}s[2]&&u.ops.pop(),u.trys.pop();continue}n=e.call(t,u)}catch(t){n=[6,t],o=0}finally{i=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}var i,o,s,h,u={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return h={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(h[Symbol.iterator]=function(){return this}),h}function r(t,e){void 0===e&&(e={});var n="undefined"!=typeof window?window:global;if(!("fetch"in n||e.disablePolyfill||"undefined"==typeof window))throw new Error("No polyfill found for fetch(). You need to include dist/umd/o.polyfill.js to work with older browsers");if("fetch"in n||e.disablePolyfill||"undefined"!=typeof window||require("cross-fetch/polyfill"),!("URL"in n||e.disablePolyfill||"undefined"==typeof window))throw new Error("No polyfill found for URL(). You need to include dist/umd/o.polyfill.js to work with older browsers");"URL"in n||e.disablePolyfill||"undefined"!=typeof window||require("universal-url").shim();var r={batch:{boundaryPrefix:"batch_",changsetBoundaryPrefix:"changset_",endpoint:"$batch",headers:new Headers({"Content-Type":"multipart/mixed"}),useChangset:!1,useRelativeURLs:!1},credentials:"omit",fragment:"value",headers:new Headers({"Content-Type":"application/json"}),mode:"cors",redirect:"follow",referrer:"client",onStart:function(){return null},onError:function(){return null},onFinish:function(){return null}},o=i(i({},r),e);if("string"==typeof t)try{var s=o.rootUrl||window.location.href;t=new URL(t,s.endsWith("/")?s:s+"/")}catch(e){t=new URL(t,o.rootUrl)}return o.rootUrl=t,new u(o)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t}).apply(this,arguments)},o=function(){function t(t,e){this.config=e,this.url="string"==typeof t?new URL(t):t}return Object.defineProperty(t.prototype,"fetch",{get:function(){var t=new Request(this.url.href,this.config);return fetch(t,this.config)},enumerable:!1,configurable:!0}),t.prototype.applyQuery=function(t){for(var e in t)t.hasOwnProperty(e)&&(this.url.searchParams.get(e)?this.url.searchParams.set(e,t[e]):this.url.searchParams.append(e,t[e]))},t}(),s="\r\n",h=function(){function t(t,e,n,r){var o=this;void 0===r&&(r=!1),this.changeset=r,this.batchBody="",this.batchConfig=i(i({},e),e.batch),this.batchUid=this.getUid(),this.batchConfig.headers.set("Content-Type","multipart/mixed; boundary="+this.batchUid),this.batchConfig.batch.useChangset?t=this.checkForChangset(t,n):this.batchBody+="--"+this.batchUid,t.forEach(function(t){return"GET"===t.config.method&&t.applyQuery(n)});var h=0;this.batchBody+=t.map(function(t){return h++,["","Content-Type: application/http","Content-Transfer-Encoding: binary","Content-ID: "+h,"",t.config.method+" "+o.getRequestURL(t)+" HTTP/1.1",""+o.getHeaders(t),""+o.getBody(t)].join(s)}).join(s+"--"+this.batchUid),this.batchBody+=s+"--"+this.batchUid+"--"+s,r||this.batchConfig.headers.set("Content-Type","multipart/mixed;boundary="+this.batchUid)}return t.prototype.fetch=function(t){return e(this,void 0,void 0,function(){var e,r,s;return n(this,function(n){switch(n.label){case 0:return e=new o(t,i(i({},this.batchConfig),{body:this.batchBody,method:"POST"})),[4,e.fetch];case 1:return r=n.sent(),200!==r.status?[3,3]:[4,r.text()];case 2:return s=n.sent(),[2,this.parseResponse(s,r.headers.get("Content-Type"))];case 3:throw r}})})},t.prototype.parseResponse=function(t,e){var n=this,r=e.split("boundary="),i=r[r.length-1],o=t.split("--"+i);o.shift(),o.pop();var s=!1,h=o.map(function(t){var e=t.trim().split("\r\n\r\n");if(0===e.length)return t;if(e.length>3){var r=e.find(function(t){return t.startsWith("Content-Type: ")&&t.includes("boundary=changesetresponse_")});return r?(e.shift(),s=!0,n.parseResponse(e.join("\r\n\r\n"),r)):t}var i=e[0].split("\r\n").find(function(t){return t.startsWith("Content-ID: ")});if(i)try{var o=parseInt(i.substring(12),10)}catch(t){}var h=+e[1].split(" ")[1];if(3===e.length){var u;try{var a=JSON.parse(e[2]);u=a[n.batchConfig.fragment]||a}catch(t){u=e[2]}}return{contentId:o,status:h,body:u}});return s?h[0]:h},t.prototype.checkForChangset=function(e,n){var r=this.getChangeResources(e);return this.changeset?this.batchBody+=["","Content-Type: multipart/mixed;boundary="+this.batchUid,"","--"+this.batchUid].join(s):r.length>0?(this.batchBody="--"+this.batchUid,this.batchBody+=new t(r,this.batchConfig,n,!0).batchBody,e=this.getGETResources(e)):this.batchBody="--"+this.batchUid,e},t.prototype.getGETResources=function(t){return t.filter(function(t){return"GET"===t.config.method})},t.prototype.getChangeResources=function(t){return t.filter(function(t){return"GET"!==t.config.method})},t.prototype.getBody=function(t){return t.config.body?""+t.config.body+s+s:""},t.prototype.getUid=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"===e?n:7&n|8).toString(16)});return""+(this.changeset?this.batchConfig.batch.changsetBoundaryPrefix:this.batchConfig.batch.boundaryPrefix)+e},t.prototype.getHeaders=function(t){var e=new Headers(t.config.headers||void 0),n=Array.from(e).map(function(t){return t[0]+": "+t[1]});return n.length&&n.push(""),n.join(s)},t.prototype.getRequestURL=function(t){var e=t.url.href;return this.batchConfig.batch.useRelativeURLs&&(e=e.replace(this.batchConfig.rootUrl.href,"")),e},t}(),u=function(){function t(t){this.config=t,this.requests=[]}return t.prototype.query=function(t){return e(this,void 0,void 0,function(){var r,i,o,s=this;return n(this,function(h){switch(h.label){case 0:return h.trys.push([0,3,4,5]),this.config.onStart(this),[4,this.getFetch(t)];case 1:return r=h.sent(),[4,Promise.all(r.map(function(t){return e(s,void 0,void 0,function(){var e,r;return n(this,function(n){switch(n.label){case 0:if(!(t.status>=400))return[3,1];throw this.config.onError(this,t),t;case 1:if(!t.ok||!t.json)return[3,6];n.label=2;case 2:return n.trys.push([2,4,,5]),this.config.onFinish(this,t),[4,t.json()];case 3:return e=n.sent(),[2,e[this.config.fragment]||e];case 4:return r=n.sent(),[2,t];case 5:return[3,8];case 6:return[4,t.text()];case 7:return[2,n.sent()];case 8:return[2]}})})}))];case 2:return i=h.sent(),[2,i.length>1?i:i[0]];case 3:throw o=h.sent();case 4:return this.requests=[],[7];case 5:return[2]}})})},t.prototype.fetch=function(t){return e(this,void 0,void 0,function(){var e,r;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,3,4]),this.config.onStart(this),[4,this.getFetch(t)];case 1:return e=n.sent(),[2,1===e.length?e[0]:e];case 2:throw r=n.sent(),this.config.onError(this,r),r;case 3:return this.config.onFinish(this),this.requests=[],[7];case 4:return[2]}})})},t.prototype.batch=function(t){return e(this,void 0,void 0,function(){var e,r,i,o;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,3,4]),e=new h(this.requests,this.config,t),r=this.getUrl(this.config.batch.endpoint),[4,e.fetch(r)];case 1:return i=n.sent(),[2,i];case 2:throw o=n.sent();case 3:return this.requests=[],[7];case 4:return[2]}})})},t.prototype.get=function(t){void 0===t&&(t="");var e=this.getUrl(t),n=new o(e,i(i({},this.config),{method:"GET"}));return this.requests.push(n),this},t.prototype.post=function(t,e){void 0===t&&(t="");var n=this.getUrl(t),r=new o(n,i(i({},this.config),{method:"POST",body:this.getBody(e)}));return this.requests.push(r),this},t.prototype.put=function(t,e){void 0===t&&(t="");var n=this.getUrl(t),r=new o(n,i(i({},this.config),{method:"PUT",body:this.getBody(e)}));return this.requests.push(r),this},t.prototype.patch=function(t,e){void 0===t&&(t="");var n=this.getUrl(t),r=new o(n,i(i({},this.config),{body:this.getBody(e),method:"PATCH"}));return this.requests.push(r),this},t.prototype.delete=function(t){void 0===t&&(t="");var e=this.getUrl(t),n=new o(e,i(i({},this.config),{method:"DELETE"}));return this.requests.push(n),this},t.prototype.request=function(t){this.requests.push(t)},Object.defineProperty(t.prototype,"pending",{get:function(){return this.requests.length},enumerable:!1,configurable:!0}),t.prototype.getUrl=function(t){return new URL(t,this.config.rootUrl)},t.prototype.getFetch=function(t){return e(this,void 0,void 0,function(){var e,r,o,s,h;return n(this,function(n){switch(n.label){case 0:if(!(this.pending>1))return[3,5];e=[],r=0,o=this.requests,n.label=1;case 1:return r<o.length?((s=o[r]).applyQuery(i(i({},this.config.query),t)),[4,s.fetch]):[3,4];case 2:h=n.sent(),e.push(h),n.label=3;case 3:return r++,[3,1];case 4:return[2,e];case 5:return this.requests[0].applyQuery(i(i({},this.config.query),t)),[4,this.requests[0].fetch];case 6:return[2,[n.sent()]]}})})},t.prototype.getBody=function(t){return"object"==typeof t?JSON.stringify(t):t},t}();t.o=r,t.OBatch=h,t.OHandler=u,t.ORequest=o,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):(t=t||self,e(t.odata={}))}(this,function(t){"use strict";function e(t,e,n,r){return new(n||(n=Promise))(function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function h(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(s,h)}u((r=r.apply(t,e||[])).next())})}function n(t,e){function n(t){return function(e){return r([t,e])}}function r(n){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,o&&(s=2&n[0]?o.return:n[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,n[1])).done)return s;switch(o=0,s&&(n=[2&n[0],s.value]),n[0]){case 0:case 1:s=n;break;case 4:return u.label++,{value:n[1],done:!1};case 5:u.label++,o=n[1],n=[0];continue;case 7:n=u.ops.pop(),u.trys.pop();continue;default:if(s=u.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){u=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3])){u.label=n[1];break}if(6===n[0]&&u.label<s[1]){u.label=s[1],s=n;break}if(s&&u.label<s[2]){u.label=s[2],u.ops.push(n);break}s[2]&&u.ops.pop(),u.trys.pop();continue}n=e.call(t,u)}catch(t){n=[6,t],o=0}finally{i=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}var i,o,s,h,u={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return h={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(h[Symbol.iterator]=function(){return this}),h}function r(t,e){void 0===e&&(e={});var n="undefined"!=typeof window?window:global;if(!("fetch"in n||e.disablePolyfill||"undefined"==typeof window))throw new Error("No polyfill found for fetch(). You need to include dist/umd/o.polyfill.js to work with older browsers");if("fetch"in n||e.disablePolyfill||"undefined"!=typeof window||require("cross-fetch/polyfill"),!("URL"in n||e.disablePolyfill||"undefined"==typeof window))throw new Error("No polyfill found for URL(). You need to include dist/umd/o.polyfill.js to work with older browsers");"URL"in n||e.disablePolyfill||"undefined"!=typeof window||require("universal-url").shim();var r={batch:{boundaryPrefix:"batch_",changsetBoundaryPrefix:"changset_",endpoint:"$batch",headers:new Headers({"Content-Type":"multipart/mixed"}),useChangset:!1,useRelativeURLs:!1},credentials:"omit",fragment:"value",headers:new Headers({"Content-Type":"application/json"}),mode:"cors",redirect:"follow",referrer:"client",onStart:function(){return null},onError:function(){return null},onFinish:function(){return null}},o=i(i({},r),e);if("string"==typeof t)try{var s=o.rootUrl||window.location.href;t=new URL(t,s.endsWith("/")?s:s+"/")}catch(e){t=new URL(t,o.rootUrl)}return o.rootUrl=t,new u(o)}var i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t}).apply(this,arguments)},o=function(){function t(t,e){this.config=e,this.url="string"==typeof t?new URL(t):t}return Object.defineProperty(t.prototype,"fetch",{get:function(){var t=new Request(this.url.href,this.config);return fetch(t,this.config)},enumerable:!1,configurable:!0}),t.prototype.applyQuery=function(t){for(var e in t)t.hasOwnProperty(e)&&(this.url.searchParams.get(e)?this.url.searchParams.set(e,t[e]):this.url.searchParams.append(e,t[e]))},t}(),s="\r\n",h=function(){function t(t,e,n,r){var o=this;void 0===r&&(r=!1),this.changeset=r,this.batchBody="",this.batchConfig=i(i({},e),e.batch),this.batchUid=this.getUid(),this.batchConfig.headers.set("Content-Type","multipart/mixed; boundary="+this.batchUid),this.batchConfig.batch.useChangset?t=this.checkForChangset(t,n):this.batchBody+="--"+this.batchUid,t.forEach(function(t){return"GET"===t.config.method&&t.applyQuery(n)});var h=0;this.batchBody+=t.map(function(t){return h++,["","Content-Type: application/http","Content-Transfer-Encoding: binary","Content-ID: "+h,"",t.config.method+" "+o.getRequestURL(t)+" HTTP/1.1",""+o.getHeaders(t),""+o.getBody(t)].join(s)}).join(s+"--"+this.batchUid),this.batchBody+=s+"--"+this.batchUid+"--"+s,r||this.batchConfig.headers.set("Content-Type","multipart/mixed;boundary="+this.batchUid)}return t.prototype.fetch=function(t){return e(this,void 0,void 0,function(){var e,r,s;return n(this,function(n){switch(n.label){case 0:return e=new o(t,i(i({},this.batchConfig),{body:this.batchBody,method:"POST"})),[4,e.fetch];case 1:return r=n.sent(),200!==r.status?[3,3]:[4,r.text()];case 2:return s=n.sent(),[2,this.parseResponse(s,r.headers.get("Content-Type"))];case 3:throw r}})})},t.prototype.parseResponse=function(t,e){var n=this,r=e.split("boundary="),i=r[r.length-1],o=t.split("--"+i);o.shift(),o.pop();var s=!1,h=o.map(function(t){var e=t.trim().split("\r\n\r\n");if(0===e.length)return t;if(e.length>3){var r=e.find(function(t){return t.startsWith("Content-Type: ")&&t.includes("boundary=changesetresponse_")});return r?(e.shift(),s=!0,n.parseResponse(e.join("\r\n\r\n"),r)):t}var i=e[0].split("\r\n").find(function(t){return t.startsWith("Content-ID: ")});if(i)try{var o=parseInt(i.substring(12),10)}catch(t){}var h=+e[1].split(" ")[1];if(3===e.length){var u;try{var c=JSON.parse(e[2]);u=c[n.batchConfig.fragment]||c}catch(t){u=e[2]}}return{contentId:o,status:h,body:u}});return s?h[0]:h},t.prototype.checkForChangset=function(e,n){var r=this.getChangeResources(e);return this.changeset?this.batchBody+=["","Content-Type: multipart/mixed;boundary="+this.batchUid,"","--"+this.batchUid].join(s):r.length>0?(this.batchBody="--"+this.batchUid,this.batchBody+=new t(r,this.batchConfig,n,!0).batchBody,e=this.getGETResources(e)):this.batchBody="--"+this.batchUid,e},t.prototype.getGETResources=function(t){return t.filter(function(t){return"GET"===t.config.method})},t.prototype.getChangeResources=function(t){return t.filter(function(t){return"GET"!==t.config.method})},t.prototype.getBody=function(t){return t.config.body?""+t.config.body+s+s:""},t.prototype.getUid=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"===e?n:7&n|8).toString(16)});return""+(this.changeset?this.batchConfig.batch.changsetBoundaryPrefix:this.batchConfig.batch.boundaryPrefix)+e},t.prototype.getHeaders=function(t){var e=new Headers(t.config.headers||void 0),n=Array.from(e).map(function(t){return t[0]+": "+t[1]});return n.length&&n.push(""),n.join(s)},t.prototype.getRequestURL=function(t){var e=t.url.href;return this.batchConfig.batch.useRelativeURLs&&(e=e.replace(this.batchConfig.rootUrl.href,"")),e},t}(),u=function(){function t(t){this.config=t,this.requests=[]}return t.prototype.query=function(t){return e(this,void 0,void 0,function(){var r,i,o,s=this;return n(this,function(h){switch(h.label){case 0:return h.trys.push([0,3,4,5]),this.config.onStart(this),[4,this.getFetch(t)];case 1:return r=h.sent(),[4,Promise.all(r.map(function(t){return e(s,void 0,void 0,function(){var e,r;return n(this,function(n){switch(n.label){case 0:if(!(t.status>=400))return[3,1];throw t;case 1:if(!t.ok||!t.json)return[3,6];n.label=2;case 2:return n.trys.push([2,4,,5]),this.config.onFinish(this,t),[4,t.json()];case 3:return e=n.sent(),[2,e[this.config.fragment]||e];case 4:return r=n.sent(),[2,t];case 5:return[3,8];case 6:return[4,t.text()];case 7:return[2,n.sent()];case 8:return[2]}})})}))];case 2:return i=h.sent(),[2,i.length>1?i:i[0]];case 3:throw o=h.sent(),this.config.onError(this,o),o;case 4:return this.requests=[],[7];case 5:return[2]}})})},t.prototype.fetch=function(t){return e(this,void 0,void 0,function(){var e,r;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,3,4]),this.config.onStart(this),[4,this.getFetch(t)];case 1:return e=n.sent(),[2,1===e.length?e[0]:e];case 2:throw r=n.sent(),this.config.onError(this,r),r;case 3:return this.config.onFinish(this),this.requests=[],[7];case 4:return[2]}})})},t.prototype.batch=function(t){return e(this,void 0,void 0,function(){var e,r,i,o;return n(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,3,4]),e=new h(this.requests,this.config,t),r=this.getUrl(this.config.batch.endpoint),[4,e.fetch(r)];case 1:return i=n.sent(),[2,i];case 2:throw o=n.sent(),this.config.onError(this,o),o;case 3:return this.requests=[],[7];case 4:return[2]}})})},t.prototype.get=function(t){void 0===t&&(t="");var e=this.getUrl(t),n=new o(e,i(i({},this.config),{method:"GET"}));return this.requests.push(n),this},t.prototype.post=function(t,e){void 0===t&&(t="");var n=this.getUrl(t),r=new o(n,i(i({},this.config),{method:"POST",body:this.getBody(e)}));return this.requests.push(r),this},t.prototype.put=function(t,e){void 0===t&&(t="");var n=this.getUrl(t),r=new o(n,i(i({},this.config),{method:"PUT",body:this.getBody(e)}));return this.requests.push(r),this},t.prototype.patch=function(t,e){void 0===t&&(t="");var n=this.getUrl(t),r=new o(n,i(i({},this.config),{body:this.getBody(e),method:"PATCH"}));return this.requests.push(r),this},t.prototype.delete=function(t){void 0===t&&(t="");var e=this.getUrl(t),n=new o(e,i(i({},this.config),{method:"DELETE"}));return this.requests.push(n),this},t.prototype.request=function(t){this.requests.push(t)},Object.defineProperty(t.prototype,"pending",{get:function(){return this.requests.length},enumerable:!1,configurable:!0}),t.prototype.getUrl=function(t){return new URL(t,this.config.rootUrl)},t.prototype.getFetch=function(t){return e(this,void 0,void 0,function(){var e,r,o,s,h;return n(this,function(n){switch(n.label){case 0:if(!(this.pending>1))return[3,5];e=[],r=0,o=this.requests,n.label=1;case 1:return r<o.length?((s=o[r]).applyQuery(i(i({},this.config.query),t)),[4,s.fetch]):[3,4];case 2:h=n.sent(),e.push(h),n.label=3;case 3:return r++,[3,1];case 4:return[2,e];case 5:return this.requests[0].applyQuery(i(i({},this.config.query),t)),[4,this.requests[0].fetch];case 6:return[2,[n.sent()]]}})})},t.prototype.getBody=function(t){return"object"==typeof t?JSON.stringify(t):t},t}();t.o=r,t.OBatch=h,t.OHandler=u,t.ORequest=o,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=o.min.js.map |
{ | ||
"name": "odata", | ||
"description": "o.js is a isomorphic Odata Javascript library to simplify the request of data. The main goal is to build a standalone, lightweight and easy to understand Odata lib.", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"main": "dist/cjs/o.js", | ||
@@ -6,0 +6,0 @@ "browser": "dist/umd/o.js", |
@@ -349,2 +349,46 @@ import { o, OBatch } from "./o"; | ||
describe("Error handling", () => { | ||
let oHandler; | ||
let onError; | ||
beforeEach(() => { | ||
onError = jest.fn(); | ||
oHandler = o("https://services.odata.org/V4/TripPinServiceRW/", { onError }); | ||
}); | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
test.each([ | ||
"query", | ||
"fetch", | ||
"batch", | ||
])("Callback onError is called in %s when network call fails", async (method) => { | ||
// given | ||
const resource = "People"; | ||
const fetchError = new TypeError("Failed to fetch"); | ||
jest | ||
.spyOn(window, "fetch") | ||
.mockRejectedValue(fetchError); | ||
// when / expect | ||
await expect(async () => await oHandler.get(resource)[method]()).rejects.toBe(fetchError); | ||
expect(onError).toHaveBeenCalledTimes(1); | ||
expect(onError).toHaveBeenCalledWith(oHandler, fetchError); | ||
}); | ||
// Unlike fetch and batch methods, query is the only one that analyze the response status code and throws an error | ||
// if the status code is not 2xx. | ||
test("Callback onError is called in query when response code is 404", async () => { | ||
// given | ||
const resource = "UnknownResource"; | ||
// when / expect | ||
await expect(async () => await oHandler.get(resource).query()).rejects.toMatchObject({ status: 404 }); | ||
expect(onError).toHaveBeenCalledTimes(1); | ||
expect(onError).toHaveBeenCalledWith(oHandler, expect.objectContaining({ status: 404 })); | ||
}); | ||
}); | ||
describe("Create, Update and Delete request", () => { | ||
@@ -351,0 +395,0 @@ let oHandler; |
@@ -56,3 +56,2 @@ import { OBatch } from "./OBatch"; | ||
if (res.status >= 400) { | ||
this.config.onError(this, res); | ||
throw res; | ||
@@ -75,2 +74,3 @@ } else if (res.ok && res.json) { | ||
} catch (ex) { | ||
this.config.onError(this, ex); | ||
throw ex; | ||
@@ -117,2 +117,3 @@ } finally { | ||
} catch (ex) { | ||
this.config.onError(this, ex); | ||
throw ex; | ||
@@ -119,0 +120,0 @@ } finally { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4
1423646
57
14543