Comparing version 1.3.0 to 1.3.1
@@ -111,3 +111,3 @@ 'use strict'; | ||
this.batchUid = this.getUid(); | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed;boundary=" + this.batchUid); | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed; boundary=" + this.batchUid); | ||
if (this.batchConfig.batch.useChangset) { | ||
@@ -135,6 +135,9 @@ resources = this.checkForChangset(resources, query); | ||
this.batchBody += CRLF + "--" + this.batchUid + "--" + CRLF; | ||
if (!changeset) { | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed;boundary=" + this.batchUid); | ||
} | ||
} | ||
OBatch.prototype.fetch = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var req, res, data, error, ex_1; | ||
var req, res, data; | ||
return __generator(this, function (_a) { | ||
@@ -152,12 +155,3 @@ switch (_a.label) { | ||
return [2 /*return*/, this.parseResponse(data, res.headers.get("Content-Type"))]; | ||
case 3: | ||
_a.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, res.json()]; | ||
case 4: | ||
error = _a.sent(); | ||
throw { res: res, error: error }; | ||
case 5: | ||
ex_1 = _a.sent(); | ||
throw res; | ||
case 6: return [2 /*return*/]; | ||
case 3: throw res; | ||
} | ||
@@ -174,24 +168,46 @@ }); | ||
splitData.pop(); | ||
var wasWithChangesetresponse = false; | ||
var parsedData = splitData.map(function (data) { | ||
var dataSegments = data.trim().split("\r\n\r\n"); | ||
if (dataSegments.length === 0 || dataSegments.length > 3) { | ||
if (dataSegments.length === 0) { | ||
// we are unable to parse -> return all | ||
return data; | ||
} | ||
else if (dataSegments.length === 3) { | ||
// if length >= 3 we have a body, try to parse if JSON and return that! | ||
try { | ||
var parsed = JSON.parse(dataSegments[2]); | ||
var hasFragment = parsed[_this.batchConfig.fragment]; | ||
return hasFragment || parsed; | ||
else if (dataSegments.length > 3) { | ||
var header = dataSegments.find(function (x) { return x.startsWith("Content-Type: ") && x.includes("boundary=changesetresponse_"); }); | ||
if (!header) { | ||
return data; | ||
} | ||
catch (ex) { | ||
return dataSegments[2]; | ||
} | ||
dataSegments.shift(); | ||
wasWithChangesetresponse = true; | ||
return _this.parseResponse(dataSegments.join("\r\n\r\n"), header); | ||
} | ||
else { | ||
// it seems like we have no body, return the status code | ||
return +dataSegments[1].split(" ")[1]; | ||
var contentIdHeader = dataSegments[0].split("\r\n").find(function (x) { return x.startsWith("Content-ID: "); }); | ||
if (contentIdHeader) { | ||
try { | ||
var contentId = parseInt(contentIdHeader.substring(12), 10); | ||
} | ||
catch (ex) { | ||
} | ||
} | ||
var status = +dataSegments[1].split(" ")[1]; | ||
if (dataSegments.length === 3) { | ||
// if length == 3 we have a body, try to parse if JSON and return that! | ||
var body; | ||
try { | ||
var parsed = JSON.parse(dataSegments[2]); | ||
var hasFragment = parsed[_this.batchConfig.fragment]; | ||
body = hasFragment || parsed; | ||
} | ||
catch (ex) { | ||
body = dataSegments[2]; | ||
} | ||
} | ||
return { contentId: contentId, status: status, body: body }; | ||
} | ||
}); | ||
if (wasWithChangesetresponse) { | ||
return parsedData[0]; | ||
} | ||
return parsedData; | ||
@@ -268,3 +284,3 @@ }; | ||
// Strip away matching root from request. | ||
href = href.replace(this.batchConfig.rootUrl.href, ''); | ||
href = href.replace(this.batchConfig.rootUrl.href, ""); | ||
} | ||
@@ -640,3 +656,4 @@ return href; | ||
// we assuming a resource | ||
var configUrl = mergedConfig.rootUrl || window.location.href; | ||
var configUrl = (mergedConfig.rootUrl || | ||
window.location.href); | ||
rootUrl = new URL(rootUrl, configUrl.endsWith("/") ? configUrl : configUrl + "/"); | ||
@@ -643,0 +660,0 @@ } |
@@ -107,3 +107,3 @@ /*! ***************************************************************************** | ||
this.batchUid = this.getUid(); | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed;boundary=" + this.batchUid); | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed; boundary=" + this.batchUid); | ||
if (this.batchConfig.batch.useChangset) { | ||
@@ -131,6 +131,9 @@ resources = this.checkForChangset(resources, query); | ||
this.batchBody += CRLF + "--" + this.batchUid + "--" + CRLF; | ||
if (!changeset) { | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed;boundary=" + this.batchUid); | ||
} | ||
} | ||
OBatch.prototype.fetch = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var req, res, data, error, ex_1; | ||
var req, res, data; | ||
return __generator(this, function (_a) { | ||
@@ -148,12 +151,3 @@ switch (_a.label) { | ||
return [2 /*return*/, this.parseResponse(data, res.headers.get("Content-Type"))]; | ||
case 3: | ||
_a.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, res.json()]; | ||
case 4: | ||
error = _a.sent(); | ||
throw { res: res, error: error }; | ||
case 5: | ||
ex_1 = _a.sent(); | ||
throw res; | ||
case 6: return [2 /*return*/]; | ||
case 3: throw res; | ||
} | ||
@@ -170,24 +164,46 @@ }); | ||
splitData.pop(); | ||
var wasWithChangesetresponse = false; | ||
var parsedData = splitData.map(function (data) { | ||
var dataSegments = data.trim().split("\r\n\r\n"); | ||
if (dataSegments.length === 0 || dataSegments.length > 3) { | ||
if (dataSegments.length === 0) { | ||
// we are unable to parse -> return all | ||
return data; | ||
} | ||
else if (dataSegments.length === 3) { | ||
// if length >= 3 we have a body, try to parse if JSON and return that! | ||
try { | ||
var parsed = JSON.parse(dataSegments[2]); | ||
var hasFragment = parsed[_this.batchConfig.fragment]; | ||
return hasFragment || parsed; | ||
else if (dataSegments.length > 3) { | ||
var header = dataSegments.find(function (x) { return x.startsWith("Content-Type: ") && x.includes("boundary=changesetresponse_"); }); | ||
if (!header) { | ||
return data; | ||
} | ||
catch (ex) { | ||
return dataSegments[2]; | ||
} | ||
dataSegments.shift(); | ||
wasWithChangesetresponse = true; | ||
return _this.parseResponse(dataSegments.join("\r\n\r\n"), header); | ||
} | ||
else { | ||
// it seems like we have no body, return the status code | ||
return +dataSegments[1].split(" ")[1]; | ||
var contentIdHeader = dataSegments[0].split("\r\n").find(function (x) { return x.startsWith("Content-ID: "); }); | ||
if (contentIdHeader) { | ||
try { | ||
var contentId = parseInt(contentIdHeader.substring(12), 10); | ||
} | ||
catch (ex) { | ||
} | ||
} | ||
var status = +dataSegments[1].split(" ")[1]; | ||
if (dataSegments.length === 3) { | ||
// if length == 3 we have a body, try to parse if JSON and return that! | ||
var body; | ||
try { | ||
var parsed = JSON.parse(dataSegments[2]); | ||
var hasFragment = parsed[_this.batchConfig.fragment]; | ||
body = hasFragment || parsed; | ||
} | ||
catch (ex) { | ||
body = dataSegments[2]; | ||
} | ||
} | ||
return { contentId: contentId, status: status, body: body }; | ||
} | ||
}); | ||
if (wasWithChangesetresponse) { | ||
return parsedData[0]; | ||
} | ||
return parsedData; | ||
@@ -264,3 +280,3 @@ }; | ||
// Strip away matching root from request. | ||
href = href.replace(this.batchConfig.rootUrl.href, ''); | ||
href = href.replace(this.batchConfig.rootUrl.href, ""); | ||
} | ||
@@ -636,3 +652,4 @@ return href; | ||
// we assuming a resource | ||
var configUrl = mergedConfig.rootUrl || window.location.href; | ||
var configUrl = (mergedConfig.rootUrl || | ||
window.location.href); | ||
rootUrl = new URL(rootUrl, configUrl.endsWith("/") ? configUrl : configUrl + "/"); | ||
@@ -639,0 +656,0 @@ } |
@@ -23,3 +23,3 @@ import { OdataConfig } from "./OdataConfig"; | ||
*/ | ||
export declare function o(rootUrl: string | URL, config?: OdataConfig | any): OHandler; | ||
export declare function o(rootUrl: string | URL, config?: Partial<OdataConfig>): OHandler; | ||
/** | ||
@@ -26,0 +26,0 @@ * Default exports |
import { OHandler } from "./OHandler"; | ||
import { OdataQuery } from "./OdataQuery"; | ||
export interface OdataBatchConfig { | ||
@@ -17,7 +18,7 @@ endpoint?: string; | ||
*/ | ||
rootUrl: URL; | ||
rootUrl?: URL | string; | ||
/** | ||
* An default query | ||
*/ | ||
query?: URLSearchParams; | ||
query?: URLSearchParams | OdataQuery; | ||
/** | ||
@@ -35,15 +36,15 @@ * The fragment to parse data from | ||
*/ | ||
disablePolyfill: boolean; | ||
disablePolyfill?: boolean; | ||
/** | ||
* A function which is called on each start of a request | ||
*/ | ||
onStart: (oHandler: OHandler) => void; | ||
onStart: (oHandler: OHandler) => null; | ||
/** | ||
* A function which is called when a request has finished | ||
*/ | ||
onFinish: (oHandler: OHandler, res?: Response) => void; | ||
onFinish: (oHandler: OHandler, res?: Response) => null; | ||
/** | ||
* A function which is called when a request has a error | ||
*/ | ||
onError: (oHandler: OHandler, res: Response) => void; | ||
onError: (oHandler: OHandler, res: Response) => null; | ||
}; |
@@ -113,3 +113,3 @@ (function (global, factory) { | ||
this.batchUid = this.getUid(); | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed;boundary=" + this.batchUid); | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed; boundary=" + this.batchUid); | ||
if (this.batchConfig.batch.useChangset) { | ||
@@ -137,6 +137,9 @@ resources = this.checkForChangset(resources, query); | ||
this.batchBody += CRLF + "--" + this.batchUid + "--" + CRLF; | ||
if (!changeset) { | ||
this.batchConfig.headers.set("Content-Type", "multipart/mixed;boundary=" + this.batchUid); | ||
} | ||
} | ||
OBatch.prototype.fetch = function (url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var req, res, data, error, ex_1; | ||
var req, res, data; | ||
return __generator(this, function (_a) { | ||
@@ -154,12 +157,3 @@ switch (_a.label) { | ||
return [2 /*return*/, this.parseResponse(data, res.headers.get("Content-Type"))]; | ||
case 3: | ||
_a.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, res.json()]; | ||
case 4: | ||
error = _a.sent(); | ||
throw { res: res, error: error }; | ||
case 5: | ||
ex_1 = _a.sent(); | ||
throw res; | ||
case 6: return [2 /*return*/]; | ||
case 3: throw res; | ||
} | ||
@@ -176,24 +170,46 @@ }); | ||
splitData.pop(); | ||
var wasWithChangesetresponse = false; | ||
var parsedData = splitData.map(function (data) { | ||
var dataSegments = data.trim().split("\r\n\r\n"); | ||
if (dataSegments.length === 0 || dataSegments.length > 3) { | ||
if (dataSegments.length === 0) { | ||
// we are unable to parse -> return all | ||
return data; | ||
} | ||
else if (dataSegments.length === 3) { | ||
// if length >= 3 we have a body, try to parse if JSON and return that! | ||
try { | ||
var parsed = JSON.parse(dataSegments[2]); | ||
var hasFragment = parsed[_this.batchConfig.fragment]; | ||
return hasFragment || parsed; | ||
else if (dataSegments.length > 3) { | ||
var header = dataSegments.find(function (x) { return x.startsWith("Content-Type: ") && x.includes("boundary=changesetresponse_"); }); | ||
if (!header) { | ||
return data; | ||
} | ||
catch (ex) { | ||
return dataSegments[2]; | ||
} | ||
dataSegments.shift(); | ||
wasWithChangesetresponse = true; | ||
return _this.parseResponse(dataSegments.join("\r\n\r\n"), header); | ||
} | ||
else { | ||
// it seems like we have no body, return the status code | ||
return +dataSegments[1].split(" ")[1]; | ||
var contentIdHeader = dataSegments[0].split("\r\n").find(function (x) { return x.startsWith("Content-ID: "); }); | ||
if (contentIdHeader) { | ||
try { | ||
var contentId = parseInt(contentIdHeader.substring(12), 10); | ||
} | ||
catch (ex) { | ||
} | ||
} | ||
var status = +dataSegments[1].split(" ")[1]; | ||
if (dataSegments.length === 3) { | ||
// if length == 3 we have a body, try to parse if JSON and return that! | ||
var body; | ||
try { | ||
var parsed = JSON.parse(dataSegments[2]); | ||
var hasFragment = parsed[_this.batchConfig.fragment]; | ||
body = hasFragment || parsed; | ||
} | ||
catch (ex) { | ||
body = dataSegments[2]; | ||
} | ||
} | ||
return { contentId: contentId, status: status, body: body }; | ||
} | ||
}); | ||
if (wasWithChangesetresponse) { | ||
return parsedData[0]; | ||
} | ||
return parsedData; | ||
@@ -270,3 +286,3 @@ }; | ||
// Strip away matching root from request. | ||
href = href.replace(this.batchConfig.rootUrl.href, ''); | ||
href = href.replace(this.batchConfig.rootUrl.href, ""); | ||
} | ||
@@ -642,3 +658,4 @@ return href; | ||
// we assuming a resource | ||
var configUrl = mergedConfig.rootUrl || window.location.href; | ||
var configUrl = (mergedConfig.rootUrl || | ||
window.location.href); | ||
rootUrl = new URL(rootUrl, configUrl.endsWith("/") ? configUrl : configUrl + "/"); | ||
@@ -645,0 +662,0 @@ } |
@@ -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(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function h(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){t.done?o(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(o)throw new TypeError("Generator is already executing.");for(;u;)try{if(o=1,i&&(s=2&n[0]?i.return:n[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,n[1])).done)return s;switch(i=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++,i=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],i=0}finally{o=s=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}var o,i,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}},i=o(o({},r),e);if("string"==typeof t)try{var s=i.rootUrl||window.location.href;t=new URL(t,s.endsWith("/")?s:s+"/")}catch(e){t=new URL(t,i.rootUrl)}return i.rootUrl=t,new u(i)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}).apply(this,arguments)},i=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 i=this;void 0===r&&(r=!1),this.changeset=r,this.batchBody="",this.batchConfig=o(o({},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+" "+i.getRequestURL(t)+" HTTP/1.1",""+i.getHeaders(t),""+i.getBody(t)].join(s)}).join(s+"--"+this.batchUid),this.batchBody+=s+"--"+this.batchUid+"--"+s}return t.prototype.fetch=function(t){return e(this,void 0,void 0,function(){var e,r,s,h,u;return n(this,function(n){switch(n.label){case 0:return e=new i(t,o(o({},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 u=n.sent(),r;case 6:return[2]}})})},t.prototype.parseResponse=function(t,e){var n=this,r=e.split("boundary="),o=r[r.length-1],i=t.split("--"+o);return i.shift(),i.pop(),i.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+=["","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,o,i,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 o=h.sent(),[2,o.length>1?o:o[0]];case 3:throw i=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,o,i;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 o=n.sent(),[2,o];case 2:throw i=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 i(e,o(o({},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 i(n,o(o({},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 i(n,o(o({},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 i(n,o(o({},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 i(e,o(o({},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,i,s,h;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?((s=i[r]).applyQuery(o(o({},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(o(o({},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=i,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 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})}); | ||
//# 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.0", | ||
"version": "1.3.1", | ||
"main": "dist/cjs/o.js", | ||
@@ -6,0 +6,0 @@ "browser": "dist/umd/o.js", |
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
1463394
15288