kuzzle-sdk
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -21,4 +21,4 @@ { | ||
"dependencies": { | ||
"socket.io-client": "git@github.com:socketio/socket.io-client.git#1.3.7" | ||
"socket.io-client": "git://github.com/socketio/socket.io-client#1.3.7" | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
// Official Javascript SDK for Kuzzle v1.0.8 - 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;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(){function a(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++]=n[a])});16>e;)b[d+e++]=0;return b}function c(a,b){var c=b||0,d=m;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 d(a,b,d){var e=b&&d||0,f=b||[];a=a||{};var g=null!=a.clockseq?a.clockseq:r,h=null!=a.msecs?a.msecs:(new Date).getTime(),i=null!=a.nsecs?a.nsecs:t+1,j=h-s+(i-t)/1e4;if(0>j&&null==a.clockseq&&(g=g+1&16383),(0>j||h>s)&&null==a.nsecs&&(i=0),i>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");s=h,t=i,r=g,h+=122192928e5;var k=(1e4*(268435455&h)+i)%4294967296;f[e++]=k>>>24&255,f[e++]=k>>>16&255,f[e++]=k>>>8&255,f[e++]=255&k;var l=h/4294967296*1e4&268435455;f[e++]=l>>>8&255,f[e++]=255&l,f[e++]=l>>>24&15|16,f[e++]=l>>>16&255,f[e++]=g>>>8|128,f[e++]=255&g;for(var m=a.node||q,n=0;6>n;n++)f[e+n]=m[n];return b?b:c(f)}function e(a,b,d){var e=b&&d||0;"string"==typeof a&&(b="binary"==a?new l(16):null,a=null),a=a||{};var g=a.random||(a.rng||f)();if(g[6]=15&g[6]|64,g[8]=63&g[8]|128,b)for(var h=0;16>h;h++)b[e+h]=g[h];return b||c(g)}var f,g=this;if("function"==typeof g.require)try{var h=g.require("crypto").randomBytes;f=h&&function(){return h(16)}}catch(i){}if(!f&&g.crypto&&crypto.getRandomValues){var j=new Uint8Array(16);f=function(){return crypto.getRandomValues(j),j}}if(!f){var k=new Array(16);f=function(){for(var a,b=0;16>b;b++)0===(3&b)&&(a=4294967296*Math.random()),k[b]=a>>>((3&b)<<3)&255;return k}}for(var l="function"==typeof g.Buffer?g.Buffer:Array,m=[],n={},o=0;256>o;o++)m[o]=(o+256).toString(16).substr(1),n[m[o]]=o;var p=f(),q=[1|p[0],p[1],p[2],p[3],p[4],p[5]],r=16383&(p[6]<<8|p[7]),s=0,t=0,u=e;if(u.v1=d,u.v4=e,u.parse=a,u.unparse=c,u.BufferClass=l,"undefined"!=typeof b&&b.exports)b.exports=u;else if("function"==typeof define&&define.amd)define(function(){return u});else{var v=g.uuid;u.noConflict=function(){return g.uuid=v,u},g.uuid=u}}).call(this)},{}],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.ts<b-a.queueTTL&&(c=e)}),-1!==c&&a.offlineQueue.splice(0,c+1)),a.queueMaxSize>0&&a.offlineQueue.length>a.queueMaxSize&&a.offlineQueue.splice(0,a.offlineQueue.length-a.queueMaxSize)}function e(a,b){var c=Date.now(),d=this;b&&d.socket.once(a.requestId,function(a){b(a.error,a.result)}),d.socket.emit("kuzzle",a),d.requestHistory[a.requestId]=c,Object.keys(d.requestHistory).forEach(function(a){d.requestHistory[a]<c-1e4&&delete d.requestHistory[a]})}function f(){var a=this;a.offlineQueue.length>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}var g=a("node-uuid"),h=a("./kuzzleDataCollection");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 to Kuzzle can't be empty");return Object.defineProperties(this,{collections:{value:{},writable:!0},eventListeners:{value:{connected:[],error:[],disconnected:[],reconnected:[]}},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},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}}),"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("loggedOff"===this.state)throw new Error("This Kuzzle object has been invalidated. Did you try to access it after a logout 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")}}),c&&c.connect&&"auto"!==c.connect?this.state="ready":this.connect(d),this.bluebird?this.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["connect","getAllStatistics","getStatistics","listCollections","now","query"];return d&&-1!==e.indexOf(a)}}):this},Kuzzle.prototype.connect=function(a){var b=this;return-1===["initializing","ready","loggedOff","error","offline"].indexOf(this.state)?(a&&a(null,b),b):(b.state="connecting",b.socket=b.io(b.url,{reconnection:b.autoReconnect,reconnectionDelay:b.reconnectionDelay,"force new connection":!0}),b.socket.once("connect",function(){b.state="connected",Object.keys(b.subscriptions).forEach(function(a){Object.keys(b.subscriptions[a]).forEach(function(c){var d=b.subscriptions[a][c];d.renew(d.callback)})}),f.call(b),b.eventListeners.connected.forEach(function(a){a.fn()}),a&&a(null,b)}),b.socket.on("connect_error",function(c){b.state="error",b.eventListeners.error.forEach(function(a){a.fn()}),a&&a(c)}),b.socket.on("disconnect",function(){b.state="offline",b.autoReconnect||b.logout(),b.autoQueue&&(b.queuing=!0),b.eventListeners.disconnected.forEach(function(a){a.fn()})}),b.socket.on("reconnect",function(){b.state="connected",b.autoResubscribe&&Object.keys(b.subscriptions).forEach(function(a){Object.keys(b.subscriptions[a]).forEach(function(c){var d=b.subscriptions[a][c];d.renew(d.callback)})}),b.autoReplay&&(d.call(b),f.call(b)),b.eventListeners.reconnected.forEach(function(a){a.fn()})}),this)},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=g.v1(),this.eventListeners[a].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(null,"admin","getAllStats",{},a,function(a,c){return a?b(a):void b(null,c.statistics)}),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.statistics):c(null,[d.statistics]))},this.callbackRequired("Kuzzle.getStatistics",c),a?this.query(null,"admin","getStats",{body:{startTime:a}},b,d):this.query(null,"admin","getLastStats",{},b,d),this},Kuzzle.prototype.dataCollectionFactory=function(a,b){return this.isValid(),this.collections[a]||(this.collections[a]=new h(this,a,b)),this.collections[a]},Kuzzle.prototype.flushQueue=function(){return this.offlineQueue=[],this},Kuzzle.prototype.listCollections=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.listCollections",b),this.query(null,"read","listCollections",{},a,function(a,c){return a?b(a):b(null,c.collections)}),this},Kuzzle.prototype.logout=function(){var a;this.state="loggedOff",this.socket.close(),this.socket=null;for(a in this.collections)this.collections.hasOwnProperty(a)&&delete this.collections[a]},Kuzzle.prototype.now=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.now",b),this.query(null,"read","now",{},a,function(a,c){return a?b(a):void b(null,c.now)}),this},Kuzzle.prototype.query=function(a,b,c,f,h,i){var j,k={action:c,controller:b,metadata:this.metadata},l=this;if(this.isValid(),i||"function"!=typeof h||(i=h,h=null),h&&(h.metadata&&Object.keys(h.metadata).forEach(function(a){k.metadata[a]=h.metadata[a]}),h.queuable===!1&&"offline"===l.state))return l;f.metadata&&Object.keys(f.metadata).forEach(function(a){k.metadata[a]=f.metadata[a]});for(j in f)"metadata"!==j&&f.hasOwnProperty(j)&&(k[j]=f[j]);return k=l.addHeaders(k,this.headers),a&&(k.collection=a),k.requestId||(k.requestId=g.v4()),"connected"===l.state||h&&h.queuable===!1?e.call(this,k,i):(l.queuing||-1!==["initializing","connecting"].indexOf(l.state))&&(d.call(this,k,i),l.queueFilter?l.queueFilter(k)&&l.offlineQueue.push({ts:Date.now(),query:k,cb:i}):l.offlineQueue.push({ts:Date.now(),query:k,cb:i})),l},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]=[]}else b.forEach(function(a){c.eventListeners[a]=[]})},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].forEach(function(c,e){c.id===b&&d.eventListeners[a].splice(e,1)})},Kuzzle.prototype.replayQueue=function(){return"offline"===this.state||this.autoReplay||(d.call(this),f.call(this)),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,"node-uuid":1,"socket.io-client":void 0}],3:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{collection:{value:b,enumerable:!0},kuzzle:{value:a,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0}}),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,e=this;return c||"function"!=typeof b||(c=b,b=null),e.kuzzle.callbackRequired("KuzzleDataCollection.advancedSearch",c),d=e.kuzzle.addHeaders({body:a},this.headers),e.kuzzle.query(this.collection,"read","search",d,b,function(a,b){var d=[];return a?c(a):(b.hits.hits.forEach(function(a){d.push(e.documentFactory(a._id,a))}),void c(null,{total:b.hits.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.collection,"read","count",d,b,function(a,b){return a?c(a):void c(null,b.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.collection,"write","createCollection",c,a,b),this},d.prototype.createDocument=function(a,b,c,d){var f=this,g={},h="create";return"string"!=typeof a&&(d=c,c=b,b=a,a=null),d||"function"!=typeof c||(d=c,c=null),b instanceof e?g=b.toJSON():g.body=b,c&&(h=c.updateIfExist?"createOrUpdate":"create"),a&&(g._id=a),g.persist=!0,g=f.kuzzle.addHeaders(g,f.headers),d?f.kuzzle.query(this.collection,"write",h,g,c,function(a,b){return a?d(a):void d(null,f.documentFactory(b._id,b))}):this.kuzzle.query(this.collection,"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.collection,"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.collection,"write",d,e,b,function(a,b){return a?c(a):void("delete"===d?c(null,[e._id]):c(null,b.ids))}):this.kuzzle.query(this.collection,"write",d,e,b),this},d.prototype.fetchDocument=function(a,b,c){var d={_id:a},e=this;return c||"function"!=typeof b||(c=b,b=null),e.kuzzle.callbackRequired("KuzzleDataCollection.fetch",c),d=e.kuzzle.addHeaders(d,this.headers),e.kuzzle.query(this.collection,"read","get",d,b,function(a,b){return a?c(a):void c(null,e.documentFactory(b._id,b))}),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.toJSON():c.body=a,c.persist=!1,c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.collection,"write","publish",c,b),this},d.prototype.putMapping=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),d=new f(this,a),d.apply(b,c),this},d.prototype.replaceDocument=function(a,b,c,d){var e=this,f={_id:a,body:b};return d||"function"!=typeof c||(d=c,c=null),f=e.kuzzle.addHeaders(f,this.headers),d?e.kuzzle.query(this.collection,"write","createOrUpdate",f,c,function(a,b){return a?d(a):void d(null,e.documentFactory(b._id,b))}):e.kuzzle.query(this.collection,"write","createOrUpdate",f,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.collection,"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.collection,"write","update",f,c,function(a,b){var c;return a?d(a):(c=new e(g,b._id),void d(null,c))}):g.kuzzle.query(this.collection,"write","update",f,c),g},d.prototype.documentFactory=function(a,b){var c=b._source?new e(this,a,b._source):new e(this,a,b);return c},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.collection,eunmerable:!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,"admin","putMapping",d,a,function(a,d){return a?b?b(a):!1:(c.mapping=d._source.properties,void(b&&b(null,c)))}),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,"admin","getMapping",d,a,function(a,d){return a?b?b(a):!1:(c.mapping=d.mainindex.mappings[c.collection].properties,void(b&&b(null,c)))}),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,{queue:{value:[],writable:!0},refreshing:{value:!1,writable:!0},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}),c||this.refresh()),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}function e(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}d.prototype.toJSON=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.toJSON())},d.prototype["delete"]=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"delete",args:[a,b]}),this;if(!this.id)throw new Error("KuzzleDocument.delete: cannot delete a document without a document ID");return b?this.kuzzle.query(this.collection,"write","delete",this.toJSON(),a,function(a){return a?b(a):void b(null,c)}):this.kuzzle.query(this.collection,"write","delete",this.toJSON(),a),this},d.prototype.refresh=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"refresh",args:[a,b]}),this;if(!c.id)throw new Error("KuzzleDocument.refresh: cannot retrieve a document if no ID has been provided");return c.refreshing=!0,c.kuzzle.query(c.collection,"read","get",{_id:c.id},a,function(a,d){return a?(c.refreshing=!1,c.queue=[],b?b(a):!1):(c.version=d._version,c.content=d._source,b&&b(null,c),c.refreshing=!1,void e.call(c))}),this},d.prototype.save=function(a,b){var c=this.toJSON(),d=this;return a&&void 0===b&&"function"==typeof a&&(b=a,a=null),d.refreshing?(d.queue.push({action:"save",args:[a,b]}),d):(c.persist=!0,d.kuzzle.query(this.collection,"write","createOrUpdate",c,a,function(a,c){return a?b?b(a):!1:(d.id=c._id,d.version=c._version,void(b&&b(null,d)))}),d)},d.prototype.publish=function(a){var b=this.toJSON();return this.refreshing?(this.queue.push({action:"publish",args:[a]}),this):(b.persist=!1,this.kuzzle.query(this.collection,"write","create",b,a),this)},d.prototype.setContent=function(a,b){var c=this;return this.refreshing?(this.queue.push({action:"setContent",args:[a,b]}),this):(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()},notifier:{value:null,writable:!0},queue:{value:[],writable:!0},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.collection,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):void(this.kuzzle.requestHistory[a.result.requestId]?(this.subscribeToSelf&&this.callback(null,a.result),delete this.kuzzle.requestHistory[a.result.requestId]):this.callback(null,a.result))}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,"subscribe","count",b,function(b,c){return b?a(b):void a(null,c.count)}),this)},d.prototype.renew=function(a,b){var c={scope:this.scope,state:this.state,users:this.users},d=this;return!b&&a&&"function"==typeof a&&(b=a,a=null),this.subscribing?(this.queue.push({action:"renew",args:[a,b]}),this):(this.kuzzle.callbackRequired("KuzzleRoom.renew",b),this.unsubscribe(),this.roomId=null,this.subscribing=!0,this.callback=b,this.kuzzle.subscriptions.pending[d.id]=d,a&&(this.filters=a),c.body=this.filters,c=this.kuzzle.addHeaders(c,this.headers),d.kuzzle.query(this.collection,"subscribe","on",c,{metadata:this.metadata},function(a,b){if(delete d.kuzzle.subscriptions.pending[d.id],d.subscribing=!1,a)throw d.queue=[],new Error("Error during Kuzzle subscription: "+a.message);d.roomId=b.roomId,d.channel=b.channel,d.kuzzle.subscriptions[d.roomId]||(d.kuzzle.subscriptions[d.roomId]={}),d.kuzzle.subscriptions[d.roomId][d.id]=d,d.notifier=e.bind(d),d.kuzzle.socket.on(d.channel,d.notifier),f.call(d)}),this)},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(this.collection,"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,"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}]},{},[2]); | ||
// Official Javascript SDK for Kuzzle v1.0.9 - 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;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(){function a(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++]=n[a])});16>e;)b[d+e++]=0;return b}function c(a,b){var c=b||0,d=m;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 d(a,b,d){var e=b&&d||0,f=b||[];a=a||{};var g=null!=a.clockseq?a.clockseq:r,h=null!=a.msecs?a.msecs:(new Date).getTime(),i=null!=a.nsecs?a.nsecs:t+1,j=h-s+(i-t)/1e4;if(0>j&&null==a.clockseq&&(g=g+1&16383),(0>j||h>s)&&null==a.nsecs&&(i=0),i>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");s=h,t=i,r=g,h+=122192928e5;var k=(1e4*(268435455&h)+i)%4294967296;f[e++]=k>>>24&255,f[e++]=k>>>16&255,f[e++]=k>>>8&255,f[e++]=255&k;var l=h/4294967296*1e4&268435455;f[e++]=l>>>8&255,f[e++]=255&l,f[e++]=l>>>24&15|16,f[e++]=l>>>16&255,f[e++]=g>>>8|128,f[e++]=255&g;for(var m=a.node||q,n=0;6>n;n++)f[e+n]=m[n];return b?b:c(f)}function e(a,b,d){var e=b&&d||0;"string"==typeof a&&(b="binary"==a?new l(16):null,a=null),a=a||{};var g=a.random||(a.rng||f)();if(g[6]=15&g[6]|64,g[8]=63&g[8]|128,b)for(var h=0;16>h;h++)b[e+h]=g[h];return b||c(g)}var f,g=this;if("function"==typeof g.require)try{var h=g.require("crypto").randomBytes;f=h&&function(){return h(16)}}catch(i){}if(!f&&g.crypto&&crypto.getRandomValues){var j=new Uint8Array(16);f=function(){return crypto.getRandomValues(j),j}}if(!f){var k=new Array(16);f=function(){for(var a,b=0;16>b;b++)0===(3&b)&&(a=4294967296*Math.random()),k[b]=a>>>((3&b)<<3)&255;return k}}for(var l="function"==typeof g.Buffer?g.Buffer:Array,m=[],n={},o=0;256>o;o++)m[o]=(o+256).toString(16).substr(1),n[m[o]]=o;var p=f(),q=[1|p[0],p[1],p[2],p[3],p[4],p[5]],r=16383&(p[6]<<8|p[7]),s=0,t=0,u=e;if(u.v1=d,u.v4=e,u.parse=a,u.unparse=c,u.BufferClass=l,"undefined"!=typeof b&&b.exports)b.exports=u;else if("function"==typeof define&&define.amd)define(function(){return u});else{var v=g.uuid;u.noConflict=function(){return g.uuid=v,u},g.uuid=u}}).call(this)},{}],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.ts<b-a.queueTTL&&(c=e)}),-1!==c&&a.offlineQueue.splice(0,c+1)),a.queueMaxSize>0&&a.offlineQueue.length>a.queueMaxSize&&a.offlineQueue.splice(0,a.offlineQueue.length-a.queueMaxSize)}function e(a,b){var c=Date.now(),d=this;b&&d.socket.once(a.requestId,function(a){b(a.error,a.result)}),d.socket.emit("kuzzle",a),d.requestHistory[a.requestId]=c,Object.keys(d.requestHistory).forEach(function(a){d.requestHistory[a]<c-1e4&&delete d.requestHistory[a]})}function f(){var a=this;a.offlineQueue.length>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}var g=a("node-uuid"),h=a("./kuzzleDataCollection");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 to Kuzzle can't be empty");return Object.defineProperties(this,{collections:{value:{},writable:!0},eventListeners:{value:{connected:[],error:[],disconnected:[],reconnected:[]}},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},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}}),"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("loggedOff"===this.state)throw new Error("This Kuzzle object has been invalidated. Did you try to access it after a logout 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")}}),c&&c.connect&&"auto"!==c.connect?this.state="ready":this.connect(d),this.bluebird?this.bluebird.promisifyAll(this,{suffix:"Promise",filter:function(a,b,c,d){var e=["connect","getAllStatistics","getStatistics","listCollections","now","query"];return d&&-1!==e.indexOf(a)}}):this},Kuzzle.prototype.connect=function(a){var b=this;return-1===["initializing","ready","loggedOff","error","offline"].indexOf(this.state)?(a&&a(null,b),b):(b.state="connecting",b.socket=b.io(b.url,{reconnection:b.autoReconnect,reconnectionDelay:b.reconnectionDelay,"force new connection":!0}),b.socket.once("connect",function(){b.state="connected",Object.keys(b.subscriptions).forEach(function(a){Object.keys(b.subscriptions[a]).forEach(function(c){var d=b.subscriptions[a][c];d.renew(d.callback)})}),f.call(b),b.eventListeners.connected.forEach(function(a){a.fn()}),a&&a(null,b)}),b.socket.on("connect_error",function(c){b.state="error",b.eventListeners.error.forEach(function(a){a.fn()}),a&&a(c)}),b.socket.on("disconnect",function(){b.state="offline",b.autoReconnect||b.logout(),b.autoQueue&&(b.queuing=!0),b.eventListeners.disconnected.forEach(function(a){a.fn()})}),b.socket.on("reconnect",function(){b.state="connected",b.autoResubscribe&&Object.keys(b.subscriptions).forEach(function(a){Object.keys(b.subscriptions[a]).forEach(function(c){var d=b.subscriptions[a][c];d.renew(d.callback)})}),b.autoReplay&&(d.call(b),f.call(b)),b.eventListeners.reconnected.forEach(function(a){a.fn()})}),this)},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=g.v1(),this.eventListeners[a].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(null,"admin","getAllStats",{},a,function(a,c){return a?b(a):void b(null,c.statistics)}),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.statistics):c(null,[d.statistics]))},this.callbackRequired("Kuzzle.getStatistics",c),a?this.query(null,"admin","getStats",{body:{startTime:a}},b,d):this.query(null,"admin","getLastStats",{},b,d),this},Kuzzle.prototype.dataCollectionFactory=function(a,b){return this.isValid(),this.collections[a]||(this.collections[a]=new h(this,a,b)),this.collections[a]},Kuzzle.prototype.flushQueue=function(){return this.offlineQueue=[],this},Kuzzle.prototype.listCollections=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.listCollections",b),this.query(null,"read","listCollections",{},a,function(a,c){return a?b(a):b(null,c.collections)}),this},Kuzzle.prototype.logout=function(){var a;this.state="loggedOff",this.socket.close(),this.socket=null;for(a in this.collections)this.collections.hasOwnProperty(a)&&delete this.collections[a]},Kuzzle.prototype.now=function(a,b){return b||"function"!=typeof a||(b=a,a=null),this.callbackRequired("Kuzzle.now",b),this.query(null,"read","now",{},a,function(a,c){return a?b(a):void b(null,c.now)}),this},Kuzzle.prototype.query=function(a,b,c,f,h,i){var j,k={action:c,controller:b,metadata:this.metadata},l=this;if(this.isValid(),i||"function"!=typeof h||(i=h,h=null),h&&(h.metadata&&Object.keys(h.metadata).forEach(function(a){k.metadata[a]=h.metadata[a]}),h.queuable===!1&&"offline"===l.state))return l;f.metadata&&Object.keys(f.metadata).forEach(function(a){k.metadata[a]=f.metadata[a]});for(j in f)"metadata"!==j&&f.hasOwnProperty(j)&&(k[j]=f[j]);return k=l.addHeaders(k,this.headers),a&&(k.collection=a),k.requestId||(k.requestId=g.v4()),"connected"===l.state||h&&h.queuable===!1?e.call(this,k,i):(l.queuing||-1!==["initializing","connecting"].indexOf(l.state))&&(d.call(this,k,i),l.queueFilter?l.queueFilter(k)&&l.offlineQueue.push({ts:Date.now(),query:k,cb:i}):l.offlineQueue.push({ts:Date.now(),query:k,cb:i})),l},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]=[]}else b.forEach(function(a){c.eventListeners[a]=[]})},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].forEach(function(c,e){c.id===b&&d.eventListeners[a].splice(e,1)})},Kuzzle.prototype.replayQueue=function(){return"offline"===this.state||this.autoReplay||(d.call(this),f.call(this)),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,"node-uuid":1,"socket.io-client":void 0}],3:[function(a,b,c){function d(a,b){return Object.defineProperties(this,{collection:{value:b,enumerable:!0},kuzzle:{value:a,enumerable:!0},headers:{value:JSON.parse(JSON.stringify(a.headers)),enumerable:!0,writable:!0}}),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,e=this;return c||"function"!=typeof b||(c=b,b=null),e.kuzzle.callbackRequired("KuzzleDataCollection.advancedSearch",c),d=e.kuzzle.addHeaders({body:a},this.headers),e.kuzzle.query(this.collection,"read","search",d,b,function(a,b){var d=[];return a?c(a):(b.hits.hits.forEach(function(a){d.push(e.documentFactory(a._id,a))}),void c(null,{total:b.hits.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.collection,"read","count",d,b,function(a,b){return a?c(a):void c(null,b.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.collection,"write","createCollection",c,a,b),this},d.prototype.createDocument=function(a,b,c,d){var f=this,g={},h="create";return"string"!=typeof a&&(d=c,c=b,b=a,a=null),d||"function"!=typeof c||(d=c,c=null),b instanceof e?g=b.toJSON():g.body=b,c&&(h=c.updateIfExist?"createOrUpdate":"create"),a&&(g._id=a),g.persist=!0,g=f.kuzzle.addHeaders(g,f.headers),d?f.kuzzle.query(this.collection,"write",h,g,c,function(a,b){return a?d(a):void d(null,f.documentFactory(b._id,b))}):this.kuzzle.query(this.collection,"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.collection,"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.collection,"write",d,e,b,function(a,b){return a?c(a):void("delete"===d?c(null,[e._id]):c(null,b.ids))}):this.kuzzle.query(this.collection,"write",d,e,b),this},d.prototype.fetchDocument=function(a,b,c){var d={_id:a},e=this;return c||"function"!=typeof b||(c=b,b=null),e.kuzzle.callbackRequired("KuzzleDataCollection.fetch",c),d=e.kuzzle.addHeaders(d,this.headers),e.kuzzle.query(this.collection,"read","get",d,b,function(a,b){return a?c(a):void c(null,e.documentFactory(b._id,b))}),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.toJSON():c.body=a,c.persist=!1,c=this.kuzzle.addHeaders(c,this.headers),this.kuzzle.query(this.collection,"write","publish",c,b),this},d.prototype.putMapping=function(a,b,c){var d;return c||"function"!=typeof b||(c=b,b=null),d=new f(this,a),d.apply(b,c),this},d.prototype.replaceDocument=function(a,b,c,d){var e=this,f={_id:a,body:b};return d||"function"!=typeof c||(d=c,c=null),f=e.kuzzle.addHeaders(f,this.headers),d?e.kuzzle.query(this.collection,"write","createOrUpdate",f,c,function(a,b){return a?d(a):void d(null,e.documentFactory(b._id,b))}):e.kuzzle.query(this.collection,"write","createOrUpdate",f,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.collection,"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.collection,"write","update",f,c,function(a,b){var c;return a?d(a):(c=new e(g,b._id),void d(null,c))}):g.kuzzle.query(this.collection,"write","update",f,c),g},d.prototype.documentFactory=function(a,b){var c=b._source?new e(this,a,b._source):new e(this,a,b);return c},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.collection,eunmerable:!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,"admin","putMapping",d,a,function(a,d){return a?b?b(a):!1:(c.mapping=d._source.properties,void(b&&b(null,c)))}),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,"admin","getMapping",d,a,function(a,d){return a?b?b(a):!1:(c.mapping=d.mainindex.mappings[c.collection].properties,void(b&&b(null,c)))}),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,{queue:{value:[],writable:!0},refreshing:{value:!1,writable:!0},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}),c||this.refresh()),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}function e(){for(var a;this.queue.length>0;)a=this.queue.shift(),this[a.action].apply(this,a.args)}d.prototype.toJSON=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.toJSON())},d.prototype["delete"]=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"delete",args:[a,b]}),this;if(!this.id)throw new Error("KuzzleDocument.delete: cannot delete a document without a document ID");return b?this.kuzzle.query(this.collection,"write","delete",this.toJSON(),a,function(a){return a?b(a):void b(null,c)}):this.kuzzle.query(this.collection,"write","delete",this.toJSON(),a),this},d.prototype.refresh=function(a,b){var c=this;if(b||"function"!=typeof a||(b=a,a=null),this.refreshing)return this.queue.push({action:"refresh",args:[a,b]}),this;if(!c.id)throw new Error("KuzzleDocument.refresh: cannot retrieve a document if no ID has been provided");return c.refreshing=!0,c.kuzzle.query(c.collection,"read","get",{_id:c.id},a,function(a,d){return a?(c.refreshing=!1,c.queue=[],b?b(a):!1):(c.version=d._version,c.content=d._source,b&&b(null,c),c.refreshing=!1,void e.call(c))}),this},d.prototype.save=function(a,b){var c=this.toJSON(),d=this;return a&&void 0===b&&"function"==typeof a&&(b=a,a=null),d.refreshing?(d.queue.push({action:"save",args:[a,b]}),d):(c.persist=!0,d.kuzzle.query(this.collection,"write","createOrUpdate",c,a,function(a,c){return a?b?b(a):!1:(d.id=c._id,d.version=c._version,void(b&&b(null,d)))}),d)},d.prototype.publish=function(a){var b=this.toJSON();return this.refreshing?(this.queue.push({action:"publish",args:[a]}),this):(b.persist=!1,this.kuzzle.query(this.collection,"write","publish",b,a),this)},d.prototype.setContent=function(a,b){var c=this;return this.refreshing?(this.queue.push({action:"setContent",args:[a,b]}),this):(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()},notifier:{value:null,writable:!0},queue:{value:[],writable:!0},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.collection,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):void(this.kuzzle.requestHistory[a.result.requestId]?(this.subscribeToSelf&&this.callback(null,a.result),delete this.kuzzle.requestHistory[a.result.requestId]):this.callback(null,a.result))}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,"subscribe","count",b,function(b,c){return b?a(b):void a(null,c.count)}),this)},d.prototype.renew=function(a,b){var c={scope:this.scope,state:this.state,users:this.users},d=this;return!b&&a&&"function"==typeof a&&(b=a,a=null),this.subscribing?(this.queue.push({action:"renew",args:[a,b]}),this):(this.kuzzle.callbackRequired("KuzzleRoom.renew",b),this.unsubscribe(),this.roomId=null,this.subscribing=!0,this.callback=b,this.kuzzle.subscriptions.pending[d.id]=d,a&&(this.filters=a),c.body=this.filters,c=this.kuzzle.addHeaders(c,this.headers),d.kuzzle.query(this.collection,"subscribe","on",c,{metadata:this.metadata},function(a,b){if(delete d.kuzzle.subscriptions.pending[d.id],d.subscribing=!1,a)throw d.queue=[],new Error("Error during Kuzzle subscription: "+a.message);d.roomId=b.roomId,d.channel=b.channel,d.kuzzle.subscriptions[d.roomId]||(d.kuzzle.subscriptions[d.roomId]={}),d.kuzzle.subscriptions[d.roomId][d.id]=d,d.notifier=e.bind(d),d.kuzzle.socket.on(d.channel,d.notifier),f.call(d)}),this)},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(this.collection,"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,"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}]},{},[2]); | ||
//# sourceMappingURL=kuzzle.min.map |
{ | ||
"name": "kuzzle-sdk", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Official Javascript SDK for Kuzzle", | ||
@@ -5,0 +5,0 @@ "author": "The Kuzzle Team <support@kuzzle.io>", |
@@ -298,3 +298,3 @@ /** | ||
this.kuzzle.query(this.collection, 'write', 'create', data, options); | ||
this.kuzzle.query(this.collection, 'write', 'publish', data, options); | ||
@@ -301,0 +301,0 @@ return this; |
@@ -354,3 +354,3 @@ var | ||
this.timeout(50); | ||
this.timeout(500); | ||
@@ -357,0 +357,0 @@ kuzzle = new KuzzleRewired('nowhere', {connect: 'manual', autoReplay: false, autoQueue: false}); |
@@ -407,3 +407,3 @@ var | ||
collection: 'foo', | ||
action: 'create', | ||
action: 'publish', | ||
controller: 'write', | ||
@@ -410,0 +410,0 @@ body: {} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
316601