Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions dist/kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,11 @@ KuzzleDataCollection.prototype.advancedSearch = function (filters, options, cb)
}

result.result.hits.forEach(function (doc) {
documents.push(self.documentFactory(doc._id, doc));
var newDocument = new KuzzleDocument(self, doc._id, doc._source);

newDocument.version = doc._version;

documents.push(newDocument);
});

cb(null, { total: result.result.total, documents: documents });
Expand Down Expand Up @@ -1557,14 +1561,18 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,

if (cb) {
self.kuzzle.query(this.buildQueryArgs('write', action), data, options, function (err, res) {
var doc;

if (err) {
return cb(err);
}

cb(null, self.documentFactory(res.result._id, res.result));
doc = new KuzzleDocument(self, res.result._id, res.result._source);
doc.version = res.result._version;
cb(null, doc);
});
} else {
this.kuzzle.query(this.buildQueryArgs('write', action), data, options);
self.kuzzle.query(this.buildQueryArgs('write', action), data, options);
}

return this;
Expand Down Expand Up @@ -1668,11 +1676,15 @@ KuzzleDataCollection.prototype.fetchDocument = function (documentId, options, cb
data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('read', 'get'), data, options, function (err, res) {
var document;

if (err) {
return cb(err);
}

cb(null, self.documentFactory(res.result._id, res.result));
document = new KuzzleDocument(self, res.result._id, res.result._source);
document.version = res.result._version;
cb(null, document);
});

return this;
Expand Down Expand Up @@ -1801,11 +1813,15 @@ KuzzleDataCollection.prototype.replaceDocument = function (documentId, content,

if (cb) {
self.kuzzle.query(this.buildQueryArgs('write', 'createOrUpdate'), data, options, function (err, res) {
var document;

if (err) {
return cb(err);
}

cb(null, self.documentFactory(res.result._id, res.result));
document = new KuzzleDocument(self, res.result._id, res.result._source);
document.version = res.result._version;
cb(null, document);
});
} else {
self.kuzzle.query(this.buildQueryArgs('write', 'createOrUpdate'), data, options);
Expand Down Expand Up @@ -1916,13 +1932,7 @@ KuzzleDataCollection.prototype.updateDocument = function (documentId, content, o
* @constructor
*/
KuzzleDataCollection.prototype.documentFactory = function (id, content) {
var document = content._source ? new KuzzleDocument(this, id, content._source) : new KuzzleDocument(this, id, content);

if (content._version && content._source) {
document.version = content._version;
}

return document;
return new KuzzleDocument(this, id, content);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/kuzzle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kuzzle.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuzzle-sdk",
"version": "1.3.3",
"version": "1.3.4",
"description": "Official Javascript SDK for Kuzzle",
"author": "The Kuzzle Team <[email protected]>",
"repository": {
Expand Down
34 changes: 22 additions & 12 deletions src/kuzzleDataCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ KuzzleDataCollection.prototype.advancedSearch = function (filters, options, cb)
}

result.result.hits.forEach(function (doc) {
documents.push(self.documentFactory(doc._id, doc));
var newDocument = new KuzzleDocument(self, doc._id, doc._source);

newDocument.version = doc._version;

documents.push(newDocument);
});

cb(null, { total: result.result.total, documents: documents });
Expand Down Expand Up @@ -227,14 +231,18 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,

if (cb) {
self.kuzzle.query(this.buildQueryArgs('write', action), data, options, function (err, res) {
var doc;

if (err) {
return cb(err);
}

cb(null, self.documentFactory(res.result._id, res.result));
doc = new KuzzleDocument(self, res.result._id, res.result._source);
doc.version = res.result._version;
cb(null, doc);
});
} else {
this.kuzzle.query(this.buildQueryArgs('write', action), data, options);
self.kuzzle.query(this.buildQueryArgs('write', action), data, options);
}

return this;
Expand Down Expand Up @@ -338,11 +346,15 @@ KuzzleDataCollection.prototype.fetchDocument = function (documentId, options, cb
data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('read', 'get'), data, options, function (err, res) {
var document;

if (err) {
return cb(err);
}

cb(null, self.documentFactory(res.result._id, res.result));
document = new KuzzleDocument(self, res.result._id, res.result._source);
document.version = res.result._version;
cb(null, document);
});

return this;
Expand Down Expand Up @@ -471,11 +483,15 @@ KuzzleDataCollection.prototype.replaceDocument = function (documentId, content,

if (cb) {
self.kuzzle.query(this.buildQueryArgs('write', 'createOrUpdate'), data, options, function (err, res) {
var document;

if (err) {
return cb(err);
}

cb(null, self.documentFactory(res.result._id, res.result));
document = new KuzzleDocument(self, res.result._id, res.result._source);
document.version = res.result._version;
cb(null, document);
});
} else {
self.kuzzle.query(this.buildQueryArgs('write', 'createOrUpdate'), data, options);
Expand Down Expand Up @@ -586,13 +602,7 @@ KuzzleDataCollection.prototype.updateDocument = function (documentId, content, o
* @constructor
*/
KuzzleDataCollection.prototype.documentFactory = function (id, content) {
var document = content._source ? new KuzzleDocument(this, id, content._source) : new KuzzleDocument(this, id, content);

if (content._version && content._source) {
document.version = content._version;
}

return document;
return new KuzzleDocument(this, id, content);
};

/**
Expand Down
4 changes: 0 additions & 4 deletions test/kuzzleDataCollection/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,10 +1002,6 @@ describe('KuzzleDataCollection methods', function () {
should(kuzzle.dataCollectionFactory('foo').documentFactory('foo', { foo: 'bar'})).be.instanceof(KuzzleDocument);
});

it('documentFactory should handle a _source content', function () {
should(kuzzle.dataCollectionFactory('foo').documentFactory('foo', { _source: {foo: 'bar'}})).be.instanceof(KuzzleDocument);
});

it('roomFactory should return a new KuzzleRoom object', function () {
should(kuzzle.dataCollectionFactory('foo').roomFactory()).be.instanceof(KuzzleRoom);
});
Expand Down