2
2
// shim for using process in browser
3
3
4
4
var 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
- } ( ) )
30
5
var queue = [ ] ;
31
6
var draining = false ;
32
7
var currentQueue ;
33
8
var queueIndex = - 1 ;
34
9
35
10
function cleanUpNextTick ( ) {
36
- if ( ! draining || ! currentQueue ) {
37
- return ;
38
- }
39
11
draining = false ;
40
12
if ( currentQueue . length ) {
41
13
queue = currentQueue . concat ( queue ) ;
@@ -51,7 +23,7 @@ function drainQueue() {
51
23
if ( draining ) {
52
24
return ;
53
25
}
54
- var timeout = cachedSetTimeout ( cleanUpNextTick ) ;
26
+ var timeout = setTimeout ( cleanUpNextTick ) ;
55
27
draining = true ;
56
28
57
29
var len = queue . length ;
@@ -68,7 +40,7 @@ function drainQueue() {
68
40
}
69
41
currentQueue = null ;
70
42
draining = false ;
71
- cachedClearTimeout ( timeout ) ;
43
+ clearTimeout ( timeout ) ;
72
44
}
73
45
74
46
process . nextTick = function ( fun ) {
@@ -80,7 +52,7 @@ process.nextTick = function (fun) {
80
52
}
81
53
queue . push ( new Item ( fun , args ) ) ;
82
54
if ( queue . length === 1 && ! draining ) {
83
- cachedSetTimeout ( drainQueue , 0 ) ;
55
+ setTimeout ( drainQueue , 0 ) ;
84
56
}
85
57
} ;
86
58
@@ -2245,9 +2217,10 @@ KuzzleDataCollection.prototype.getMapping = function (options, cb) {
2245
2217
*
2246
2218
* @param {object } document - either a KuzzleDocument instance or a JSON object
2247
2219
* @param {object } [options] - optional arguments
2220
+ * @param {responseCallback } [cb] - Returns a raw Kuzzle response
2248
2221
* @returns {* } this
2249
2222
*/
2250
- KuzzleDataCollection . prototype . publishMessage = function ( document , options ) {
2223
+ KuzzleDataCollection . prototype . publishMessage = function ( document , options , cb ) {
2251
2224
var data = { } ;
2252
2225
2253
2226
if ( document instanceof KuzzleDocument ) {
@@ -2257,7 +2230,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options) {
2257
2230
}
2258
2231
2259
2232
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 ) ;
2261
2234
2262
2235
return this ;
2263
2236
} ;
@@ -2566,6 +2539,11 @@ KuzzleDataMapping.prototype.refresh = function (options, cb) {
2566
2539
if ( res . result [ self . collection . index ] ) {
2567
2540
if ( res . result [ self . collection . index ] . mappings [ self . collection . collection ] ) {
2568
2541
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
+ }
2569
2547
} else {
2570
2548
return cb ? cb ( new Error ( 'No mapping found for collection ' + self . collection . collection ) ) : false ;
2571
2549
}
0 commit comments