diff --git a/README.md b/README.md index f4f66e7..a8fad78 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # o.js -*o.js beta v0.2.1* +*o.js beta v0.2.2* o.js is a client side Odata Javascript library to simplify the request of data. The main goal is to build a **standalone, lightweight and easy** to understand Odata lib. diff --git a/o.js b/o.js index 8420bfa..0787e20 100644 --- a/o.js +++ b/o.js @@ -1,5 +1,5 @@ // +++ -// o.js v0.2.1 +// o.js v0.2.2 // // o.js is a simple oData wrapper for JavaScript. // Currently supporting the following operations: diff --git a/o.min.js b/o.min.js index 972aaf4..9fd17a0 100644 --- a/o.min.js +++ b/o.min.js @@ -1 +1 @@ -!function(e,n){"function"==typeof define&&define.amd?define(["q"],n):"object"==typeof exports?module.exports=n(require("q")):e.o=n(e.Q)}(this,function(e){function n(e){function n(){for(var e,n={},t=0,r=arguments.length;r>t;t++)for(e in arguments[t])arguments[t].hasOwnProperty(e)&&(n[e]=arguments[t][e]);return n}var r=this;return r.oConfig=r.oConfig||{endpoint:null,format:"json",version:4,strictMode:!0,start:null,ready:null,error:null,headers:[],username:null,password:null,isAsync:!0,isCors:!0,openAjaxRequests:0,isHashRoute:!0,appending:""},r.config=function(e){r.oConfig=n(r.oConfig,e)},r.isEndpoint=function(){return null!==r.oConfig.endpoint},"undefined"==typeof e?r:new t(e,r.oConfig)}function t(n,t){function r(){if("undefined"!=typeof e){var n=e;return n}if("undefined"==typeof window){var n=require("q");return n}return null}function o(e,n,t,r){if(A(n)){var o="",a=[];for(i=0;i0?"?"+e.substring(1):""}function f(e){for(var n=0;n-1||e.toUpperCase().indexOf("HTTPS://")>-1?X=!1:G.oConfig.endpoint||L("You can not use resource query without defining your oData endpoint. Use o().config({endpoint:youeEndpoint}) to define your oData endpoint."),routeName=e,c(e),G)}function C(e){$("$expand")?(M.queryList[M.query.$expand].value+=","+e,M.queryList[M.query.$expand].original=M.queryList[M.query.$expand].value):x("$expand",e,e)}function m(e){var n=e.split("?"),t=e,r="",o={path:[],appending:"",query:{},queryList:[],method:"GET",data:null,progress:null};if(2===n.length){t=n[0],r=n[1];for(var i=r.split("&"),a=0;a0?e:void L(n+": Parameter must be set.")}function E(e,n){if("number"==typeof e)return e;var t=n;return e&&e.length>0&&(isNaN(e)||(t=parseInt(e))),t}function P(e){for(var n=0,t=0;t-1&&n++;return n}function b(e){for(var n=[],t=0;t-1&&n.push(t);for(var t=n.length-1;t>=0;t--)U.splice(n[t],1);U[0]&&(M=U[0])}function R(e){return JSON?JSON.stringify(e):(L("No JSON support."),e)}function A(e){return"undefined"==typeof Array.isArray?"[object Array]"===e.toString():Array.isArray(e)}function N(e,n){return e?-1!==e.indexOf(n,e.length-n.length):!1}function k(e,n){return 0===e.indexOf(n)}function L(e){function n(e){this.message=e,this.name="o.js exception"}if(n.prototype=new Error,G.oConfig.strictMode===!0)throw new n(e);console.log("o.js exception: "+e)}function j(e,n){var t="",r=S(),o=!1;n&&(t+="--batch_"+e+"\n",t+="Content-Type: multipart/mixed; boundary=changeset_"+r+"\n\n");for(var i=0;i=200&&e.status<300){if(204!==e.status)if(o){var n,i=[],s=/({[\s\S]*?--batchresponse_)/g;do n=s.exec(e.responseText),n&&(_(n[0].substring(0,n[0].length-16),f),i.push(f.data));while(n);f.data=i}else _(e.responseText,f);z&&z.resolve(f),"function"==typeof t&&t.call(f,f.data,a)}else try{var p=e.responseText;if(JSON&&""!=e.responseText&&(p=JSON.parse(e.responseText)),""!==p&&p["odata.error"]){var l=p["odata.error"].message.value+" | HTTP Status: "+e.status+" | oData Code: "+p["odata.error"].code;L(l)}else L("Request to "+u()+" failed with HTTP status "+(e.status||404)+".")}catch(d){if(D(f,!0,e.status||404,e.responseText),"function"==typeof r)r(e.status||404,d);else{if(!z)throw d;d.status=e.status||404,z.reject(d)}}D(f,!1)}},G.oConfig.username&&G.oConfig.password&&(W&&L("CORS and Basic Auth is not supported for IE <= 9. Try to set isCors:false in the OData config if you do not need CORS support."),e.setRequestHeader("Authorization","Basic "+B(G.oConfig.username+":"+G.oConfig.password))),!W){if(i)for(var p=0;p0)for(var p=0;p>2,a=(3&t)<<4|r>>4,u=(15&r)<<2|o>>6,s=63&o,isNaN(r)?u=s=64:isNaN(o)&&(s=64),f=f+this._keyStr.charAt(i)+this._keyStr.charAt(a)+this._keyStr.charAt(u)+this._keyStr.charAt(s);return f},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");for(var n="",t=0;tr?n+=String.fromCharCode(r):r>127&&2048>r?(n+=String.fromCharCode(r>>6|192),n+=String.fromCharCode(63&r|128)):(n+=String.fromCharCode(r>>12|224),n+=String.fromCharCode(r>>6&63|128),n+=String.fromCharCode(63&r|128))}return n}};return n.encode(e)}var G=this,M=null,U=[],I=[],X=!0,z=null,Q=null,W=!1,F=function(){},K={},V={"==":"eq","===":"eq","!=":"ne","!==":"ne",">":"gt",">=":"ge","<":"lt","<=":"le","&&":"and","||":"or","!":"not","*":"mul","%":"mod"};return G.data=[],G.inlinecount=null,G.param={},G.oConfig=t,G.routes=G.route=function(e,n){A(e)||(e=[e]),"undefined"==typeof window&&L("Routes are only supported in a browser env.");for(var t=window.location.hash,r=0;rt;t++)for(e in arguments[t])arguments[t].hasOwnProperty(e)&&(n[e]=arguments[t][e]);return n}var r=this;return r.oConfig=r.oConfig||{endpoint:null,format:"json",version:4,strictMode:!0,start:null,ready:null,error:null,headers:[],username:null,password:null,isAsync:!0,isCors:!0,openAjaxRequests:0,isHashRoute:!0,appending:""},r.config=function(e){r.oConfig=n(r.oConfig,e)},r.isEndpoint=function(){return null!==r.oConfig.endpoint},"undefined"==typeof e?r:new t(e,r.oConfig)}function t(n,t){function r(){if("undefined"!=typeof e){var n=e;return n}if("undefined"==typeof window){var n=require("q");return n}return null}function o(e,n,t,r){if(A(n)){var o="",a=[];for(i=0;i0?"?"+e.substring(1):""}function f(e){for(var n=0;n-1||e.toUpperCase().indexOf("HTTPS://")>-1?X=!1:G.oConfig.endpoint||L("You can not use resource query without defining your oData endpoint. Use o().config({endpoint:youeEndpoint}) to define your oData endpoint."),routeName=e,h(e),G)}function m(e){$("$expand")?(M.queryList[M.query.$expand].value+=","+e,M.queryList[M.query.$expand].original=M.queryList[M.query.$expand].value):x("$expand",e,e)}function C(e){var n=e.split("?"),t=e,r="",o={path:[],appending:"",query:{},queryList:[],method:"GET",data:null,progress:null};if(2===n.length){t=n[0],r=n[1];for(var i=r.split("&"),a=0;a0?e:void L(n+": Parameter must be set.")}function E(e,n){if("number"==typeof e)return e;var t=n;return e&&e.length>0&&(isNaN(e)||(t=parseInt(e))),t}function P(e){for(var n=0,t=0;t-1&&n++;return n}function b(e){for(var n=[],t=0;t-1&&n.push(t);for(var t=n.length-1;t>=0;t--)U.splice(n[t],1);U[0]&&(M=U[0])}function R(e){return JSON?JSON.stringify(e):(L("No JSON support."),e)}function A(e){return"undefined"==typeof Array.isArray?"[object Array]"===e.toString():Array.isArray(e)}function N(e,n){return e?-1!==e.indexOf(n,e.length-n.length):!1}function k(e,n){return 0===e.indexOf(n)}function L(e){function n(e){this.message=e,this.name="o.js exception"}if(n.prototype=new Error,G.oConfig.strictMode===!0)throw new n(e);console.log("o.js exception: "+e)}function j(e,n){var t="",r=S(),o=!1;n&&(t+="--batch_"+e+"\n",t+="Content-Type: multipart/mixed; boundary=changeset_"+r+"\n\n");for(var i=0;i=200&&e.status<300){if(204!==e.status)if(o){var n,i=[],s=/({[\s\S]*?--batchresponse_)/g;do n=s.exec(e.responseText),n&&(_(n[0].substring(0,n[0].length-16),f),i.push(f.data));while(n);f.data=i}else _(e.responseText,f);z&&z.resolve(f),"function"==typeof t&&t.call(f,f.data,a)}else try{var p=e.responseText;if(JSON&&""!=e.responseText&&(p=JSON.parse(e.responseText)),""!==p&&p["odata.error"]){var l=p["odata.error"].message.value+" | HTTP Status: "+e.status+" | oData Code: "+p["odata.error"].code;L(l)}else L("Request to "+u()+" failed with HTTP status "+(e.status||404)+".")}catch(d){if(D(f,!0,e.status||404,e.responseText),"function"==typeof r)r(e.status||404,d);else{if(!z)throw d;d.status=e.status||404,z.reject(d)}}D(f,!1)}},G.oConfig.username&&G.oConfig.password&&(W&&L("CORS and Basic Auth is not supported for IE <= 9. Try to set isCors:false in the OData config if you do not need CORS support."),e.setRequestHeader("Authorization","Basic "+B(G.oConfig.username+":"+G.oConfig.password))),!W){if(i)for(var p=0;p0)for(var p=0;p>2,a=(3&t)<<4|r>>4,u=(15&r)<<2|o>>6,s=63&o,isNaN(r)?u=s=64:isNaN(o)&&(s=64),f=f+this._keyStr.charAt(i)+this._keyStr.charAt(a)+this._keyStr.charAt(u)+this._keyStr.charAt(s);return f},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");for(var n="",t=0;tr?n+=String.fromCharCode(r):r>127&&2048>r?(n+=String.fromCharCode(r>>6|192),n+=String.fromCharCode(63&r|128)):(n+=String.fromCharCode(r>>12|224),n+=String.fromCharCode(r>>6&63|128),n+=String.fromCharCode(63&r|128))}return n}};return n.encode(e)}var G=this,M=null,U=[],I=[],X=!0,z=null,Q=null,W=!1,F=function(){},K={},V={"==":"eq","===":"eq","!=":"ne","!==":"ne",">":"gt",">=":"ge","<":"lt","<=":"le","&&":"and","||":"or","!":"not","*":"mul","%":"mod"};return G.data=[],G.inlinecount=null,G.param={},G.oConfig=t,G.routes=G.route=function(e,n){A(e)||(e=[e]),"undefined"==typeof window&&L("Routes are only supported in a browser env.");for(var t=window.location.hash,r=0;r