22// shim for using process in browser
33
44var process = module . exports = { } ;
5-
6- // cached from whatever global is present so that test runners that stub it
7- // don't break things. But we need to wrap it in a try catch in case it is
8- // wrapped in strict mode code which doesn't define any globals. It's inside a
9- // function because try/catches deoptimize in certain engines.
10-
11- var cachedSetTimeout ;
12- var cachedClearTimeout ;
13-
14- ( function ( ) {
15- try {
16- cachedSetTimeout = setTimeout ;
17- } catch ( e ) {
18- cachedSetTimeout = function ( ) {
19- throw new Error ( 'setTimeout is not defined' ) ;
20- }
21- }
22- try {
23- cachedClearTimeout = clearTimeout ;
24- } catch ( e ) {
25- cachedClearTimeout = function ( ) {
26- throw new Error ( 'clearTimeout is not defined' ) ;
27- }
28- }
29- } ( ) )
305var queue = [ ] ;
316var draining = false ;
327var currentQueue ;
338var queueIndex = - 1 ;
349
3510function cleanUpNextTick ( ) {
36- if ( ! draining || ! currentQueue ) {
37- return ;
38- }
3911 draining = false ;
4012 if ( currentQueue . length ) {
4113 queue = currentQueue . concat ( queue ) ;
@@ -51,7 +23,7 @@ function drainQueue() {
5123 if ( draining ) {
5224 return ;
5325 }
54- var timeout = cachedSetTimeout ( cleanUpNextTick ) ;
26+ var timeout = setTimeout ( cleanUpNextTick ) ;
5527 draining = true ;
5628
5729 var len = queue . length ;
@@ -68,7 +40,7 @@ function drainQueue() {
6840 }
6941 currentQueue = null ;
7042 draining = false ;
71- cachedClearTimeout ( timeout ) ;
43+ clearTimeout ( timeout ) ;
7244}
7345
7446process . nextTick = function ( fun ) {
@@ -80,7 +52,7 @@ process.nextTick = function (fun) {
8052 }
8153 queue . push ( new Item ( fun , args ) ) ;
8254 if ( queue . length === 1 && ! draining ) {
83- cachedSetTimeout ( drainQueue , 0 ) ;
55+ setTimeout ( drainQueue , 0 ) ;
8456 }
8557} ;
8658
@@ -2245,9 +2217,10 @@ KuzzleDataCollection.prototype.getMapping = function (options, cb) {
22452217 *
22462218 * @param {object } document - either a KuzzleDocument instance or a JSON object
22472219 * @param {object } [options] - optional arguments
2220+ * @param {responseCallback } [cb] - Returns a raw Kuzzle response
22482221 * @returns {* } this
22492222 */
2250- KuzzleDataCollection . prototype . publishMessage = function ( document , options ) {
2223+ KuzzleDataCollection . prototype . publishMessage = function ( document , options , cb ) {
22512224 var data = { } ;
22522225
22532226 if ( document instanceof KuzzleDocument ) {
@@ -2257,7 +2230,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options) {
22572230 }
22582231
22592232 data = this . kuzzle . addHeaders ( data , this . headers ) ;
2260- this . kuzzle . query ( this . buildQueryArgs ( 'write' , 'publish' ) , data , options ) ;
2233+ this . kuzzle . query ( this . buildQueryArgs ( 'write' , 'publish' ) , data , options , cb ) ;
22612234
22622235 return this ;
22632236} ;
@@ -2566,6 +2539,11 @@ KuzzleDataMapping.prototype.refresh = function (options, cb) {
25662539 if ( res . result [ self . collection . index ] ) {
25672540 if ( res . result [ self . collection . index ] . mappings [ self . collection . collection ] ) {
25682541 self . mapping = res . result [ self . collection . index ] . mappings [ self . collection . collection ] . properties ;
2542+
2543+ // Mappings can be empty. The mapping property should never be "undefined"
2544+ if ( self . mapping === undefined ) {
2545+ self . mapping = { } ;
2546+ }
25692547 } else {
25702548 return cb ? cb ( new Error ( 'No mapping found for collection ' + self . collection . collection ) ) : false ;
25712549 }
0 commit comments