forked from aerogear-attic/aerogear-js
/
aerogear.min.js
17 lines (17 loc) · 15.8 KB
/
aerogear.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*! AeroGear JavaScript Library - v1.0.0-M3 - 2013-02-15
* https://github.com/aerogear/aerogear-js
* JBoss, Home of Professional Open Source
* Copyright Red Hat, Inc., and individual contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var AeroGear={};AeroGear.Core=function(){if(this instanceof AeroGear.Core)throw"Invalid instantiation of base class AeroGear.Core";this.add=function(e){var t,r,a=this[this.collectionName]||{};if(!e)return this;if("string"==typeof e)a[e]=AeroGear[this.lib].adapters[this.type](e);else if(AeroGear.isArray(e))for(t=0;e.length>t;t++)r=e[t],"string"==typeof r?a[r]=AeroGear[this.lib].adapters[this.type](r):a[r.name]=AeroGear[this.lib].adapters[r.type||this.type](r.name,r.settings||{});else a[e.name]=AeroGear[this.lib].adapters[e.type||this.type](e.name,e.settings||{});return this[this.collectionName]=a,this},this.remove=function(e){var t,r,a=this[this.collectionName]||{};if("string"==typeof e)delete a[e];else if(AeroGear.isArray(e))for(t=0;e.length>t;t++)r=e[t],"string"==typeof r?delete a[r]:delete a[r.name];else e&&delete a[e.name];return this[this.collectionName]=a,this}},AeroGear.isArray=function(e){return"[object Array]"==={}.toString.call(e)},function(){function e(e,t,r){var a=t&&r||0,n=0;for(t=t||[],e.toLowerCase().replace(/[0-9a-f]{2}/g,function(e){16>n&&(t[a+n++]=l[e])});16>n;)t[a+n++]=0;return t}function t(e,t){var r=t||0,a=g;return a[e[r++]]+a[e[r++]]+a[e[r++]]+a[e[r++]]+"-"+a[e[r++]]+a[e[r++]]+"-"+a[e[r++]]+a[e[r++]]+"-"+a[e[r++]]+a[e[r++]]+"-"+a[e[r++]]+a[e[r++]]+a[e[r++]]+a[e[r++]]+a[e[r++]]+a[e[r++]]}function r(e,r,a){var n=r&&a||0,i=r||[];e=e||{};var s=null!=e.clockseq?e.clockseq:A,o=null!=e.msecs?e.msecs:(new Date).getTime(),u=null!=e.nsecs?e.nsecs:S+1,c=o-b+(u-S)/1e4;if(0>c&&null==e.clockseq&&(s=16383&s+1),(0>c||o>b)&&null==e.nsecs&&(u=0),u>=1e4)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");b=o,S=u,A=s,o+=122192928e5;var p=(1e4*(268435455&o)+u)%4294967296;i[n++]=255&p>>>24,i[n++]=255&p>>>16,i[n++]=255&p>>>8,i[n++]=255&p;var d=268435455&1e4*(o/4294967296);i[n++]=255&d>>>8,i[n++]=255&d,i[n++]=16|15&d>>>24,i[n++]=255&d>>>16,i[n++]=128|s>>>8,i[n++]=255&s;for(var h=e.node||v,f=0;6>f;f++)i[n+f]=h[f];return r?r:t(i)}function a(e,r,a){var n=r&&a||0;"string"==typeof e&&(r="binary"==e?new f(16):null,e=null),e=e||{};var i=e.random||(e.rng||h)();if(i[6]=64|15&i[6],i[8]=128|63&i[8],r)for(var s=0;16>s;s++)r[n+s]=i[s];return r||t(i)}var n,i,s,o=this,u=Array(16);if(n=function(){for(var e,e,t=u,r=0,r=0;16>r;r++)0==(3&r)&&(e=4294967296*Math.random()),t[r]=255&e>>>((3&r)<<3);return t},o.crypto&&crypto.getRandomValues){var c=new Uint32Array(4);s=function(){crypto.getRandomValues(c);for(var e=0;16>e;e++)u[e]=255&c[e>>2]>>>8*(3&e);return u}}try{var p=require("crypto").randomBytes;i=p&&function(){return p(16)}}catch(d){}for(var h=i||s||n,f="function"==typeof Buffer?Buffer:Array,g=[],l={},y=0;256>y;y++)g[y]=(y+256).toString(16).substr(1),l[g[y]]=y;var m=h(),v=[1|m[0],m[1],m[2],m[3],m[4],m[5]],A=16383&(m[6]<<8|m[7]),b=0,S=0,I=a;if(I.v1=r,I.v4=a,I.parse=e,I.unparse=t,I.BufferClass=f,I.mathRNG=n,I.nodeRNG=i,I.whatwgRNG=s,"undefined"!=typeof module)module.exports=I;else{var R=o.uuid;I.noConflict=function(){return o.uuid=R,I},o.uuid=I}}(),function(e){e.Pipeline=function(t){return this instanceof e.Pipeline?(e.Core.call(this),this.lib="Pipeline",this.type=t?t.type||"Rest":"Rest",this.collectionName="pipes",this.add(t),undefined):new e.Pipeline(t)},e.Pipeline.prototype=e.Core,e.Pipeline.constructor=e.Pipeline,e.Pipeline.adapters={}}(AeroGear,jQuery),function(e,t,r,a){e.Pipeline.adapters.Rest=function(r,n){if(!(this instanceof e.Pipeline.adapters.Rest))return new e.Pipeline.adapters.Rest(r,n);n=n||{};var i=n.endpoint||r,s={url:n.baseURL?n.baseURL+i:i,contentType:"application/json",dataType:"json"},o=n.recordId||"id",u=n.authenticator||null,c=n.pageConfig;this.addAuthIdentifier=function(e){return u?u.addAuthIdentifier(e):e},this.deauthorize=function(){u&&u.deauthorize()},this.getAjaxSettings=function(){return s},this.getRecordId=function(){return o},this.getPageConfig=function(){return c},this.updatePageConfig=function(e,r){r?(c={},c.metadataLocation=e.metadataLocation?e.metadataLocation:"webLinking",c.previousIdentifier=e.previousIdentifier?e.previousIdentifier:"previous",c.nextIdentifier=e.nextIdentifier?e.nextIdentifier:"next",c.parameterProvider=e.parameterProvider?e.parameterProvider:null):t.extend(c,e)},c&&this.updatePageConfig(c,!0),this.webLinkingPageParser=function(e){var t,r,n,i,s,o={};r=e.getResponseHeader("Link").split(",");for(var u in r){t=r[u].trim().split(";");for(var p in t)n=t[p].trim(),0===n.indexOf("<")&&n.lastIndexOf(">")===t[p].length-1?i=n.substr(1,n.length-2).split("?")[1]:0===n.indexOf("rel=")&&(n.indexOf(c.previousIdentifier)>=0?s=c.previousIdentifier:n.indexOf(c.nextIdentifier)>=0&&(s=c.nextIdentifier));s&&(o[s]=i,s=a)}return o},this.headerPageParser=function(e){var t=e.getResponseHeader(c.previousIdentifier),r=e.getResponseHeader(c.nextIdentifier),a={},n={};return c.parameterProvider?(a=c.parameterProvider(e),n[c.previousIdentifier]=a[c.previousIdentifier],n[c.nextIdentifier]=a[c.nextIdentifier]):(n[c.previousIdentifier]=t?t.split("?")[1]:null,n[c.nextIdentifier]=r?r.split("?")[1]:null),n},this.bodyPageParser=function(e){var t={},r={};return c.parameterProvider?(r=c.parameterProvider(e),t[c.previousIdentifier]=r[c.previousIdentifier],t[c.nextIdentifier]=r[c.nextIdentifier]):(t[c.previousIdentifier]=e[c.previousIdentifier],t[c.nextIdentifier]=e[c.nextIdentifier]),t},this.formatJSONError=function(e){if("json"===this.getAjaxSettings().dataType)try{e.responseJSON=JSON.parse(e.responseText)}catch(t){}return e}},e.Pipeline.adapters.Rest.prototype.read=function(e){var r,n,i,s,o=this,u=this.getRecordId(),c=this.getAjaxSettings(),p=this.getPageConfig();if(e=e?e:{},e.query=e.query?e.query:{},r=e[u]?c.url+"/"+e[u]:c.url,p&&e.paging!==!1){e.paging||(e.paging={offset:e.offsetValue||0,limit:e.limitValue||10}),e.query=e.query||{};for(var d in e.paging)e.query[d]=e.paging[d]}return n=function(t,r,n){var i;p&&e.paging!==!1&&(i=o[p.metadataLocation+"PageParser"]("body"===p.metadataLocation?t:n),["previous","next"].forEach(function(r){t[r]=function(e,t,r){return function(n){return r.paging=!0,r.offsetValue=r.limitValue=a,r.query=t,r.success=n&&n.success?n.success:r.success,r.error=n&&n.error?n.error:r.error,e.read(r)}}(o,i[p[r+"Identifier"]],e)})),e.success&&e.success.apply(this,arguments)},i=function(t){t=o.formatJSONError(t),e.error&&e.error.apply(this,arguments)},s={type:"GET",data:e.query,success:n,error:i,url:r,statusCode:e.statusCode,complete:e.complete,headers:e.headers},e.jsonp&&(s.dataType="jsonp",s.jsonp=e.jsonp.callback?e.jsonp.callback:"callback",e.jsonp.customCallback&&(s.jsonpCallback=e.jsonp.customCallback)),t.ajax(this.addAuthIdentifier(t.extend({},this.getAjaxSettings(),s)))},e.Pipeline.adapters.Rest.prototype.save=function(e,r){var a,n,i,s,o,u=this,c=this.getRecordId(),p=this.getAjaxSettings();return e=e||{},r=r||{},a=e[c]?"PUT":"POST",n=e[c]?p.url+"/"+e[c]:p.url,i=function(){r.success&&r.success.apply(this,arguments)},s=function(e){e=u.formatJSONError(e),r.error&&r.error.apply(this,arguments)},o=t.extend({},p,{data:e,type:a,url:n,success:i,error:s,statusCode:r.statusCode,complete:r.complete,headers:r.headers}),"application/json"===o.contentType&&o.data&&"string"!=typeof o.data&&(o.data=JSON.stringify(o.data)),t.ajax(this.addAuthIdentifier(t.extend({},this.getAjaxSettings(),o)))},e.Pipeline.adapters.Rest.prototype.remove=function(e,r){var a,n,i,s,o,u=this,c=this.getRecordId(),p=this.getAjaxSettings(),d="";return"string"==typeof e||"number"==typeof e?a=e:e&&e[c]?a=e[c]:e&&!r&&(r=e),r=r||{},d=a?"/"+a:"",n=p.url+d,i=function(){r.success&&r.success.apply(this,arguments)},s=function(e){e=u.formatJSONError(e),r.error&&r.error.apply(this,arguments)},o={type:"DELETE",url:n,success:i,error:s,statusCode:r.statusCode,complete:r.complete,headers:r.headers},t.ajax(this.addAuthIdentifier(t.extend({},p,o)))}}(AeroGear,jQuery,uuid),function(e){e.DataManager=function(t){return this instanceof e.DataManager?(e.Core.call(this),this.lib="DataManager",this.type=t?t.type||"Memory":"Memory",this.collectionName="stores",this.add(t),undefined):new e.DataManager(t)},e.DataManager.prototype=e.Core,e.DataManager.constructor=e.DataManager,e.DataManager.adapters={},e.DataManager.STATUS_NEW=1,e.DataManager.STATUS_MODIFIED=2,e.DataManager.STATUS_REMOVED=0}(AeroGear,jQuery),function(e,t){e.DataManager.adapters.Memory=function(t,r){if(!(this instanceof e.DataManager.adapters.Memory))return new e.DataManager.adapters.Memory(t,r);r=r||{};var a=r.recordId?r.recordId:"id",n=null;this.getRecordId=function(){return a},this.getData=function(){return n},this.setData=function(e){n=e},this.emptyData=function(){n=null},this.addDataRecord=function(e){n=n||[],n.push(e)},this.updateDataRecord=function(e,t){n[e]=t},this.removeDataRecord=function(e){n.splice(e,1)},this.traverseObjects=function(e,t,r){for(;"object"==typeof t&&r;)e=Object.keys(t)[0],t=t[e],r=r[e];return t===r?!0:!1}},e.DataManager.adapters.Memory.prototype.read=function(e){var t={};return t[this.getRecordId()]=e,e?this.filter(t):this.getData()},e.DataManager.adapters.Memory.prototype.save=function(t,r){var a=!1;if(t=e.isArray(t)?t:[t],r)this.setData(t);else if(this.getData())for(var n=0;t.length>n;n++){for(var i in this.getData())if(this.getData()[i][this.getRecordId()]===t[n][this.getRecordId()]){this.updateDataRecord(i,t[n]),a=!0;break}a||this.addDataRecord(t[n]),a=!1}else this.setData(t);return this.getData()},e.DataManager.adapters.Memory.prototype.remove=function(t){if(!t)return this.emptyData(),this.getData();t=e.isArray(t)?t:[t];for(var r,a,n,i=0;t.length>i;i++){if("string"==typeof t[i]||"number"==typeof t[i])r=t[i];else{if(!t)continue;r=t[i][this.getRecordId()]}a=this.getData(!0);for(n in a)a[n][this.getRecordId()]===r&&this.removeDataRecord(n)}return this.getData()},e.DataManager.adapters.Memory.prototype.filter=function(r,a){var n,i,s,o,u,c=this;return n=r?this.getData().filter(function(n){var p,d,h=a?!1:!0,f=Object.keys(r);for(i=0;f.length>i;i++){if(r[f[i]].data)for(p=r[f[i]],d=p.matchAny?!1:!0,s=0;p.data.length>s;s++)if(e.isArray(n[f[i]]))if(n[f[i]].length){if(0===t(n[f]).not(p.data).length&&0===t(p.data).not(n[f]).length){d=!0;break}for(o=0;n[f[i]].length>o;o++){if(p.matchAny&&p.data[s]===n[f[i]][o]){if(d=!0,a)break;for(u=0;n[f[i]].length>u;u++)if(!a&&p.data[s]!==n[f[i]][u]){d=!1;break}}if(!p.matchAny&&p.data[s]!==n[f[i]][o]){d=!1;break}}}else d=!1;else if("object"==typeof p.data[s]){if(p.matchAny&&c.traverseObjects(f[i],p.data[s],n[f[i]])){d=!0;break}if(!p.matchAny&&!c.traverseObjects(f[i],p.data[s],n[f[i]])){d=!1;break}}else{if(p.matchAny&&p.data[s]===n[f[i]]){d=!0;break}if(!p.matchAny&&p.data[s]!==n[f[i]]){d=!1;break}}else if(e.isArray(n[f[i]]))if(d=a?!1:!0,n[f[i]].length)for(s=0;n[f[i]].length>s;s++){if(a&&r[f[i]]===n[f[i]][s]){d=!0;break}if(!a&&r[f[i]]!==n[f[i]][s]){d=!1;break}}else d=!1;else d="object"==typeof r[f[i]]?c.traverseObjects(f[i],r[f[i]],n[f[i]]):r[f[i]]===n[f[i]]?!0:!1;if(a&&d){h=!0;break}if(!a&&!d){h=!1;break}}return h}):this.getData()||[]}}(AeroGear,jQuery,uuid),function(e){e.DataManager.adapters.SessionLocal=function(t,r){if(!(this instanceof e.DataManager.adapters.SessionLocal))return new e.DataManager.adapters.SessionLocal(t,r);e.DataManager.adapters.Memory.apply(this,arguments);var a=r.storageType||"sessionStorage",n=t,i=document.location.pathname.replace(/[\/\.]/g,"-"),s=n+i,o=JSON.parse(window[a].getItem(s));o&&e.DataManager.adapters.Memory.prototype.save.call(this,o,!0),this.getStoreType=function(){return a},this.getStoreKey=function(){return s}},e.DataManager.adapters.SessionLocal.prototype=Object.create(new e.DataManager.adapters.Memory,{save:{value:function(t,r){var a=r&&r.reset?r.reset:!1,n=window[this.getStoreType()].getItem(this.getStoreKey()),i=e.DataManager.adapters.Memory.prototype.save.apply(this,[arguments[0],a]);try{window[this.getStoreType()].setItem(this.getStoreKey(),JSON.stringify(i)),r&&r.storageSuccess&&r.storageSuccess(i)}catch(s){if(n=n?JSON.parse(n):[],i=e.DataManager.adapters.Memory.prototype.save.apply(this,[n,!0]),!r||!r.storageError)throw s;r.storageError(s,t)}return i},enumerable:!0,configurable:!0,writable:!0},remove:{value:function(){var t=e.DataManager.adapters.Memory.prototype.remove.apply(this,arguments);return window[this.getStoreType()].setItem(this.getStoreKey(),JSON.stringify(t)),t},enumerable:!0,configurable:!0,writable:!0}})}(AeroGear,jQuery,uuid),function(e){e.Auth=function(t){return this instanceof e.Auth?(e.Core.call(this),this.lib="Auth",this.type=t?t.type||"Rest":"Rest",this.collectionName="modules",this.add(t),undefined):new e.Auth(t)},e.Auth.prototype=e.Core,e.Auth.constructor=e.Auth,e.Auth.adapters={}}(AeroGear,jQuery),function(e,t){e.Auth.adapters.Rest=function(r,a){if(!(this instanceof e.Auth.adapters.Rest))return new e.Auth.adapters.Rest(r,a);a=a||{};var n=a.endpoints||{},i=r,s=!!a.agAuth,o=a.baseURL,u=a.tokenName||"Auth-Token";this.addAuthIdentifier=function(e){return e.headers=e.headers?e.headers:{},e.headers[u]=sessionStorage.getItem("ag-auth-"+i),t.extend({},e)},this.deauthorize=function(){sessionStorage.removeItem("ag-auth-"+i)},this.getSettings=function(){return a},this.getEndpoints=function(){return n},this.getName=function(){return i},this.getAGAuth=function(){return s},this.getBaseURL=function(){return o},this.getTokenName=function(){return u}},e.Auth.adapters.Rest.prototype.enroll=function(e,r){r=r||{};var a=this,n=this.getName(),i=this.getTokenName(),s=this.getBaseURL(),o=this.getEndpoints(),u=this.getAGAuth(),c=function(e,t,s){sessionStorage.setItem("ag-auth-"+n,a.getAGAuth()?s.getResponseHeader(i):"true"),r.success&&r.success.apply(this,arguments)},p=function(e,t,a){var n;try{e.responseJSON=JSON.parse(e.responseText),n=[e,t,a]}catch(i){n=arguments}r.error&&r.error.apply(this,n)},d={success:c,error:p,data:e},h="";return r.contentType?d.contentType=r.contentType:u&&(d.contentType="application/json"),r.dataType?d.dataType=r.dataType:u&&(d.dataType="json"),r.baseURL?h=r.baseURL:s&&(h=s),h+=o.enroll?o.enroll:"auth/enroll",h.length&&(d.url=h),t.ajax(t.extend({},this.getSettings(),{type:"POST"},d))},e.Auth.adapters.Rest.prototype.login=function(e,r){r=r||{};var a=this,n=this.getName(),i=this.getTokenName(),s=this.getBaseURL(),o=this.getEndpoints(),u=this.getAGAuth(),c=function(e,t,s){sessionStorage.setItem("ag-auth-"+n,a.getAGAuth()?s.getResponseHeader(i):"true"),r.success&&r.success.apply(this,arguments)},p=function(e,t,a){var n;try{e.responseJSON=JSON.parse(e.responseText),n=[e,t,a]}catch(i){n=arguments}r.error&&r.error.apply(this,n)},d={success:c,error:p,data:e},h="";return r.contentType?d.contentType=r.contentType:u&&(d.contentType="application/json"),r.dataType?d.dataType=r.dataType:u&&(d.dataType="json"),r.baseURL?h=r.baseURL:s&&(h=s),h+=o.login?o.login:"auth/login",h.length&&(d.url=h),t.ajax(t.extend({},this.getSettings(),{type:"POST"},d))},e.Auth.adapters.Rest.prototype.logout=function(e){e=e||{};var r=this,a=this.getName(),n=this.getTokenName(),i=this.getBaseURL(),s=this.getEndpoints(),o=function(){r.deauthorize(),e.success&&e.success.apply(this,arguments)},u=function(t,r,a){var n;try{t.responseJSON=JSON.parse(t.responseText),n=[t,r,a]}catch(i){n=arguments}e.error&&e.error.apply(this,n)},c={success:o,error:u},p="";return e.baseURL?p=e.baseURL:i&&(p=i),p+=s.logout?s.logout:"auth/logout",p.length&&(c.url=p),c.headers={},c.headers[n]=sessionStorage.getItem("ag-auth-"+a),t.ajax(t.extend({},this.getSettings(),{type:"POST"},c))}}(AeroGear,jQuery);
//@ sourceMappingURL=dist/aerogear.js.map