Skip to content

Commit 5a3fee1

Browse files
author
ballinette
committed
Merge branch 'master' into 5.x
# Conflicts: # src/Document.js # test/Collection/methods.test.js # test/security/kuzzleSecurity/userMethods.test.js
2 parents 514828f + 80f303f commit 5a3fee1

File tree

10 files changed

+66
-17
lines changed

10 files changed

+66
-17
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# [4.0.1](https://github.com/kuzzleio/sdk-javascript/releases/tag/4.0.1) (2017-05-9)
2+
3+
[Full Changelog](https://github.com/kuzzleio/sdk-javascript/compare/4.0.1...4.0.1)
4+
5+
### Compatibility
6+
7+
| Kuzzle | Proxy |
8+
|--------|-------|
9+
| 1.0.0-RC10 | 1.0.0-RC10 |
10+
11+
#### Enhancements
12+
13+
- [ [#200](https://github.com/kuzzleio/sdk-javascript/pull/200) ] Add kuzzle info in Document object ([AnthonySendra](https://github.com/AnthonySendra))
14+
115
# [4.0.0](https://github.com/kuzzleio/sdk-javascript/releases/tag/4.0.0) (2017-04-10)
216

317
[Full Changelog](https://github.com/kuzzleio/sdk-javascript/compare/4.0.0...4.0.0)
@@ -36,6 +50,7 @@
3650
- [ [#177](https://github.com/kuzzleio/sdk-javascript/pull/177) ] Remove previous and next cache in SearchResult ([dbengsch](https://github.com/dbengsch))
3751
- [ [#177](https://github.com/kuzzleio/sdk-javascript/pull/177) ] Remove previous and next cache in SearchResult ([dbengsch](https://github.com/dbengsch))
3852
- [ [#184](https://github.com/kuzzleio/sdk-javascript/pull/184) ] Browsers compatibility fix ([scottinet](https://github.com/scottinet))
53+
3954
---
4055

4156
# 3.4.0

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ You can access the Kuzzle repository on [Github](https://github.com/kuzzleio/kuz
2626

2727
## SDK Documentation
2828

29-
The complete SDK documentation is available [here](http://kuzzleio.github.io/sdk-documentation)
29+
The complete SDK documentation is available [here](http://docs.kuzzle.io/sdk-reference/?javascript#kuzzle)
30+
31+
## Report an issue
32+
33+
Use following meta repository to report issues on SDK:
34+
35+
https://github.com/kuzzleio/kuzzle-sdk/issues
3036

3137
## Protocols used
3238

dist/kuzzle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.0",
3+
"version": "4.0.1",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <support@kuzzle.io>",
66
"repository": {

src/Collection.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Collection.prototype.createDocument = function (id, document, options, cb) {
193193
return cb(err);
194194
}
195195

196-
doc = new Document(self, res.result._id, res.result._source);
196+
doc = new Document(self, res.result._id, res.result._source, res.result._meta);
197197
doc.version = res.result._version;
198198
cb(null, doc);
199199
});
@@ -276,7 +276,7 @@ Collection.prototype.fetchDocument = function (documentId, options, cb) {
276276
return cb(err);
277277
}
278278

279-
document = new Document(self, res.result._id, res.result._source);
279+
document = new Document(self, res.result._id, res.result._source, res.result._meta);
280280
document.version = res.result._version;
281281
cb(null, document);
282282
});
@@ -419,7 +419,7 @@ Collection.prototype.replaceDocument = function (documentId, content, options, c
419419
return cb(err);
420420
}
421421

422-
document = new Document(self, res.result._id, res.result._source);
422+
document = new Document(self, res.result._id, res.result._source, res.result._meta);
423423
document.version = res.result._version;
424424
cb(null, document);
425425
});
@@ -462,7 +462,7 @@ Collection.prototype.search = function (filters, options, cb) {
462462
}
463463

464464
result.result.hits.forEach(function (doc) {
465-
var newDocument = new Document(self, doc._id, doc._source);
465+
var newDocument = new Document(self, doc._id, doc._source, doc._meta);
466466

467467
newDocument.version = doc._version;
468468

@@ -531,7 +531,7 @@ Collection.prototype.scroll = function (scrollId, options, filters, cb) {
531531
}
532532

533533
result.result.hits.forEach(function (doc) {
534-
var newDocument = new Document(self, doc._id, doc._source);
534+
var newDocument = new Document(self, doc._id, doc._source, doc._meta);
535535

536536
newDocument.version = doc._version;
537537

src/Document.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
* @param {Collection} collection - an instanciated Collection object
1919
* @param {string} [documentId] - ID of an existing document
2020
* @param {object} [content] - Initializes this document with the provided content
21+
* @param {object} [meta] - Initializes this document with the provided meta
2122
* @constructor
2223
*/
23-
function Document(collection, documentId, content) {
24+
function Document(collection, documentId, content, meta) {
2425
Object.defineProperties(this, {
2526
// read-only properties
2627
collection: {
@@ -55,6 +56,11 @@ function Document(collection, documentId, content) {
5556
value: undefined,
5657
enumerable: true,
5758
writable: true
59+
},
60+
meta: {
61+
value: meta || {},
62+
enumerable: true,
63+
writable: false
5864
}
5965
});
6066

@@ -112,6 +118,7 @@ Document.prototype.serialize = function () {
112118
}
113119

114120
data.body = this.content;
121+
data.meta = this.meta;
115122
data = this.kuzzle.addHeaders(data, this.headers);
116123

117124
return data;
@@ -182,7 +189,7 @@ Document.prototype.refresh = function (options, cb) {
182189
return cb(error);
183190
}
184191

185-
newDocument = new Document(self.dataCollection, self.id, res.result._source);
192+
newDocument = new Document(self.dataCollection, self.id, res.result._source, res.result._meta);
186193
newDocument.version = res.result._version;
187194

188195
cb(null, newDocument);

src/Room.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ function notificationCallback (data) {
322322

323323
if (data.controller === 'document' || (data.controller === 'realtime' && data.action === 'publish')) {
324324
data.type = 'document';
325-
data.document = new Document(this.collection, data.result._id, data.result._source);
325+
data.document = new Document(this.collection, data.result._id, data.result._source, data.result._meta);
326326
delete data.result;
327327
}
328328
else if (data.controller === 'realtime') {

test/Collection/methods.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ describe('Collection methods', function () {
2626

2727
describe('#search', function () {
2828
beforeEach(function () {
29-
result = { result: { _scroll_id: 'banana', total: 123, hits: [ {_id: 'foobar', _source: { foo: 'bar'}} ], aggregations: {someAggregate: {}}}};
29+
result = {
30+
result: {
31+
_scroll_id: 'banana',
32+
total: 123,
33+
hits: [
34+
{_id: 'foobar', _source: { foo: 'bar'}, _meta: {author: 'toto'}}
35+
],
36+
aggregations: {someAggregate: {}}
37+
}
38+
};
3039
expectedQuery = {
3140
index: 'bar',
3241
collection: 'foo',
@@ -355,7 +364,7 @@ describe('Collection methods', function () {
355364
})).be.exactly(collection);
356365

357366
should(kuzzle.query).be.calledOnce();
358-
should(kuzzle.query).calledWith(expectedQuery, {body: content}, null, sinon.match.func);
367+
should(kuzzle.query).calledWith(expectedQuery, {body: content, meta: {}}, null, sinon.match.func);
359368

360369
kuzzle.query.yield(null, result);
361370
});
@@ -672,7 +681,7 @@ describe('Collection methods', function () {
672681

673682
collection.publishMessage(new Document(collection, content), options);
674683
should(kuzzle.query).be.calledOnce();
675-
should(kuzzle.query).calledWith(expectedQuery, {body: content}, options);
684+
should(kuzzle.query).calledWith(expectedQuery, {body: content, meta: {}}, options);
676685
});
677686
});
678687

test/Document/constructor.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,37 @@ describe('Document constructor', function () {
2222
should(document).be.instanceof(Document);
2323
should(document.id).be.undefined();
2424
should(document.content).be.empty();
25+
should(document.meta).be.empty();
2526
should(document.version).be.undefined();
2627
should(document.collection).be.exactly('foo');
2728

2829
document = new Document(collection, { some: 'content' });
2930
should(document.id).be.undefined();
3031
should(document.content).match({some: 'content'});
32+
should(document.meta).be.empty();
3133
should(document.version).be.undefined();
3234
should(document.collection).be.exactly('foo');
3335

3436
document = new Document(collection, 'id', { some: 'content', _version: 123 });
3537
should(document.id).be.exactly('id');
3638
should(document.content).match({some: 'content'});
39+
should(document.meta).be.empty();
3740
should(document.version).be.exactly(123);
3841
should(document.collection).be.exactly('foo');
3942

4043
document = new Document(collection, 'id');
4144
should(document.id).be.exactly('id');
4245
should(document.content).be.empty();
46+
should(document.meta).be.empty();
4347
should(document.version).be.undefined();
4448
should(document.collection).be.exactly('foo');
49+
50+
document = new Document(collection, 'id', { some: 'content', _version: 123 }, {author: 'toto'});
51+
should(document.id).be.exactly('id');
52+
should(document.content).match({some: 'content'});
53+
should(document.meta).match({author: 'toto'});
54+
should(document.version).be.exactly(123);
55+
should(document.collection).be.exactly('foo');
4556
});
4657

4758
it('should expose documented properties with the right permissions', function () {
@@ -52,6 +63,7 @@ describe('Document constructor', function () {
5263
should(document).have.propertyWithDescriptor('headers', { enumerable: true, writable: true, configurable: false });
5364
should(document).have.propertyWithDescriptor('id', { enumerable: true, writable: true, configurable: false });
5465
should(document).have.propertyWithDescriptor('version', { enumerable: true, writable: true, configurable: false });
66+
should(document).have.propertyWithDescriptor('meta', { enumerable: true, writable: false, configurable: false });
5567
});
5668

5769
it('should promisify the right functions', function () {

test/Document/methods.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('Document methods', function () {
7474
document.id = 'foo';
7575
document.delete(options);
7676
should(kuzzle.query).be.calledOnce();
77-
should(kuzzle.query).calledWith(expectedQuery, {_id: 'foo', body: {}}, options);
77+
should(kuzzle.query).calledWith(expectedQuery, {_id: 'foo', body: {}, meta: {}}, options);
7878
});
7979

8080
it('should handle arguments correctly', function () {
@@ -241,7 +241,7 @@ describe('Document methods', function () {
241241
document.id = 'foo';
242242
should(document.save(options)).be.exactly(document);
243243
should(kuzzle.query).be.calledOnce();
244-
should(kuzzle.query).calledWith(expectedQuery, {_id: 'foo', body: {}}, options);
244+
should(kuzzle.query).calledWith(expectedQuery, {_id: 'foo', body: {}, meta: {}}, options);
245245
});
246246

247247
it('should handle arguments correctly', function () {
@@ -311,7 +311,7 @@ describe('Document methods', function () {
311311

312312
should(document.publish(options)).be.exactly(document);
313313
should(kuzzle.query).be.calledOnce();
314-
should(kuzzle.query).calledWith(expectedQuery, {body: {}}, options);
314+
should(kuzzle.query).calledWith(expectedQuery, {body: {}, meta: {}}, options);
315315
});
316316

317317
it('should handle arguments correctly', function () {

0 commit comments

Comments
 (0)