From 88cac72e0e32a0fbe1a2f1dbd6976bbd6a3b220b Mon Sep 17 00:00:00 2001 From: Travis CI Date: Wed, 17 Feb 2016 13:29:19 +0000 Subject: [PATCH] Travis CI - [ci skip] - automatic dist folder --- dist/kuzzle.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/kuzzle.min.js b/dist/kuzzle.min.js index dfbf2efd0..e3f9bef16 100644 --- a/dist/kuzzle.min.js +++ b/dist/kuzzle.min.js @@ -1,4 +1,4 @@ -// Official Javascript SDK for Kuzzle v1.6.2 - License: Apache-2.0 +// Official Javascript SDK for Kuzzle v1.6.3 - License: Apache-2.0 !function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gb;b++)0===(3&b)&&(a=4294967296*Math.random()),e[b]=a>>>((3&b)<<3)&255;return e},"undefined"!=typeof console&&console.warn&&console.warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()")}}function e(){if("function"==typeof a)try{var b=a("crypto").randomBytes;l=j=b&&function(){return b(16)},j()}catch(c){}}function f(a,b,c){var d=b&&c||0,e=0;for(b=b||[],a.toLowerCase().replace(/[0-9a-f]{2}/g,function(a){16>e&&(b[d+e++]=q[a])});16>e;)b[d+e++]=0;return b}function g(a,b){var c=b||0,d=p;return d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]}function h(a,b,c){var d=b&&c||0,e=b||[];a=a||{};var f=null!=a.clockseq?a.clockseq:u,h=null!=a.msecs?a.msecs:(new Date).getTime(),i=null!=a.nsecs?a.nsecs:w+1,j=h-v+(i-w)/1e4;if(0>j&&null==a.clockseq&&(f=f+1&16383),(0>j||h>v)&&null==a.nsecs&&(i=0),i>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");v=h,w=i,u=f,h+=122192928e5;var k=(1e4*(268435455&h)+i)%4294967296;e[d++]=k>>>24&255,e[d++]=k>>>16&255,e[d++]=k>>>8&255,e[d++]=255&k;var l=h/4294967296*1e4&268435455;e[d++]=l>>>8&255,e[d++]=255&l,e[d++]=l>>>24&15|16,e[d++]=l>>>16&255,e[d++]=f>>>8|128,e[d++]=255&f;for(var m=a.node||t,n=0;6>n;n++)e[d+n]=m[n];return b?b:g(e)}function i(a,b,c){var d=b&&c||0;"string"==typeof a&&(b="binary"===a?new o(16):null,a=null),a=a||{};var e=a.random||(a.rng||j)();if(e[6]=15&e[6]|64,e[8]=63&e[8]|128,b)for(var f=0;16>f;f++)b[d+f]=e[f];return b||g(e)}var j,k,l,m,n;c?d():e();for(var o="function"==typeof Buffer?Buffer:Array,p=[],q={},r=0;256>r;r++)p[r]=(r+256).toString(16).substr(1),q[p[r]]=r;var s=j(),t=[1|s[0],s[1],s[2],s[3],s[4],s[5]],u=16383&(s[6]<<8|s[7]),v=0,w=0,x=i;x.v1=h,x.v4=i,x.parse=f,x.unparse=g,x.BufferClass=o,x._rng=j,x._mathRNG=k,x._nodeRNG=l,x._whatwgRNG=m,"undefined"!=typeof b&&b.exports?b.exports=x:"function"==typeof define&&define.amd?define(function(){return x}):(n=c.uuid,x.noConflict=function(){return c.uuid=n,x},c.uuid=x)}("undefined"!=typeof window?window:null)},{}],2:[function(a,b,c){function d(){var a=this,b=Date.now(),c=-1;a.queueTTL>0&&(a.offlineQueue.forEach(function(d,e){d.ts0&&a.offlineQueue.length>a.queueMaxSize&&a.offlineQueue.splice(0,a.offlineQueue.length-a.queueMaxSize)}function e(a,b){var c=Date.now(),d=this;(void 0!==d.jwtToken||b)&&d.socket.once(a.requestId,function(c){c.error&&"Token expired"===c.error.message&&(d.jwtToken=void 0,d.emitEvent("jwtTokenExpired",a,b)),b&&b(c.error,c)}),d.socket.emit("kuzzle",a),d.requestHistory[a.requestId]=c,Object.keys(d.requestHistory).forEach(function(a){d.requestHistory[a]0?(e.call(a,a.offlineQueue[0].query,a.offlineQueue[0].cb),a.offlineQueue.shift(),setTimeout(function(){f.call(a)},Math.max(0,a.replayInterval))):a.queuing=!1}function g(){var a=this;Object.keys(a.subscriptions).forEach(function(b){Object.keys(a.subscriptions[b]).forEach(function(c){var d=a.subscriptions[b][c];d.renew(d.callback)})})}var h=a("node-uuid"),i=a("./kuzzleDataCollection"),j=a("./security/kuzzleSecurity"),k=a("./security/kuzzleUser");b.exports=Kuzzle=function(b,c,d){var e=this;if(!(this instanceof Kuzzle))return new Kuzzle(b,c,d);if(d||"function"!=typeof c||(d=c,c=null),!b||""===b)throw new Error("URL argument missing");return Object.defineProperties(this,{collections:{value:{},writable:!0},connectCB:{value:d},eventListeners:{value:{connected:{lastEmitted:null,listeners:[]},error:{lastEmitted:null,listeners:[]},disconnected:{lastEmitted:null,listeners:[]},reconnected:{lastEmitted:null,listeners:[]},jwtTokenExpired:{lastEmitted:null,listeners:[]}}},eventTimeout:{value:200},io:{value:null,writable:!0},queuing:{value:!1,writable:!0},requestHistory:{value:{},writable:!0},socket:{value:null,writable:!0},state:{value:"initializing",writable:!0},subscriptions:{value:{pending:{}},writable:!0},autoReconnect:{value:c&&"boolean"==typeof c.autoReconnect?c.autoReconnect:!0,enumerable:!0},defaultIndex:{value:c&&"string"==typeof c.defaultIndex?c.defaultIndex:void 0,writable:!0,enumerable:!0},reconnectionDelay:{value:c&&"number"==typeof c.reconnectionDelay?c.reconnectionDelay:1e3,enumerable:!0},url:{value:b,enumerable:!0},autoQueue:{value:!1,enumerable:!0,writable:!0},autoReplay:{value:!1,enumerable:!0,writable:!0},autoResubscribe:{value:!0,enumerable:!0,writable:!0},headers:{value:{},enumerable:!0,writable:!0},metadata:{value:{},enumerable:!0,writable:!0},offlineQueue:{value:[],enumerable:!0,writable:!0},queueFilter:{value:null,enumerable:!0,writable:!0},queueMaxSize:{value:500,enumerable:!0,writable:!0},queueTTL:{value:12e4,enumerable:!0,writable:!0},replayInterval:{value:10,enumerable:!0,writable:!0},jwtToken:{value:void 0,enumerable:!0,writable:!0}}),"undefined"!=typeof window&&window.io?this.io=window.io:this.io=a("socket.io-client"),c&&(Object.keys(c).forEach(function(a){e.hasOwnProperty(a)&&Object.getOwnPropertyDescriptor(e,a).writable&&(e[a]=c[a])}),"auto"===c.offlineMode&&this.autoReconnect&&(this.autoQueue=this.autoReplay=this.autoResubscribe=!0)),Object.defineProperty(this,"isValid",{value:function(){if("disconnected"===e.state)throw new Error("This Kuzzle object has been invalidated. Did you try to access it after a disconnect call?")}}),Object.defineProperty(this,"addHeaders",{value:function(a,b){return Object.keys(b).forEach(function(c){a[c]||(a[c]=b[c])}),a}}),Object.defineProperty(this,"callbackRequired",{value:function(a,b){if(!b||"function"!=typeof b)throw new Error(a+": a callback argument is required for read queries")}}),Object.defineProperty(this,"security",{value:new j(this),enumerable:!0}),Object.defineProperty(this,"emitEvent",{value:function(a){var b=Date.now(),c=Array.prototype.slice.call(arguments,1);return this.eventListeners[a].lastEmitted&&this.eventListeners[a].lastEmitted>=b-this.eventTimeout?!1:(this.eventListeners[a].listeners.forEach(function(a){a.fn.apply(this,c)}),void(this.eventListeners[a].lastEmitted=b))}}),c&&c.connect&&"auto"!==c.connect?this.state="ready":this.connect(),this.bluebird?this.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["getAllStatistics","getServerInfo","getStatistics","listCollections","listIndexes","login","logout","now","query","checkToken","whoAmI"];return d&&-1!==e.indexOf(a)}}):void 0},Kuzzle.prototype.connect=function(){var a=this;return-1===["initializing","ready","disconnected","error","offline"].indexOf(this.state)?(a.connectCB&&a.connectCB(null,a),a):(a.state="connecting",a.socket=a.io(a.url,{reconnection:a.autoReconnect,reconnectionDelay:a.reconnectionDelay,forceNew:!0}),a.socket.once("connect",function(){a.state="connected",g.call(a),f.call(a),a.emitEvent("connected"),a.connectCB&&a.connectCB(null,a)}),a.socket.on("connect_error",function(b){a.state="error",a.emitEvent("error"),a.connectCB&&a.connectCB(b)}),a.socket.on("disconnect",function(){a.state="offline",a.autoReconnect||a.disconnect(),a.autoQueue&&(a.queuing=!0),a.emitEvent("disconnected")}),a.socket.on("reconnect",function(){var b=function(){a.autoResubscribe&&g.call(a),a.autoReplay&&(d.call(a),f.call(a)),a.emitEvent("reconnected")};a.state="connected",a.jwtToken?a.checkToken(a.jwtToken,function(c,d){(c||!d.valid)&&(a.jwtToken=void 0,a.emitEvent("jwtTokenExpired")),b()}):b()}),this)},Kuzzle.prototype.setJwtToken=function(a){return this.jwtToken=a,this},Kuzzle.prototype.getJwtToken=function(){return this.jwtToken},Kuzzle.prototype.login=function(a,b,c,d){var e=this,f={strategy:a};return d||"function"!=typeof c||(d=c,c=null),Object.keys(b).forEach(function(a){f[a]=b[a]}),-1!==["number","string"].indexOf(typeof c)&&(f.expiresIn=c),this.query({controller:"auth",action:"login"},{body:f},{queuable:!1},function(a,b){if(null===a)e.setJwtToken(b.result.jwt),g.call(e),"function"==typeof d&&d(null,e);else{if("function"!=typeof d)throw new Error(a.message);d(a)}}),e},Kuzzle.prototype.logout=function(a){var b=this,c={action:"logout",controller:"auth",requestId:h.v4(),body:{}};return this.query({controller:"auth",action:"logout"},c,{queuable:!1},function(c){null===c?(b.setJwtToken(void 0),"function"==typeof a&&a(null,b)):"function"==typeof a&&a(c)}),b},Kuzzle.prototype.checkToken=function(a,b){var c=this,d={body:{token:a}};return this.callbackRequired("Kuzzle.checkToken",b),this.query({controller:"auth",action:"checkToken"},d,{},b),c},Kuzzle.prototype.whoAmI=function(a){var b=this;return b.callbackRequired("Kuzzle.whoAmI",a),b.query({controller:"auth",action:"getCurrentUser"},{},{},function(c,d){return c?a(c):void a(null,new k(b.security,d.result._id,d.result._source))}),b},Kuzzle.prototype.addListener=function(a,b){var c,d=Object.keys(this.eventListeners),e=typeof b;if(this.isValid(),-1===d.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+d.toString());if("function"!==e)throw new Error("Invalid listener type: expected a function, got a "+e);return c=h.v1(),this.eventListeners[a].listeners.push({id:c,fn:b}),c},Kuzzle.prototype.getAllStatistics=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.getAllStatistics",b),this.query({controller:"admin",action:"getAllStats"},{},a,function(a,c){return a?b(a):void b(null,c.result.hits)}),this},Kuzzle.prototype.getStatistics=function(a,b,c){var d;return c||(1===arguments.length?(c=arguments[0],b=null,a=null):(c=arguments[1],"object"==typeof arguments[0]?(b=arguments[0],a=null):(a=arguments[0],b=null))),d=function(b,d){return b?c(b):void(a?c(null,d.result.hits):c(null,[d.result]))},this.callbackRequired("Kuzzle.getStatistics",c),a?this.query({controller:"admin",action:"getStats"},{body:{startTime:a}},b,d):this.query({controller:"admin",action:"getLastStats"},{},b,d),this},Kuzzle.prototype.dataCollectionFactory=function(a,b){if(this.isValid(),1===arguments.length?(b=arguments[0],a=this.defaultIndex):2===arguments.length&&"object"==typeof b&&(headers=b,b=a,a=this.defaultIndex),!a)throw new Error("Unable to create a new data collection object: no index specified");return this.collections[a]||(this.collections[a]={}),this.collections[a][b]||(this.collections[a][b]=new i(this,a,b)),this.collections[a][b]},Kuzzle.prototype.flushQueue=function(){return this.offlineQueue=[],this},Kuzzle.prototype.listCollections=function(){var a,b,c,d="all",e=Array.prototype.slice.call(arguments);if(e.forEach(function(d){switch(typeof d){case"string":a=d;break;case"object":b=d;break;case"function":c=d}}),!a){if(!this.defaultIndex)throw new Error("Kuzzle.listCollections: index required");a=this.defaultIndex}return this.callbackRequired("Kuzzle.listCollections",c),b&&b.type&&(d=b.type),this.query({index:a,controller:"read",action:"listCollections"},{body:{type:d}},b,function(a,b){return a?c(a):c(null,b.result.collections)}),this},Kuzzle.prototype.listIndexes=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.listIndexes",b),this.query({controller:"read",action:"listIndexes"},{},a,function(a,c){return a?b(a):b(null,c.result.indexes)}),this},Kuzzle.prototype.disconnect=function(){var a;this.logout(),this.state="disconnected",this.socket.close(),this.socket=null;for(a in this.collections)this.collections.hasOwnProperty(a)&&delete this.collections[a]},Kuzzle.prototype.getServerInfo=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.getServerInfo",b),this.query({controller:"read",action:"serverInfo"},{},a,function(a,c){return a?b(a):void b(null,c.result.serverInfo)}),this},Kuzzle.prototype.now=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.now",b),this.query({controller:"read",action:"now"},{},a,function(a,c){return a?b(a):void b(null,c.result.now)}),this},Kuzzle.prototype.query=function(a,b,c,f){var g,i={action:a.action,controller:a.controller,metadata:this.metadata},j=this;if(this.isValid(),f||"function"!=typeof c||(f=c,c=null),c&&(c.metadata&&Object.keys(c.metadata).forEach(function(a){i.metadata[a]=c.metadata[a]}),c.queuable===!1&&"offline"===j.state))return j;b.metadata&&Object.keys(b.metadata).forEach(function(a){i.metadata[a]=b.metadata[a]});for(g in b)"metadata"!==g&&b.hasOwnProperty(g)&&(i[g]=b[g]);return i=j.addHeaders(i,this.headers),void 0===j.jwtToken||"auth"===i.controller&&"checkToken"===i.action||(i.headers=i.headers||{},i.headers.authorization="Bearer "+j.jwtToken),a.collection&&(i.collection=a.collection),a.index&&(i.index=a.index),i.requestId||(i.requestId=h.v4()),"connected"===j.state||c&&c.queuable===!1?"connected"===j.state?e.call(this,i,f):f&&f(new Error("Unable to execute request: not connected to a Kuzzle server.\nDiscarded request: "+i)):(j.queuing||-1!==["initializing","connecting"].indexOf(j.state))&&(d.call(this,i,f),j.queueFilter?j.queueFilter(i)&&j.offlineQueue.push({ts:Date.now(),query:i,cb:f}):j.offlineQueue.push({ts:Date.now(),query:i,cb:f})),j},Kuzzle.prototype.removeAllListeners=function(a){var b=Object.keys(this.eventListeners),c=this;if(a){if(-1===b.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+b.toString());this.eventListeners[a].listeners=[]}else b.forEach(function(a){c.eventListeners[a].listeners=[]})},Kuzzle.prototype.removeListener=function(a,b){var c=Object.keys(this.eventListeners),d=this;if(-1===c.indexOf(a))throw new Error("["+a+"] is not a known event. Known events: "+c.toString());this.eventListeners[a].listeners.forEach(function(c,e){c.id===b&&d.eventListeners[a].listeners.splice(e,1)})},Kuzzle.prototype.replayQueue=function(){return"offline"===this.state||this.autoReplay||(d.call(this),f.call(this)),this},Kuzzle.prototype.setDefaultIndex=function(a){if("string"!=typeof a)throw new Error("Invalid default index: ["+a+"] (an index name is expected)");if(0===a.length)throw new Error("Cannot set an empty index as the default index");return this.defaultIndex=a,this},Kuzzle.prototype.setHeaders=function(a,b){var c=this;if("object"!=typeof a||Array.isArray(a))throw new Error("Expected a content object, received a "+typeof a);return b?c.headers=a:Object.keys(a).forEach(function(b){c.headers[b]=a[b]}),c},Kuzzle.prototype.startQueuing=function(){return"offline"!==this.state||this.autoQueue||(this.queuing=!0),this},Kuzzle.prototype.stopQueuing=function(){return"offline"!==this.state||this.autoQueue||(this.queuing=!1),this}},{"./kuzzleDataCollection":3,"./security/kuzzleSecurity":9,"./security/kuzzleUser":11,"node-uuid":1,"socket.io-client":void 0}],3:[function(a,b,c){function d(a,b,c){if(!b||!c)throw new Error("The KuzzleDataCollection object constructor needs an index and a collection arguments");return Object.defineProperties(this,{collection:{value:c,enumerable:!0},index:{value:b,enumerable:!0},kuzzle:{value:a,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0}}),Object.defineProperty(this,"buildQueryArgs",{value:function(a,b){return{controller:a,action:b,collection:this.collection,index:this.index}}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["publishMessage","setHeaders","subscribe"];return d&&-1===e.indexOf(a)}}):this}var e=a("./kuzzleDocument"),f=a("./kuzzleDataMapping"),g=a("./kuzzleRoom");d.prototype.advancedSearch=function(a,b,c){var d,f=this;return c||"function"!=typeof b||(c=b,b=null),f.kuzzle.callbackRequired("KuzzleDataCollection.advancedSearch",c),d=f.kuzzle.addHeaders({body:a},this.headers),f.kuzzle.query(this.buildQueryArgs("read","search"),d,b,function(a,b){var d=[];return a?c(a):(b.result.hits.forEach(function(a){var b=new e(f,a._id,a._source);b.version=a._version,d.push(b)}),void c(null,{total:b.result.total,documents:d}))}),this},d.prototype.count=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),this.kuzzle.callbackRequired("KuzzleDataCollection.count",c),d=this.kuzzle.addHeaders({body:a},this.headers),this.kuzzle.query(this.buildQueryArgs("read","count"),d,b,function(a,b){return a?c(a):void c(null,b.result.count)}),this},d.prototype.create=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("write","createCollection"),c,a,b),this},d.prototype.createDocument=function(a,b,c,d){var f=this,g={},h="create";return a&&"string"!=typeof a&&(d=c,c=b,b=a,a=null),d||"function"!=typeof c||(d=c,c=null),b instanceof e?g=b.serialize():g.body=b,c&&(h=c.updateIfExist?"createOrReplace":"create"),a&&(g._id=a),g=f.kuzzle.addHeaders(g,f.headers),d?f.kuzzle.query(this.buildQueryArgs("write",h),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),c.version=b.result._version,void d(null,c))}):f.kuzzle.query(this.buildQueryArgs("write",h),g,c),this},d.prototype["delete"]=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("admin","deleteCollection"),c,a,b),this},d.prototype.deleteDocument=function(a,b,c){var d,e={};return"string"==typeof a?(e._id=a,d="delete"):(e.body=a,d="deleteByQuery"),c||"function"!=typeof b||(c=b,b=null),e=this.kuzzle.addHeaders(e,this.headers),c?this.kuzzle.query(this.buildQueryArgs("write",d),e,b,function(a,b){return a?c(a):void("delete"===d?c(null,[b.result._id]):c(null,b.result.ids))}):this.kuzzle.query(this.buildQueryArgs("write",d),e,b),this},d.prototype.fetchDocument=function(a,b,c){var d={_id:a},f=this;return c||"function"!=typeof b||(c=b,b=null),f.kuzzle.callbackRequired("KuzzleDataCollection.fetch",c),d=f.kuzzle.addHeaders(d,this.headers),f.kuzzle.query(this.buildQueryArgs("read","get"),d,b,function(a,b){var d;return a?c(a):(d=new e(f,b.result._id,b.result._source),d.version=b.result._version,void c(null,d))}),this},d.prototype.fetchAllDocuments=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDataCollection.fetchAll",b),this.advancedSearch({},a,b),this},d.prototype.getMapping=function(a,b){var c;return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDataCollection.getMapping",b),c=new f(this),c.refresh(a,b),this},d.prototype.publishMessage=function(a,b){var c={};return a instanceof e?c=a.serialize():c.body=a,c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("write","publish"),c,b),this},d.prototype.replaceDocument=function(a,b,c,d){var f=this,g={_id:a,body:b};return d||"function"!=typeof c||(d=c,c=null),g=f.kuzzle.addHeaders(g,this.headers),d?f.kuzzle.query(this.buildQueryArgs("write","createOrReplace"),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),c.version=b.result._version,void d(null,c))}):f.kuzzle.query(this.buildQueryArgs("write","createOrReplace"),g,c),this},d.prototype.subscribe=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),this.kuzzle.callbackRequired("KuzzleDataCollection.subscribe",c),d=new g(this,b),d.renew(a,c)},d.prototype.truncate=function(a,b){var c={};return b||"function"!=typeof a||(b=a,a=null),c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.buildQueryArgs("admin","truncateCollection"),c,a,b),this},d.prototype.updateDocument=function(a,b,c,d){var f={_id:a,body:b},g=this;return d||"function"!=typeof c||(d=c,c=null),f=g.kuzzle.addHeaders(f,this.headers),d?g.kuzzle.query(this.buildQueryArgs("write","update"),f,c,function(a,b){var c;return a?d(a):(c=new e(g,b.result._id),void c.refresh(d))}):g.kuzzle.query(this.buildQueryArgs("write","update"),f,c),g},d.prototype.documentFactory=function(a,b){return new e(this,a,b)},d.prototype.roomFactory=function(a){return new g(this,a)},d.prototype.dataMappingFactory=function(a){return new f(this,a)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{"./kuzzleDataMapping":4,"./kuzzleDocument":5,"./kuzzleRoom":6}],4:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{collection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},mapping:{value:b||{},enumerable:!0,writable:!0}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["set","setHeaders"];return d&&-1===e.indexOf(a)}}):this}d.prototype.apply=function(a,b){var c=this,d=this.kuzzle.addHeaders({body:{properties:this.mapping}},this.headers);return b||"function"!=typeof a||(b=a,a=null),c.kuzzle.query(this.collection.buildQueryArgs("admin","updateMapping"),d,a,function(d){return d?b?b(d):!1:void c.refresh(a,b)}),this},d.prototype.refresh=function(a,b){var c=this,d=this.kuzzle.addHeaders({},this.headers);return b||"function"!=typeof a||(b=a,a=null),this.kuzzle.query(this.collection.buildQueryArgs("admin","getMapping"),d,a,function(a,d){return a?b?b(a):!1:d.result[c.collection.index]?d.result[c.collection.index].mappings[c.collection.collection]?(c.mapping=d.result[c.collection.index].mappings[c.collection.collection].properties,void(b&&b(null,c))):b?b(new Error("No mapping found for collection "+c.collection.collection)):!1:b?b(new Error("No mapping found for index "+c.collection.index)):!1}),this},d.prototype.set=function(a,b){return this.mapping[a]=b,this},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{}],5:[function(a,b,c){function d(a,b,c){return Object.defineProperties(this,{collection:{value:a.collection,enumerable:!0},dataCollection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},id:{value:void 0,enumerable:!0,writable:!0},content:{value:{},writable:!0,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},version:{value:void 0,enumerable:!0,writable:!0}}),!c&&b&&"object"==typeof b&&(c=b,b=null),c&&(c._version&&(this.version=c._version,delete c._version),this.setContent(c,!0)),b&&Object.defineProperty(this,"id",{value:b,enumerable:!0}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["delete","refresh","save"];return d&&-1!==e.indexOf(a)}}):this}d.prototype.serialize=function(){var a={};return this.id&&(a._id=this.id),a.body=this.content,a._version=this.version,a=this.kuzzle.addHeaders(a,this.headers)},d.prototype.toString=function(){return JSON.stringify(this.serialize())},d.prototype["delete"]=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),!this.id)throw new Error("KuzzleDocument.delete: cannot delete a document without a document ID");return b?this.kuzzle.query(this.dataCollection.buildQueryArgs("write","delete"),this.serialize(),a,function(a){return a?b(a):void b(null,c)}):this.kuzzle.query(this.dataCollection.buildQueryArgs("write","delete"),this.serialize(),a),this},d.prototype.refresh=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),!c.id)throw new Error("KuzzleDocument.refresh: cannot retrieve a document if no ID has been provided");this.kuzzle.callbackRequired("KuzzleDocument.refresh",b),c.kuzzle.query(c.dataCollection.buildQueryArgs("read","get"),{_id:c.id},a,function(a,e){var f;return a?b(a):(f=new d(c.dataCollection,c.id,e.result._source),f.version=e.result._version,void b(null,f))})},d.prototype.save=function(a,b){var c=this.serialize(),d=this;return a&&void 0===b&&"function"==typeof a&&(b=a,a=null),d.kuzzle.query(this.dataCollection.buildQueryArgs("write","createOrReplace"),c,a,function(a,c){return a?b?b(a):!1:(d.id=c.result._id,d.version=c.result._version,void(b&&b(null,d)))}),d},d.prototype.publish=function(a){var b=this.serialize();return this.kuzzle.query(this.dataCollection.buildQueryArgs("write","publish"),b,a),this},d.prototype.setContent=function(a,b){var c=this;return b?this.content=a:Object.keys(a).forEach(function(b){c.content[b]=a[b]}),this},d.prototype.subscribe=function(a,b){var c;if(a&&!b&&"function"==typeof a&&(b=a,a=null),this.kuzzle.callbackRequired("KuzzleDocument.subscribe",b),!this.id)throw new Error("KuzzleDocument.subscribe: cannot subscribe to a document if no ID has been provided");return c={ids:{values:[this.id]}},this.dataCollection.subscribe(c,a,b)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{}],6:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{callback:{value:null,writable:!0},channel:{value:null,writable:!0},id:{value:g.v4()},lastRenewal:{value:null,writable:!0},notifier:{value:null,writable:!0},queue:{value:[],writable:!0},renewalDelay:{value:500},scope:{value:b&&b.scope?b.scope:"all"},state:{value:b&&b.state?b.state:"done"},subscribing:{value:!1,writable:!0},users:{value:b&&b.users?b.users:"none"},collection:{value:a,enumerable:!0},kuzzle:{value:a.kuzzle,enumerable:!0},filters:{value:null,enumerable:!0,writable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0},metadata:{value:b&&b.metadata?b.metadata:{},enumerable:!0,writable:!0},roomId:{value:null,enumerable:!0,writable:!0},subscribeToSelf:{value:b&&"boolean"==typeof b.subscribeToSelf?b.subscribeToSelf:!0,enumerable:!0,writable:!0}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["count"];return d&&-1!==e.indexOf(a)}}):this}function e(a){return a.error?this.callback(a.error):"jwtTokenExpired"===a.action?(this.kuzzle.jwtToken=void 0,this.kuzzle.emitEvent("jwtTokenExpired")):void(this.kuzzle.requestHistory[a.requestId]?(this.subscribeToSelf&&this.callback(null,a),delete this.kuzzle.requestHistory[a.requestId]):this.callback(null,a))}function f(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}var g=a("node-uuid");d.prototype.count=function(a){var b;return this.kuzzle.callbackRequired("KuzzleRoom.count",a),b=this.kuzzle.addHeaders({body:{roomId:this.roomId}},this.headers),this.subscribing?(this.queue.push({action:"count",args:[a]}),this):(this.kuzzle.query(this.collection.buildQueryArgs("subscribe","count"),b,function(b,c){return b?a(b):void a(null,c.result.count)}),this)},d.prototype.renew=function(a,b){var c=Date.now(),d={scope:this.scope,state:this.state,users:this.users},g=this;return!b&&a&&"function"==typeof a&&(b=a,a=null),g.lastRenewal&&c-g.lastRenewal<=g.renewalDelay?g:(a&&(g.filters=a),"connected"!==g.kuzzle.state?(g.callback=b,g.kuzzle.subscriptions.pending[g.id]=g,g):g.subscribing?(g.queue.push({action:"renew",args:[a,b]}),g):(g.kuzzle.callbackRequired("KuzzleRoom.renew",b),g.unsubscribe(),g.roomId=null,g.subscribing=!0,g.callback=b,g.kuzzle.subscriptions.pending[g.id]=g,d.body=g.filters,d=g.kuzzle.addHeaders(d,this.headers),g.kuzzle.query(g.collection.buildQueryArgs("subscribe","on"),d,{metadata:g.metadata},function(a,b){if(delete g.kuzzle.subscriptions.pending[g.id],g.subscribing=!1,a)throw g.queue=[],new Error("Error during Kuzzle subscription: "+a.message);g.lastRenewal=c,g.roomId=b.result.roomId,g.channel=b.result.channel,g.kuzzle.subscriptions[g.roomId]||(g.kuzzle.subscriptions[g.roomId]={}),g.kuzzle.subscriptions[g.roomId][g.id]=g,g.notifier=e.bind(g),g.kuzzle.socket.on(g.channel,g.notifier),f.call(g)}),g))},d.prototype.unsubscribe=function(){var a,b=this,c=b.roomId;return b.subscribing?(b.queue.push({action:"unsubscribe",args:[]}),b):(c&&(b.kuzzle.socket.off(b.channel,this.notifier),1===Object.keys(b.kuzzle.subscriptions[c]).length?(delete b.kuzzle.subscriptions[c],0===Object.keys(b.kuzzle.subscriptions.pending).length?b.kuzzle.query(b.collection.buildQueryArgs("subscribe","off"),{body:{roomId:c}}):a=setInterval(function(){0===Object.keys(b.kuzzle.subscriptions.pending).length&&(b.kuzzle.subscriptions[c]||b.kuzzle.query(b.collection.buildQueryArgs("subscribe","off"),{body:{roomId:c}}),clearInterval(a))},100)):delete b.kuzzle.subscriptions[c][b.id],b.roomId=null),b)},d.prototype.setHeaders=function(a,b){return this.kuzzle.setHeaders.call(this,a,b),this},b.exports=d},{"node-uuid":1}],7:[function(a,b,c){function d(a,b,c){return e.call(this,a,b,c),Object.defineProperties(this,{deleteActionName:{value:"deleteProfile"}}),c&&c.roles&&(c.roles=c.roles.map(function(b){return b._id&&b._source?new f(a,b._id,b._source):b})),a.kuzzle.bluebird?a.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["hydrate","save"];return d&&-1!==e.indexOf(a)}}):void 0}var e=a("./kuzzleSecurityDocument"),f=a("./kuzzleRole");d.prototype=Object.create(e.prototype,{constructor:{value:d}}),d.prototype.save=function(a,b){var c,d=this;if(!this.content.roles)throw new Error('Argument "roles" is mandatory in a profile. This argument contains an array of KuzzleRole or an array of id string');return a&&void 0===b&&"function"==typeof a&&(b=a,a=null),c=this.serialize(),d.kuzzle.query(d.kuzzleSecurity.buildQueryArgs("createOrReplaceProfile"),c,a,function(a){return a?b?b(a):!1:void(b&&b(null,d))}),d},d.prototype.addRole=function(a){if("string"!=typeof a&&!(a instanceof f))throw new Error('Parameter "roles" must be a KuzzleRole or a id string');return this.content.roles||(this.content.roles=[]),this.content.roles.push(a),this},d.prototype.setRoles=function(a){if(!Array.isArray(a))throw new Error('Parameter "roles" must be an array of KuzzleRole or an array of string');return a.map(function(a){if("string"!=typeof a&&!(a instanceof f))throw new Error('Parameter "roles" must be an array of KuzzleRole or an array of string')}),this.content.roles=a,this},d.prototype.hydrate=function(a,b){var c=this,e={ids:[]};e.ids=this.content.roles.map(function(a){return"string"==typeof a?a:a instanceof f?a.id:void 0}),a&&void 0===b&&"function"==typeof a&&(b=a,a=null),c.kuzzle.callbackRequired("KuzzleProfile.hydrate",b),c.kuzzle.query(c.kuzzleSecurity.buildQueryArgs("mGetRoles"),{body:e},a,function(a,e){return a?b(a):void b(null,new d(c,c.id,{roles:e.result.hits}))})},d.prototype.serialize=function(){var a={};return this.id&&(a._id=this.id),a.body=this.content,a.body.roles&&Array.isArray(a.body.roles)?(a.body.roles=a.body.roles.map(function(a){return a instanceof f?a.id:a}),a):a},b.exports=d},{"./kuzzleRole":8,"./kuzzleSecurityDocument":10}],8:[function(a,b,c){function d(a,b,c){return e.call(this,a,b,c),Object.defineProperties(this,{deleteActionName:{value:"deleteRole"}}),a.kuzzle.bluebird?a.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["save"];return d&&-1!==e.indexOf(a)}}):void 0}var e=a("./kuzzleSecurityDocument");d.prototype=Object.create(e.prototype,{constructor:{value:d}}),d.prototype.save=function(a,b){var c=this.serialize(),d=this;a&&void 0===b&&"function"==typeof a&&(b=a,a=null),d.kuzzle.query(this.kuzzleSecurity.buildQueryArgs("createOrReplaceRole"),c,a,function(a){return a?b?b(a):!1:void(b&&b(null,d))})},b.exports=d},{"./kuzzleSecurityDocument":10}],9:[function(a,b,c){function d(a){return Object.defineProperty(this,"kuzzle",{value:a}),Object.defineProperty(this,"buildQueryArgs",{value:function(a){return{controller:"security",action:a}}}),this.kuzzle.bluebird?this.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["roleFactory","profileFactory","userFactory"];return d&&-1===e.indexOf(a)}}):this}var e=a("./kuzzleRole"),f=a("./kuzzleProfile"),g=a("./kuzzleUser"); d.prototype.getRole=function(a,b,c){var d,f=this;if(!a)throw new Error("Id parameter is mandatory for getRole function");c||"function"!=typeof b||(c=b,b=null),d={_id:a},f.kuzzle.callbackRequired("KuzzleSecurity.getRole",c),f.kuzzle.query(this.buildQueryArgs("getRole"),d,b,function(a,b){return a?c(a):void c(null,new e(f,b.result._id,b.result._source))})},d.prototype.searchRoles=function(a,b,c){var d=this;c||"function"!=typeof b||(c=b,b=null),d.kuzzle.callbackRequired("KuzzleSecurity.searchRoles",c),d.kuzzle.query(this.buildQueryArgs("searchRoles"),{body:a},b,function(a,b){var f;return a?c(a):(f=b.result.hits.map(function(a){return new e(d,a._id,a._source)}),void c(null,{total:b.result.total,roles:f}))})},d.prototype.createRole=function(a,b,c,d){var f=this,g={},h="createRole";if(!a||"string"!=typeof a)throw new Error("KuzzleSecurity.createRole: cannot create a role without a role ID");d||"function"!=typeof c||(d=c,c=null),g._id=a,g.body=b,c&&(h=c.replaceIfExist?"createOrReplaceRole":"createRole"),d?f.kuzzle.query(this.buildQueryArgs(h),g,c,function(a,b){var c;return a?d(a):(c=new e(f,b.result._id,b.result._source),void d(null,c))}):f.kuzzle.query(this.buildQueryArgs(h),g)},d.prototype.deleteRole=function(a,b,c){var d={_id:a};c||"function"!=typeof b||(c=b,b=null),c?this.kuzzle.query(this.buildQueryArgs("deleteRole"),d,b,function(a,b){return a?c(a):void c(null,b.result._id)}):this.kuzzle.query(this.buildQueryArgs("deleteRole"),d,b)},d.prototype.roleFactory=function(a,b){return new e(this,a,b)},d.prototype.getProfile=function(a,b,c){var d,e=this,g=!0;if(!a||"string"!=typeof a)throw new Error("Id parameter is mandatory for getProfile function");c||"function"!=typeof b?void 0!==b.hydrate&&(g=b.hydrate):(c=b,b=null),d={_id:a},e.kuzzle.callbackRequired("KuzzleSecurity.getProfile",c),e.kuzzle.query(this.buildQueryArgs("getProfile"),d,b,function(a,b){return a?c(a):(g||(b.result._source.roles=b.result._source.roles.map(function(a){return a._id})),void c(null,new f(e,b.result._id,b.result._source)))})},d.prototype.searchProfiles=function(a,b,c){var d=this;a.hydrate=!0,c||"function"!=typeof b?void 0!==b.hydrate&&(a.hydrate=b.hydrate):(c=b,b=null),d.kuzzle.callbackRequired("KuzzleSecurity.searchProfiles",c),d.kuzzle.query(this.buildQueryArgs("searchProfiles"),{body:a},b,function(a,b){var e;return a?c(a):(e=b.result.hits.map(function(a){return new f(d,a._id,a._source)}),void c(null,{total:b.result.total,profiles:e}))})},d.prototype.createProfile=function(a,b,c,d){var e=this,g={},h="createProfile";if(!a||"string"!=typeof a)throw new Error("KuzzleSecurity.createProfile: cannot create a profile without a profile ID");d||"function"!=typeof c||(d=c,c=null),g._id=a,g.body=b,c&&(h=c.replaceIfExist?"createOrReplaceProfile":"createProfile"),d?e.kuzzle.query(this.buildQueryArgs(h),g,c,function(a,b){var c;return a?d(a):(c=new f(e,b.result._id,b.result._source),void d(null,c))}):e.kuzzle.query(this.buildQueryArgs(h),g)},d.prototype.deleteProfile=function(a,b,c){var d={_id:a};c||"function"!=typeof b||(c=b,b=null),c?this.kuzzle.query(this.buildQueryArgs("deleteProfile"),d,b,function(a,b){return a?c(a):void c(null,b.result._id)}):this.kuzzle.query(this.buildQueryArgs("deleteProfile"),d,b)},d.prototype.profileFactory=function(a,b){return new f(this,a,b)},d.prototype.getUser=function(a,b,c){var d,e=this,f=!0;if(!a||"string"!=typeof a)throw new Error("Id parameter is mandatory for getUser function");c||"function"!=typeof b?void 0!==b.hydrate&&(f=b.hydrate):(c=b,b=null),d={_id:a},e.kuzzle.callbackRequired("KuzzleSecurity.getUser",c),e.kuzzle.query(this.buildQueryArgs("getUser"),d,b,function(a,b){return a?c(a):(f||(b.result._source.profile=b.result._source.profile._id),void c(null,new g(e,b.result._id,b.result._source)))})},d.prototype.searchUsers=function(a,b,c){var d=this;a.hydrate=!0,c||"function"!=typeof b?void 0!==b.hydrate&&(a.hydrate=b.hydrate):(c=b,b=null),d.kuzzle.callbackRequired("KuzzleSecurity.searchUsers",c),d.kuzzle.query(this.buildQueryArgs("searchUsers"),{body:a},b,function(a,b){var e;return a?c(a):(e=b.result.hits.map(function(a){return new g(d,a._id,a._source)}),void c(null,{total:b.result.total,users:e}))})},d.prototype.createUser=function(a,b,c,d){var e=this,f={},h="createUser";if(!a||"string"!=typeof a)throw new Error("KuzzleSecurity.createUser: cannot create a user without a user ID");d||"function"!=typeof c||(d=c,c=null),f._id=a,f.body=b,c&&(h=c.replaceIfExist?"createOrReplaceUser":"createUser"),d?e.kuzzle.query(this.buildQueryArgs(h),f,null,function(a,b){var c;return a?d(a):(c=new g(e,b.result._id,b.result._source),void d(null,c))}):e.kuzzle.query(this.buildQueryArgs(h),f)},d.prototype.deleteUser=function(a,b,c){var d={_id:a};c||"function"!=typeof b||(c=b,b=null),c?this.kuzzle.query(this.buildQueryArgs("deleteUser"),d,b,function(a,b){return a?c(a):void c(null,b.result._id)}):this.kuzzle.query(this.buildQueryArgs("deleteUser"),d,b)},d.prototype.userFactory=function(a,b){return new g(this,a,b)},b.exports=d},{"./kuzzleProfile":7,"./kuzzleRole":8,"./kuzzleUser":11}],10:[function(a,b,c){function d(a,b,c){if(!b)throw new Error("A security document must have an id");return Object.defineProperties(this,{kuzzle:{value:a.kuzzle},kuzzleSecurity:{value:a},id:{value:b,enumerable:!0},content:{value:{},writable:!0,enumerable:!0}}),c&&this.setContent(c,!0),a.kuzzle.bluebird?a.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["delete"];return d&&-1!==e.indexOf(a)}}):void 0}d.prototype.setContent=function(a,b){var c=this;return b?this.content=a:Object.keys(a).forEach(function(b){c.content[b]=a[b]}),this},d.prototype.serialize=function(){var a={};return this.id&&(a._id=this.id),a.body=this.content,a},d.prototype["delete"]=function(a,b){var c=this;a&&void 0===b&&"function"==typeof a&&(b=a,a=null),c.kuzzle.query(this.kuzzleSecurity.buildQueryArgs(this.deleteActionName),{_id:this.id},a,function(a,c){return a?b?b(a):!1:void(b&&b(null,c.result._id))})},b.exports=d},{}],11:[function(a,b,c){function d(a,b,c){return e.call(this,a,b,c),c.profile&&c.profile._id&&c.profile._source&&(c.profile=new f(a,c.profile._id,c.profile._source)),Object.defineProperties(this,{deleteActionName:{value:"deleteUser"}}),a.kuzzle.bluebird?a.kuzzle.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["hydrate","save"];return d&&-1!==e.indexOf(a)}}):void 0}var e=a("./kuzzleSecurityDocument"),f=a("./kuzzleProfile");d.prototype=Object.create(e.prototype,{constructor:{value:d}}),d.prototype.hydrate=function(a,b){var c=this;if(a&&void 0===b&&"function"==typeof a&&(b=a,a=null),c.kuzzle.callbackRequired("KuzzleUser.hydrate",b),!this.content.profile||"string"!=typeof this.content.profile)throw new Error("The User must contains a profile as string in order to be hydrated");c.kuzzle.query(this.kuzzleSecurity.buildQueryArgs("getProfile"),{_id:this.content.profile},a,function(a,e){var g;return a?b(a):(g=new d(c.kuzzleSecurity,c.id,c.content),g.setProfile(new f(c.kuzzleSecurity,e.result._id,e.result._source)),void b(null,g))})},d.prototype.setProfile=function(a){if("string"!=typeof a&&!(a instanceof f))throw new Error('Parameter "profile" must be a KuzzleProfile or a string');return this.content.profile=a,this},d.prototype.save=function(a,b){var c=this.serialize(),d=this;return a&&void 0===b&&"function"==typeof a&&(b=a,a=null),d.kuzzle.query(this.kuzzleSecurity.buildQueryArgs("createOrReplaceUser"),c,a,function(a){return a?b?b(a):!1:void(b&&b(null,d))}),d},d.prototype.serialize=function(){var a={};return this.id&&(a._id=this.id),a.body=this.content,a.body.profile&&a.body.profile.id&&(a.body.profile=a.body.profile.id),a},b.exports=d},{"./kuzzleProfile":7,"./kuzzleSecurityDocument":10}]},{},[2]); //# sourceMappingURL=kuzzle.min.map \ No newline at end of file