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
16 changes: 8 additions & 8 deletions dist/kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,
}

if (document instanceof KuzzleDocument) {
data = document.toJSON();
data = document.serialize();
} else {
data.body = document;
}
Expand Down Expand Up @@ -1849,7 +1849,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options) {
var data = {};

if (document instanceof KuzzleDocument) {
data = document.toJSON();
data = document.serialize();
} else {
data.body = document;
}
Expand Down Expand Up @@ -2313,7 +2313,7 @@ function KuzzleDocument(kuzzleDataCollection, documentId, content) {
*
* @return {object} JSON object representing this document
*/
KuzzleDocument.prototype.toJSON = function () {
KuzzleDocument.prototype.serialize = function () {
var
data = {};

Expand All @@ -2334,7 +2334,7 @@ KuzzleDocument.prototype.toJSON = function () {
* @return {string} serialized version of this object
*/
KuzzleDocument.prototype.toString = function () {
return JSON.stringify(this.toJSON());
return JSON.stringify(this.serialize());
};

/**
Expand All @@ -2361,15 +2361,15 @@ KuzzleDocument.prototype.delete = function (options, cb) {
}

if (cb) {
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.toJSON(), options, function (err) {
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options, function (err) {
if (err) {
return cb(err);
}

cb(null, self);
});
} else {
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.toJSON(), options);
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options);
}

return this;
Expand Down Expand Up @@ -2427,7 +2427,7 @@ KuzzleDocument.prototype.refresh = function (options, cb) {
*/
KuzzleDocument.prototype.save = function (options, cb) {
var
data = this.toJSON(),
data = this.serialize(),
self = this;

if (options && cb === undefined && typeof options === 'function') {
Expand Down Expand Up @@ -2462,7 +2462,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
* @returns {*} this
*/
KuzzleDocument.prototype.publish = function (options) {
var data = this.toJSON();
var data = this.serialize();

this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'publish'), data, options);

Expand Down
2 changes: 1 addition & 1 deletion 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.

4 changes: 2 additions & 2 deletions src/kuzzleDataCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,
}

if (document instanceof KuzzleDocument) {
data = document.toJSON();
data = document.serialize();
} else {
data.body = document;
}
Expand Down Expand Up @@ -418,7 +418,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options) {
var data = {};

if (document instanceof KuzzleDocument) {
data = document.toJSON();
data = document.serialize();
} else {
data.body = document;
}
Expand Down
12 changes: 6 additions & 6 deletions src/kuzzleDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function KuzzleDocument(kuzzleDataCollection, documentId, content) {
*
* @return {object} JSON object representing this document
*/
KuzzleDocument.prototype.toJSON = function () {
KuzzleDocument.prototype.serialize = function () {
var
data = {};

Expand All @@ -120,7 +120,7 @@ KuzzleDocument.prototype.toJSON = function () {
* @return {string} serialized version of this object
*/
KuzzleDocument.prototype.toString = function () {
return JSON.stringify(this.toJSON());
return JSON.stringify(this.serialize());
};

/**
Expand All @@ -147,15 +147,15 @@ KuzzleDocument.prototype.delete = function (options, cb) {
}

if (cb) {
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.toJSON(), options, function (err) {
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options, function (err) {
if (err) {
return cb(err);
}

cb(null, self);
});
} else {
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.toJSON(), options);
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options);
}

return this;
Expand Down Expand Up @@ -213,7 +213,7 @@ KuzzleDocument.prototype.refresh = function (options, cb) {
*/
KuzzleDocument.prototype.save = function (options, cb) {
var
data = this.toJSON(),
data = this.serialize(),
self = this;

if (options && cb === undefined && typeof options === 'function') {
Expand Down Expand Up @@ -248,7 +248,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
* @returns {*} this
*/
KuzzleDocument.prototype.publish = function (options) {
var data = this.toJSON();
var data = this.serialize();

this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'publish'), data, options);

Expand Down
8 changes: 4 additions & 4 deletions test/kuzzleDocument/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ describe('KuzzleDocument methods', function () {
it('should serialize itself properly', function () {
var
document = new KuzzleDocument(dataCollection, {some: 'content'}),
serialized = document.toJSON();
serialized = document.serialize();

should(serialized._id).be.undefined();
should(serialized._version).be.undefined();
should(serialized.body).be.an.Object().and.match({some: 'content'});

document.id = 'foo';
serialized = document.toJSON();
serialized = document.serialize();
should(serialized._id).be.exactly('foo');
should(serialized._version).be.undefined();
should(serialized.body).be.an.Object().and.match({some: 'content'});

document.version = 42;
serialized = document.toJSON();
serialized = document.serialize();
should(serialized._id).be.exactly('foo');
should(serialized._version).be.exactly(42);
should(serialized.body).be.an.Object().and.match({some: 'content'});
Expand All @@ -86,7 +86,7 @@ describe('KuzzleDocument methods', function () {
it('should stringify itself properly', function () {
var
document = new KuzzleDocument(dataCollection, 'id', {some: 'content', _version: 42}),
serialized = document.toJSON(),
serialized = document.serialize(),
stringified = document.toString();

should(stringified).be.a.String();
Expand Down