Comparing version 1.0.2 to 1.0.3
@@ -89,3 +89,8 @@ 'use strict'; | ||
if (query.hasOwnProperty(key)) { | ||
this.url.searchParams.append(key, query[key]); | ||
if (this.url.searchParams.get(key)) { | ||
this.url.searchParams.set(key, query[key]); | ||
} | ||
else { | ||
this.url.searchParams.append(key, query[key]); | ||
} | ||
} | ||
@@ -494,3 +499,3 @@ } | ||
req = _a[_i]; | ||
req.applyQuery(query); | ||
req.applyQuery(__assign({}, this.config.query, query)); | ||
return [4 /*yield*/, req.fetch]; | ||
@@ -506,3 +511,3 @@ case 2: | ||
case 5: | ||
this.requests[0].applyQuery(query); | ||
this.requests[0].applyQuery(__assign({}, this.config.query, query)); | ||
return [4 /*yield*/, this.requests[0].fetch]; | ||
@@ -544,2 +549,3 @@ case 6: return [2 /*return*/, [_b.sent()]]; | ||
function o(rootUrl, config) { | ||
if (config === void 0) { config = {}; } | ||
// polyfill fetch if we have no fetch | ||
@@ -559,5 +565,5 @@ var env = typeof window !== "undefined" ? window : global; | ||
headers: new Headers({ | ||
"Content-Type": "multipart/mixed", | ||
"Content-Type": "multipart/mixed" | ||
}), | ||
useChangset: false, | ||
useChangset: false | ||
}, | ||
@@ -568,3 +574,3 @@ boundaryPrefix: "batch_", | ||
headers: new Headers({ | ||
"Content-Type": "application/json", | ||
"Content-Type": "application/json" | ||
}), | ||
@@ -571,0 +577,0 @@ mode: "cors", |
@@ -85,3 +85,8 @@ /*! ***************************************************************************** | ||
if (query.hasOwnProperty(key)) { | ||
this.url.searchParams.append(key, query[key]); | ||
if (this.url.searchParams.get(key)) { | ||
this.url.searchParams.set(key, query[key]); | ||
} | ||
else { | ||
this.url.searchParams.append(key, query[key]); | ||
} | ||
} | ||
@@ -490,3 +495,3 @@ } | ||
req = _a[_i]; | ||
req.applyQuery(query); | ||
req.applyQuery(__assign({}, this.config.query, query)); | ||
return [4 /*yield*/, req.fetch]; | ||
@@ -502,3 +507,3 @@ case 2: | ||
case 5: | ||
this.requests[0].applyQuery(query); | ||
this.requests[0].applyQuery(__assign({}, this.config.query, query)); | ||
return [4 /*yield*/, this.requests[0].fetch]; | ||
@@ -540,2 +545,3 @@ case 6: return [2 /*return*/, [_b.sent()]]; | ||
function o(rootUrl, config) { | ||
if (config === void 0) { config = {}; } | ||
// polyfill fetch if we have no fetch | ||
@@ -555,5 +561,5 @@ var env = typeof window !== "undefined" ? window : global; | ||
headers: new Headers({ | ||
"Content-Type": "multipart/mixed", | ||
"Content-Type": "multipart/mixed" | ||
}), | ||
useChangset: false, | ||
useChangset: false | ||
}, | ||
@@ -564,3 +570,3 @@ boundaryPrefix: "batch_", | ||
headers: new Headers({ | ||
"Content-Type": "application/json", | ||
"Content-Type": "application/json" | ||
}), | ||
@@ -567,0 +573,0 @@ mode: "cors", |
@@ -91,3 +91,8 @@ (function (global, factory) { | ||
if (query.hasOwnProperty(key)) { | ||
this.url.searchParams.append(key, query[key]); | ||
if (this.url.searchParams.get(key)) { | ||
this.url.searchParams.set(key, query[key]); | ||
} | ||
else { | ||
this.url.searchParams.append(key, query[key]); | ||
} | ||
} | ||
@@ -496,3 +501,3 @@ } | ||
req = _a[_i]; | ||
req.applyQuery(query); | ||
req.applyQuery(__assign({}, this.config.query, query)); | ||
return [4 /*yield*/, req.fetch]; | ||
@@ -508,3 +513,3 @@ case 2: | ||
case 5: | ||
this.requests[0].applyQuery(query); | ||
this.requests[0].applyQuery(__assign({}, this.config.query, query)); | ||
return [4 /*yield*/, this.requests[0].fetch]; | ||
@@ -546,2 +551,3 @@ case 6: return [2 /*return*/, [_b.sent()]]; | ||
function o(rootUrl, config) { | ||
if (config === void 0) { config = {}; } | ||
// polyfill fetch if we have no fetch | ||
@@ -561,5 +567,5 @@ var env = typeof window !== "undefined" ? window : global; | ||
headers: new Headers({ | ||
"Content-Type": "multipart/mixed", | ||
"Content-Type": "multipart/mixed" | ||
}), | ||
useChangset: false, | ||
useChangset: false | ||
}, | ||
@@ -570,3 +576,3 @@ boundaryPrefix: "batch_", | ||
headers: new Headers({ | ||
"Content-Type": "application/json", | ||
"Content-Type": "application/json" | ||
}), | ||
@@ -573,0 +579,0 @@ mode: "cors", |
@@ -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{h(r.next(t))}catch(t){o(t)}}function c(t){try{h(r.throw(t))}catch(t){o(t)}}function h(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(s,c)}h((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(;h;)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 h.label++,{value:n[1],done:!1};case 5:h.label++,o=n[1],n=[0];continue;case 7:n=h.ops.pop(),h.trys.pop();continue;default:if(s=h.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){h=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3])){h.label=n[1];break}if(6===n[0]&&h.label<s[1]){h.label=s[1],s=n;break}if(s&&h.label<s[2]){h.label=s[2],h.ops.push(n);break}s[2]&&h.ops.pop(),h.trys.pop();continue}n=e.call(t,h)}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,c,h={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return c={next:n(0),throw:n(1),return:n(2)},"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c}function r(t,e){var n="undefined"!=typeof window?window:global;"fetch"in n||e.disablePolyfill||require("cross-fetch/polyfill"),"URL"in n||e.disablePolyfill||require("universal-url").shim();var r={batch:{changsetBoundaryPrefix:"changset_",endpoint:"$batch",headers:new Headers({"Content-Type":"multipart/mixed"}),useChangset:!1},boundaryPrefix:"batch_",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({},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 c(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:!0,configurable:!0}),t.prototype.applyQuery=function(t){for(var e in t)t.hasOwnProperty(e)&&this.url.searchParams.append(e,t[e])},t}(),s=function(){function t(t,e,n,r){void 0===r&&(r=!1);var o=this;this.changeset=r,this.batchConfig=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 s=0;this.batchBody+=t.map(function(t){return"\nContent-Type: application/http\nContent-Transfer-Encoding: binary\nContent-ID: "+ ++s+"\n\n"+t.config.method+" "+t.url.href+" HTTP/1.1\n"+o.getHeaders(t)+"\n"+o.getBody(t)}).join("\n--"+this.batchUid),this.batchBody+="\n--"+this.batchUid+"--\n "}return t.prototype.fetch=function(t){return e(this,void 0,void 0,function(){var e,r,s,c,h;return n(this,function(n){switch(n.label){case 0:return e=new o(t,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:return n.trys.push([3,5,,6]),[4,r.json()];case 4:throw c=n.sent(),{res:r,error:c};case 5:throw h=n.sent(),r;case 6:return[2]}})})},t.prototype.parseResponse=function(t,e){var n=this,r=e.split("boundary="),i=r[r.length-1],o=t.split("--"+i);return o.shift(),o.pop(),o.map(function(t){var e=t.trim().split("\r\n\r\n");if(0===e.length||e.length>3)return t;if(3!==e.length)return+e[1].split(" ")[1];try{var r=JSON.parse(e[2]);return r[n.batchConfig.fragment]||r}catch(t){return e[2]}})},t.prototype.checkForChangset=function(e,n){var r=this.getChangeResources(e);return this.changeset?this.batchBody+="\nContent-Type: multipart/mixed; boundary="+this.batchUid+"\n\n--"+this.batchUid: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?"\n "+t.config.body+"\n\n ":""},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){return Object.keys(t.config.headers).map(function(e){return e+":"+t.config.headers[e]}).join("\n")},t}(),c=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(c){switch(c.label){case 0:return c.trys.push([0,3,4,5]),this.config.onStart(this),[4,this.getFetch(t)];case 1:return r=c.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=c.sent(),[2,i.length>1?i:i[0]];case 3:throw o=c.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 s(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({},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({},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({},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({},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({},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:!0,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,i,o,s;return n(this,function(n){switch(n.label){case 0:if(!(this.pending>1))return[3,5];e=[],r=0,i=this.requests,n.label=1;case 1:return r<i.length?((o=i[r]).applyQuery(t),[4,o.fetch]):[3,4];case 2:s=n.sent(),e.push(s),n.label=3;case 3:return r++,[3,1];case 4:return[2,e];case 5:return this.requests[0].applyQuery(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=s,t.OHandler=c,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{c(r.next(t))}catch(t){o(t)}}function h(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(s,h)}c((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(;c;)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 c.label++,{value:n[1],done:!1};case 5:c.label++,o=n[1],n=[0];continue;case 7:n=c.ops.pop(),c.trys.pop();continue;default:if(s=c.trys,!(s=s.length>0&&s[s.length-1])&&(6===n[0]||2===n[0])){c=0;continue}if(3===n[0]&&(!s||n[1]>s[0]&&n[1]<s[3])){c.label=n[1];break}if(6===n[0]&&c.label<s[1]){c.label=s[1],s=n;break}if(s&&c.label<s[2]){c.label=s[2],c.ops.push(n);break}s[2]&&c.ops.pop(),c.trys.pop();continue}n=e.call(t,c)}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,c={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;"fetch"in n||e.disablePolyfill||require("cross-fetch/polyfill"),"URL"in n||e.disablePolyfill||require("universal-url").shim();var r={batch:{changsetBoundaryPrefix:"changset_",endpoint:"$batch",headers:new Headers({"Content-Type":"multipart/mixed"}),useChangset:!1},boundaryPrefix:"batch_",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({},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 h(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:!0,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=function(){function t(t,e,n,r){void 0===r&&(r=!1);var o=this;this.changeset=r,this.batchConfig=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 s=0;this.batchBody+=t.map(function(t){return"\nContent-Type: application/http\nContent-Transfer-Encoding: binary\nContent-ID: "+ ++s+"\n\n"+t.config.method+" "+t.url.href+" HTTP/1.1\n"+o.getHeaders(t)+"\n"+o.getBody(t)}).join("\n--"+this.batchUid),this.batchBody+="\n--"+this.batchUid+"--\n "}return t.prototype.fetch=function(t){return e(this,void 0,void 0,function(){var e,r,s,h,c;return n(this,function(n){switch(n.label){case 0:return e=new o(t,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:return n.trys.push([3,5,,6]),[4,r.json()];case 4:throw h=n.sent(),{res:r,error:h};case 5:throw c=n.sent(),r;case 6:return[2]}})})},t.prototype.parseResponse=function(t,e){var n=this,r=e.split("boundary="),i=r[r.length-1],o=t.split("--"+i);return o.shift(),o.pop(),o.map(function(t){var e=t.trim().split("\r\n\r\n");if(0===e.length||e.length>3)return t;if(3!==e.length)return+e[1].split(" ")[1];try{var r=JSON.parse(e[2]);return r[n.batchConfig.fragment]||r}catch(t){return e[2]}})},t.prototype.checkForChangset=function(e,n){var r=this.getChangeResources(e);return this.changeset?this.batchBody+="\nContent-Type: multipart/mixed; boundary="+this.batchUid+"\n\n--"+this.batchUid: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?"\n "+t.config.body+"\n\n ":""},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){return Object.keys(t.config.headers).map(function(e){return e+":"+t.config.headers[e]}).join("\n")},t}(),h=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 s(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({},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({},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({},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({},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({},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:!0,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({},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({},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=s,t.OHandler=h,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.0.2", | ||
"version": "1.0.3", | ||
"main": "dist/cjs/o.js", | ||
"browser": "dist/umd/o.js", | ||
"module": "dist/es2015/o.js", | ||
"types": "dist/types/o.d.ts", | ||
"dependencies": { | ||
"@babel/core": "^7.2.2", | ||
"cross-fetch": "^3.0.0", | ||
@@ -15,5 +15,6 @@ "tslib": "^1.9.3", | ||
"devDependencies": { | ||
"@babel/core": "^7.2.2", | ||
"@types/jest": "^23.3.10", | ||
"@types/node": "^10.12.24", | ||
"jest": "^23.6.0", | ||
"jest": "^25.0.0", | ||
"rollup": "^0.68.2", | ||
@@ -24,3 +25,3 @@ "rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-sourcemaps": "^0.4.2", | ||
"rollup-plugin-typescript2": "^0.18.1", | ||
"rollup-plugin-typescript2": "^0.24.2", | ||
"rollup-plugin-uglify-es": "0.0.1", | ||
@@ -27,0 +28,0 @@ "ts-jest": "^23.10.5", |
@@ -118,2 +118,59 @@ import { o } from "./o"; | ||
}); | ||
test("Attach the correct queries to the request", async () => { | ||
// when | ||
const data = await o( | ||
"https://services.odata.org/TripPinRESTierService/People?$top=2", | ||
{ | ||
query: { $top: 1, $filter: `FirstName eq 'john'` } | ||
} | ||
).get().fetch(); | ||
// expect | ||
expect(decodeURIComponent((data as Response).url)).toContain( | ||
"People?$top=1&$filter=FirstName+eq+'john'", | ||
); | ||
}); | ||
test("Check right URL Params override. query-parameter in fetch()/query() wins over query-config", async () => { | ||
// when | ||
const data = await o( | ||
"https://services.odata.org/TripPinRESTierService/People", | ||
{ | ||
query: { $top: 1 } | ||
} | ||
).get().fetch({ $top: 2 }); | ||
// expect | ||
expect(decodeURIComponent((data as Response).url)).toContain( | ||
"People?$top=2", | ||
); | ||
}); | ||
test("Check right URL Params override. query-parameter in fetch()/query() wins over baseUrl", async () => { | ||
// when | ||
const data = await o( | ||
"https://services.odata.org/TripPinRESTierService/People?$top=1", | ||
).get().fetch({ $top: 2 }); | ||
// expect | ||
expect(decodeURIComponent((data as Response).url)).toContain( | ||
"People?$top=2", | ||
); | ||
}); | ||
test("Check right URL Params override. query-config wins over baseUrl", async () => { | ||
// when | ||
const data = await o( | ||
"https://services.odata.org/TripPinRESTierService/People?$top=1", | ||
{ | ||
query: { $top: 2 } | ||
} | ||
).get().fetch(); | ||
// expect | ||
expect(decodeURIComponent((data as Response).url)).toContain( | ||
"People?$top=2", | ||
); | ||
}); | ||
}); | ||
@@ -437,3 +494,3 @@ | ||
.get(resource1) | ||
.patch(resource2, { Name: "New"}) | ||
.patch(resource2, { Name: "New" }) | ||
.get(resource2) | ||
@@ -460,4 +517,4 @@ .batch(); | ||
const result = await oHandler | ||
.post(resource, data ) | ||
.patch("$1", { LastName: "Bar"}) | ||
.post(resource, data) | ||
.patch("$1", { LastName: "Bar" }) | ||
.get(`${resource}('${data.UserName}')`) | ||
@@ -464,0 +521,0 @@ .batch(); |
13
src/o.ts
@@ -24,4 +24,3 @@ import { OdataConfig } from "./OdataConfig"; | ||
*/ | ||
export function o(rootUrl: string | URL, config?: OdataConfig | any) { | ||
export function o(rootUrl: string | URL, config: OdataConfig | any = {}) { | ||
// polyfill fetch if we have no fetch | ||
@@ -42,5 +41,5 @@ const env = typeof window !== "undefined" ? window : global; | ||
headers: new Headers({ | ||
"Content-Type": "multipart/mixed", | ||
"Content-Type": "multipart/mixed" | ||
}), | ||
useChangset: false, | ||
useChangset: false | ||
}, | ||
@@ -51,3 +50,3 @@ boundaryPrefix: "batch_", | ||
headers: new Headers({ | ||
"Content-Type": "application/json", | ||
"Content-Type": "application/json" | ||
}), | ||
@@ -69,7 +68,7 @@ mode: "cors", | ||
rootUrl, | ||
configUrl.endsWith("/") ? configUrl : `${configUrl}/`, | ||
configUrl.endsWith("/") ? configUrl : `${configUrl}/` | ||
); | ||
} catch (ex) { | ||
// no window?! | ||
rootUrl = new URL(rootUrl, mergedConfig.rootUrl); | ||
rootUrl = new URL(rootUrl as string, mergedConfig.rootUrl); | ||
} | ||
@@ -76,0 +75,0 @@ } |
@@ -223,3 +223,3 @@ import { OBatch } from "./OBatch"; | ||
for (const req of this.requests) { | ||
req.applyQuery(query); | ||
req.applyQuery({ ...this.config.query, ...query }); | ||
const request = await req.fetch; | ||
@@ -230,3 +230,3 @@ result.push(request); | ||
} else { | ||
this.requests[0].applyQuery(query); | ||
this.requests[0].applyQuery({ ...this.config.query, ...query }); | ||
return [await this.requests[0].fetch]; | ||
@@ -233,0 +233,0 @@ } |
@@ -22,3 +22,7 @@ import { OdataQuery } from "./OdataQuery"; | ||
if (query.hasOwnProperty(key)) { | ||
this.url.searchParams.append(key, query[key]); | ||
if (this.url.searchParams.get(key)) { | ||
this.url.searchParams.set(key, query[key]); | ||
} else { | ||
this.url.searchParams.append(key, query[key]); | ||
} | ||
} | ||
@@ -25,0 +29,0 @@ } |
@@ -12,3 +12,5 @@ { | ||
"moduleResolution": "node", | ||
"types": ["node", "jest"] | ||
"types": ["node", "jest"], | ||
"declaration": true, | ||
"declarationDir": "dist/types" | ||
}, | ||
@@ -18,2 +20,2 @@ "include": ["src"], | ||
"compileOnSave": false | ||
} | ||
} |
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
Sorry, the diff of this file is not supported yet
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
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
1328377
3
61
14334
15
- Removed@babel/core@^7.2.2
- Removed@ampproject/remapping@2.3.0(transitive)
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/compat-data@7.26.2(transitive)
- Removed@babel/core@7.26.0(transitive)
- Removed@babel/generator@7.26.2(transitive)
- Removed@babel/helper-compilation-targets@7.25.9(transitive)
- Removed@babel/helper-module-imports@7.25.9(transitive)
- Removed@babel/helper-module-transforms@7.26.0(transitive)
- Removed@babel/helper-string-parser@7.25.9(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@babel/helper-validator-option@7.25.9(transitive)
- Removed@babel/helpers@7.26.0(transitive)
- Removed@babel/parser@7.26.2(transitive)
- Removed@babel/template@7.25.9(transitive)
- Removed@babel/traverse@7.25.9(transitive)
- Removed@babel/types@7.26.0(transitive)
- Removed@jridgewell/gen-mapping@0.3.5(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/set-array@1.2.1(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.25(transitive)
- Removedbrowserslist@4.24.2(transitive)
- Removedcaniuse-lite@1.0.30001684(transitive)
- Removedconvert-source-map@2.0.0(transitive)
- Removeddebug@4.3.7(transitive)
- Removedelectron-to-chromium@1.5.65(transitive)
- Removedescalade@3.2.0(transitive)
- Removedgensync@1.0.0-beta.2(transitive)
- Removedglobals@11.12.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjsesc@3.0.2(transitive)
- Removedjson5@2.2.3(transitive)
- Removedlru-cache@5.1.1(transitive)
- Removedms@2.1.3(transitive)
- Removednode-releases@2.0.18(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedsemver@6.3.1(transitive)
- Removedupdate-browserslist-db@1.1.1(transitive)
- Removedyallist@3.1.1(transitive)