Skip to content

Commit

Permalink
chore: release v5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kelp404 committed Apr 23, 2022
1 parent 9b4df13 commit 5039bee
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
35 changes: 32 additions & 3 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

static get(ids, fetchReference = true) {
return new Promise((resolve, reject) => {
var x;
var previousError, x;
/*
Fetch the document with id or ids.
If the document is not exist, it will return null.
Expand Down Expand Up @@ -144,6 +144,7 @@
}
// fetch documents
if (ids.constructor === Array) {
previousError = new Error('From previous stack');
this._es.mget({
index: this.getIndexName(),
type: this.getDocumentType(),
Expand All @@ -153,6 +154,7 @@
}, (error, response) => {
var dbField, doc, i, item, len, property, propertyName, ref, ref1, ref2, result;
if (error) {
error.stack += previousError.stack;
return reject(error);
}
result = [];
Expand Down Expand Up @@ -190,13 +192,15 @@
return;
}
// fetch the document
previousError = new Error('From previous stack');
return this._es.get({
index: this.getIndexName(),
type: this.getDocumentType(),
id: ids
}, (error, response) => {
var args, dbField, document, property, propertyName, ref, ref1;
if (error) {
error.stack += previousError.stack;
if (error.status === 404) {
return resolve(null);
}
Expand Down Expand Up @@ -236,12 +240,15 @@
@param id {string} The documents' id.
@returns {promise<bool>}
*/
var previousError;
previousError = new Error('From previous stack');
return this._es.exists({
index: this.getIndexName(),
type: this.getDocumentType(),
id: id
}, function(error, response) {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(response);
Expand Down Expand Up @@ -269,15 +276,18 @@

static refresh(args = {}) {
return new Promise((resolve, reject) => {
var previousError;
/*
Explicitly refresh one or more index, making all operations performed since the last refresh available for search.
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-5-6.html#api-indices-refresh-5-6
@params args {object}
@returns {promise}
*/
args.index = this.getIndexName();
previousError = new Error('From previous stack');
return this._es.indices.refresh(args, function(error) {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve();
Expand All @@ -295,10 +305,13 @@
var closeIndex, createIndex, openIndex, putMapping, putSettings;
createIndex = () => {
return new Promise((resolve, reject) => {
var previousError;
previousError = new Error('From previous stack');
return this._es.indices.create({
index: this.getIndexName()
}, function(error, response) {
if (error && error.status !== 400) {
error.stack += previousError.stack;
return reject(error);
}
return setTimeout(function() {
Expand All @@ -309,10 +322,13 @@
};
closeIndex = () => {
return new Promise((resolve, reject) => {
var previousError;
previousError = new Error('From previous stack');
return this._es.indices.close({
index: this.getIndexName()
}, function(error, response) {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(response);
Expand All @@ -321,9 +337,11 @@
};
putSettings = () => {
return new Promise((resolve, reject) => {
var previousError;
if (!this._settings) {
return resolve();
}
previousError = new Error('From previous stack');
return this._es.indices.putSettings({
index: this.getIndexName(),
body: {
Expand All @@ -333,6 +351,7 @@
}
}, function(error, response) {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(response);
Expand All @@ -341,7 +360,7 @@
};
putMapping = () => {
return new Promise((resolve, reject) => {
var field, mapping, property, propertyName, ref, ref1, ref2, ref3;
var field, mapping, previousError, property, propertyName, ref, ref1, ref2, ref3;
mapping = {};
ref = this._properties;
for (propertyName in ref) {
Expand Down Expand Up @@ -428,6 +447,7 @@
mapping[(ref3 = property.dbField) != null ? ref3 : propertyName] = field;
}
}
previousError = new Error('From previous stack');
return this._es.indices.putMapping({
index: this.getIndexName(),
type: this.getDocumentType(),
Expand All @@ -436,6 +456,7 @@
}
}, function(error, response) {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(response);
Expand All @@ -444,10 +465,13 @@
};
openIndex = () => {
return new Promise((resolve, reject) => {
var previousError;
previousError = new Error('From previous stack');
return this._es.indices.open({
index: this.getIndexName()
}, function(error, response) {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(response);
Expand All @@ -464,7 +488,7 @@

save(refresh = false) {
return new Promise((resolve, reject) => {
var args, convertError, dbFieldName, document, error, property, propertyName, ref, ref1, ref2;
var args, convertError, dbFieldName, document, error, previousError, property, propertyName, ref, ref1, ref2;
/*
Save this document.
@param refresh {bool} Refresh the index after performing the operation.
Expand Down Expand Up @@ -509,8 +533,10 @@
body: document
};
}
previousError = new Error('From previous stack');
return this.constructor._es.index(args, (error, response) => {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
this.id = response._id;
Expand All @@ -526,13 +552,16 @@
Delete this document.
@returns {promise<Document>}
*/
var previousError;
previousError = new Error('From previous stack');
return this.constructor._es.delete({
index: this.constructor.getIndexName(),
type: this.constructor.getDocumentType(),
refresh: refresh,
id: this.id
}, (error) => {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(this);
Expand Down
16 changes: 12 additions & 4 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@

fetch(args = {}) {
return new Promise((resolve, reject) => {
var queryObject;
var previousError, queryObject;
/*
Fetch documents by this query.
@param args {object}
Expand All @@ -293,6 +293,7 @@
});
return;
}
previousError = new Error('From previous stack');
return this.documentClass._es.search({
index: this.documentClass.getIndexName(),
body: {
Expand All @@ -305,6 +306,7 @@
}, (error, response) => {
var items, total;
if (error) {
error.stack += previousError.stack;
return reject(error);
}
items = (() => {
Expand Down Expand Up @@ -374,15 +376,17 @@
Count documents by the query.
@returns {promise<number>}
*/
var queryObject;
var previousError, queryObject;
queryObject = this.compileQueries();
previousError = new Error('From previous stack');
return this.documentClass._es.count({
index: this.documentClass.getIndexName(),
body: {
query: queryObject.query
}
}, function(error, response) {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(response.count);
Expand All @@ -398,7 +402,7 @@
@param field {string} The property name of the document.
@returns {promise<number>}
*/
var allFields, dbField, property, propertyName, queryObject, ref, ref1, ref2, ref3;
var allFields, dbField, previousError, property, propertyName, queryObject, ref, ref1, ref2, ref3;
allFields = [];
ref = this.documentClass._properties;
for (propertyName in ref) {
Expand All @@ -416,6 +420,7 @@
if (queryObject.isContainsEmpty) {
return resolve(0);
}
previousError = new Error('From previous stack');
return this.documentClass._es.search({
index: this.documentClass.getIndexName(),
body: {
Expand All @@ -431,6 +436,7 @@
size: 0
}, (error, response) => {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(response.aggregations.intraday_return.value);
Expand All @@ -440,7 +446,7 @@

groupBy(field, args = {}) {
return new Promise((resolve, reject) => {
var allFields, dbField, property, propertyName, queryObject, ref, ref1, ref2, ref3, ref4;
var allFields, dbField, previousError, property, propertyName, queryObject, ref, ref1, ref2, ref3, ref4;
/*
Aggregations
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations.html
Expand Down Expand Up @@ -481,6 +487,7 @@
if (queryObject.isContainsEmpty) {
return resolve([]);
}
previousError = new Error('From previous stack');
return this.documentClass._es.search({
index: this.documentClass.getIndexName(),
body: {
Expand All @@ -500,6 +507,7 @@
size: 0
}, (error, response) => {
if (error) {
error.stack += previousError.stack;
return reject(error);
}
return resolve(response.aggregations.genres.buckets);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enju",
"version": "5.1.2",
"version": "5.2.0",
"description": "An elasticsearch client on node.js written in CoffeeScript.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 5039bee

Please sign in to comment.