Skip to content

Commit ba1bb6d

Browse files
authored
Merge pull request #223 from kuzzleio/5.0.0-proposal
Release 5.0.0
2 parents 977d2d1 + 334feb3 commit ba1bb6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+5065
-4779
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "4.0.1",
3+
"version": "5.0.0",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <support@kuzzle.io>",
66
"repository": {

src/Collection.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ Collection.prototype.count = function (filters, options, cb) {
102102

103103
query = this.kuzzle.addHeaders({body: filters}, this.headers);
104104

105-
this.kuzzle.query(this.buildQueryArgs('document', 'count'), query, options, function (error, result) {
106-
cb(error, result && result.result.count);
105+
this.kuzzle.query(this.buildQueryArgs('document', 'count'), query, options, function (err, res) {
106+
cb(err, err ? undefined : res.result.count);
107107
});
108108
};
109109

@@ -249,6 +249,30 @@ Collection.prototype.deleteDocument = function (arg, options, cb) {
249249
return this;
250250
};
251251

252+
/**
253+
* Returns a boolean indicating whether or not a document with provided ID exists.
254+
*
255+
* @param {string} documentId - Unique document identifier
256+
* @param {object} options [options] - Optional parameters
257+
* @param {responseCallback} cb - Handles the query response
258+
*/
259+
Collection.prototype.documentExists = function (documentId, options, cb) {
260+
var
261+
data = {_id: documentId},
262+
self = this;
263+
264+
if (!cb && typeof options === 'function') {
265+
cb = options;
266+
options = null;
267+
}
268+
269+
self.kuzzle.callbackRequired('Collection.documentExists', cb);
270+
271+
self.kuzzle.query(this.buildQueryArgs('document', 'exists'), data, options, function (err, res) {
272+
cb(err, err ? undefined : res.result);
273+
});
274+
};
275+
252276
/**
253277
* Retrieve a single stored document using its unique document ID.
254278
*

src/Document.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ Document.prototype.serialize = function () {
113113
data._id = this.id;
114114
}
115115

116+
if (this.version) {
117+
data._version = this.version;
118+
}
119+
116120
data.body = this.content;
117121
data.meta = this.meta;
118-
data._version = this.version;
119122
data = this.kuzzle.addHeaders(data, this.headers);
120123

121124
return data;
@@ -158,6 +161,30 @@ Document.prototype.delete = function (options, cb) {
158161
});
159162
};
160163

164+
/**
165+
* Checks if this document exists in Kuzzle.
166+
*
167+
* @param {object} [options] - Optional parameters
168+
* @param {responseCallback} [cb] - Handles the query response
169+
* @returns {*} this
170+
*/
171+
Document.prototype.exists = function (options, cb) {
172+
var self = this;
173+
174+
if (!cb && typeof options === 'function') {
175+
cb = options;
176+
options = null;
177+
}
178+
179+
if (!self.id) {
180+
throw new Error('Document.exists: cannot check if the document exists if no id has been provided');
181+
}
182+
183+
this.kuzzle.query(this.dataCollection.buildQueryArgs('document', 'exists'), this.serialize(), options, cb && function (err, res) {
184+
cb(err, err ? undefined : res.result);
185+
});
186+
};
187+
161188
/**
162189
* Replaces the current content with the last version of this document stored in Kuzzle.
163190
*

0 commit comments

Comments
 (0)