Skip to content

Commit 5039bee

Browse files
committed
chore: release v5.2.0
1 parent 9b4df13 commit 5039bee

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

lib/document.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113

114114
static get(ids, fetchReference = true) {
115115
return new Promise((resolve, reject) => {
116-
var x;
116+
var previousError, x;
117117
/*
118118
Fetch the document with id or ids.
119119
If the document is not exist, it will return null.
@@ -144,6 +144,7 @@
144144
}
145145
// fetch documents
146146
if (ids.constructor === Array) {
147+
previousError = new Error('From previous stack');
147148
this._es.mget({
148149
index: this.getIndexName(),
149150
type: this.getDocumentType(),
@@ -153,6 +154,7 @@
153154
}, (error, response) => {
154155
var dbField, doc, i, item, len, property, propertyName, ref, ref1, ref2, result;
155156
if (error) {
157+
error.stack += previousError.stack;
156158
return reject(error);
157159
}
158160
result = [];
@@ -190,13 +192,15 @@
190192
return;
191193
}
192194
// fetch the document
195+
previousError = new Error('From previous stack');
193196
return this._es.get({
194197
index: this.getIndexName(),
195198
type: this.getDocumentType(),
196199
id: ids
197200
}, (error, response) => {
198201
var args, dbField, document, property, propertyName, ref, ref1;
199202
if (error) {
203+
error.stack += previousError.stack;
200204
if (error.status === 404) {
201205
return resolve(null);
202206
}
@@ -236,12 +240,15 @@
236240
@param id {string} The documents' id.
237241
@returns {promise<bool>}
238242
*/
243+
var previousError;
244+
previousError = new Error('From previous stack');
239245
return this._es.exists({
240246
index: this.getIndexName(),
241247
type: this.getDocumentType(),
242248
id: id
243249
}, function(error, response) {
244250
if (error) {
251+
error.stack += previousError.stack;
245252
return reject(error);
246253
}
247254
return resolve(response);
@@ -269,15 +276,18 @@
269276

270277
static refresh(args = {}) {
271278
return new Promise((resolve, reject) => {
279+
var previousError;
272280
/*
273281
Explicitly refresh one or more index, making all operations performed since the last refresh available for search.
274282
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-5-6.html#api-indices-refresh-5-6
275283
@params args {object}
276284
@returns {promise}
277285
*/
278286
args.index = this.getIndexName();
287+
previousError = new Error('From previous stack');
279288
return this._es.indices.refresh(args, function(error) {
280289
if (error) {
290+
error.stack += previousError.stack;
281291
return reject(error);
282292
}
283293
return resolve();
@@ -295,10 +305,13 @@
295305
var closeIndex, createIndex, openIndex, putMapping, putSettings;
296306
createIndex = () => {
297307
return new Promise((resolve, reject) => {
308+
var previousError;
309+
previousError = new Error('From previous stack');
298310
return this._es.indices.create({
299311
index: this.getIndexName()
300312
}, function(error, response) {
301313
if (error && error.status !== 400) {
314+
error.stack += previousError.stack;
302315
return reject(error);
303316
}
304317
return setTimeout(function() {
@@ -309,10 +322,13 @@
309322
};
310323
closeIndex = () => {
311324
return new Promise((resolve, reject) => {
325+
var previousError;
326+
previousError = new Error('From previous stack');
312327
return this._es.indices.close({
313328
index: this.getIndexName()
314329
}, function(error, response) {
315330
if (error) {
331+
error.stack += previousError.stack;
316332
return reject(error);
317333
}
318334
return resolve(response);
@@ -321,9 +337,11 @@
321337
};
322338
putSettings = () => {
323339
return new Promise((resolve, reject) => {
340+
var previousError;
324341
if (!this._settings) {
325342
return resolve();
326343
}
344+
previousError = new Error('From previous stack');
327345
return this._es.indices.putSettings({
328346
index: this.getIndexName(),
329347
body: {
@@ -333,6 +351,7 @@
333351
}
334352
}, function(error, response) {
335353
if (error) {
354+
error.stack += previousError.stack;
336355
return reject(error);
337356
}
338357
return resolve(response);
@@ -341,7 +360,7 @@
341360
};
342361
putMapping = () => {
343362
return new Promise((resolve, reject) => {
344-
var field, mapping, property, propertyName, ref, ref1, ref2, ref3;
363+
var field, mapping, previousError, property, propertyName, ref, ref1, ref2, ref3;
345364
mapping = {};
346365
ref = this._properties;
347366
for (propertyName in ref) {
@@ -428,6 +447,7 @@
428447
mapping[(ref3 = property.dbField) != null ? ref3 : propertyName] = field;
429448
}
430449
}
450+
previousError = new Error('From previous stack');
431451
return this._es.indices.putMapping({
432452
index: this.getIndexName(),
433453
type: this.getDocumentType(),
@@ -436,6 +456,7 @@
436456
}
437457
}, function(error, response) {
438458
if (error) {
459+
error.stack += previousError.stack;
439460
return reject(error);
440461
}
441462
return resolve(response);
@@ -444,10 +465,13 @@
444465
};
445466
openIndex = () => {
446467
return new Promise((resolve, reject) => {
468+
var previousError;
469+
previousError = new Error('From previous stack');
447470
return this._es.indices.open({
448471
index: this.getIndexName()
449472
}, function(error, response) {
450473
if (error) {
474+
error.stack += previousError.stack;
451475
return reject(error);
452476
}
453477
return resolve(response);
@@ -464,7 +488,7 @@
464488

465489
save(refresh = false) {
466490
return new Promise((resolve, reject) => {
467-
var args, convertError, dbFieldName, document, error, property, propertyName, ref, ref1, ref2;
491+
var args, convertError, dbFieldName, document, error, previousError, property, propertyName, ref, ref1, ref2;
468492
/*
469493
Save this document.
470494
@param refresh {bool} Refresh the index after performing the operation.
@@ -509,8 +533,10 @@
509533
body: document
510534
};
511535
}
536+
previousError = new Error('From previous stack');
512537
return this.constructor._es.index(args, (error, response) => {
513538
if (error) {
539+
error.stack += previousError.stack;
514540
return reject(error);
515541
}
516542
this.id = response._id;
@@ -526,13 +552,16 @@
526552
Delete this document.
527553
@returns {promise<Document>}
528554
*/
555+
var previousError;
556+
previousError = new Error('From previous stack');
529557
return this.constructor._es.delete({
530558
index: this.constructor.getIndexName(),
531559
type: this.constructor.getDocumentType(),
532560
refresh: refresh,
533561
id: this.id
534562
}, (error) => {
535563
if (error) {
564+
error.stack += previousError.stack;
536565
return reject(error);
537566
}
538567
return resolve(this);

lib/query.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267

268268
fetch(args = {}) {
269269
return new Promise((resolve, reject) => {
270-
var queryObject;
270+
var previousError, queryObject;
271271
/*
272272
Fetch documents by this query.
273273
@param args {object}
@@ -293,6 +293,7 @@
293293
});
294294
return;
295295
}
296+
previousError = new Error('From previous stack');
296297
return this.documentClass._es.search({
297298
index: this.documentClass.getIndexName(),
298299
body: {
@@ -305,6 +306,7 @@
305306
}, (error, response) => {
306307
var items, total;
307308
if (error) {
309+
error.stack += previousError.stack;
308310
return reject(error);
309311
}
310312
items = (() => {
@@ -374,15 +376,17 @@
374376
Count documents by the query.
375377
@returns {promise<number>}
376378
*/
377-
var queryObject;
379+
var previousError, queryObject;
378380
queryObject = this.compileQueries();
381+
previousError = new Error('From previous stack');
379382
return this.documentClass._es.count({
380383
index: this.documentClass.getIndexName(),
381384
body: {
382385
query: queryObject.query
383386
}
384387
}, function(error, response) {
385388
if (error) {
389+
error.stack += previousError.stack;
386390
return reject(error);
387391
}
388392
return resolve(response.count);
@@ -398,7 +402,7 @@
398402
@param field {string} The property name of the document.
399403
@returns {promise<number>}
400404
*/
401-
var allFields, dbField, property, propertyName, queryObject, ref, ref1, ref2, ref3;
405+
var allFields, dbField, previousError, property, propertyName, queryObject, ref, ref1, ref2, ref3;
402406
allFields = [];
403407
ref = this.documentClass._properties;
404408
for (propertyName in ref) {
@@ -416,6 +420,7 @@
416420
if (queryObject.isContainsEmpty) {
417421
return resolve(0);
418422
}
423+
previousError = new Error('From previous stack');
419424
return this.documentClass._es.search({
420425
index: this.documentClass.getIndexName(),
421426
body: {
@@ -431,6 +436,7 @@
431436
size: 0
432437
}, (error, response) => {
433438
if (error) {
439+
error.stack += previousError.stack;
434440
return reject(error);
435441
}
436442
return resolve(response.aggregations.intraday_return.value);
@@ -440,7 +446,7 @@
440446

441447
groupBy(field, args = {}) {
442448
return new Promise((resolve, reject) => {
443-
var allFields, dbField, property, propertyName, queryObject, ref, ref1, ref2, ref3, ref4;
449+
var allFields, dbField, previousError, property, propertyName, queryObject, ref, ref1, ref2, ref3, ref4;
444450
/*
445451
Aggregations
446452
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations.html
@@ -481,6 +487,7 @@
481487
if (queryObject.isContainsEmpty) {
482488
return resolve([]);
483489
}
490+
previousError = new Error('From previous stack');
484491
return this.documentClass._es.search({
485492
index: this.documentClass.getIndexName(),
486493
body: {
@@ -500,6 +507,7 @@
500507
size: 0
501508
}, (error, response) => {
502509
if (error) {
510+
error.stack += previousError.stack;
503511
return reject(error);
504512
}
505513
return resolve(response.aggregations.genres.buckets);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "enju",
3-
"version": "5.1.2",
3+
"version": "5.2.0",
44
"description": "An elasticsearch client on node.js written in CoffeeScript.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)