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
171 changes: 171 additions & 0 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,32 @@ Collection.prototype.deleteDocument = function (arg, options, cb) {
return this;
};

/**
* Deletes the current specifications of this collection
*
* @param {object} [options] - Optional parameters
* @param {responseCallback} [cb] - Handles the query response
* @return {object} this
*/
Collection.prototype.deleteSpecifications = function (options, cb) {
var
data = { index: this.index, collection: this.collection },
self = this;

if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('collection', 'deleteSpecifications'), data, options, function (err, res) {
cb(err, err ? undefined : res.result);
});

return self;
};

/**
* Returns a boolean indicating whether or not a document with provided ID exists.
*
Expand Down Expand Up @@ -553,6 +579,30 @@ Collection.prototype.mUpdateDocument = function (documents, options, cb) {
return self;
};

/**
* Retrieves the current specifications of this collection
*
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
*/
Collection.prototype.getSpecifications = function (options, cb) {
var
data = { index: this.index, collection: this.collection },
self = this;

if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

self.kuzzle.callbackRequired('Collection.getSpecifications', cb);
data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('collection', 'getSpecifications'), data, options, function (err, res) {
cb(err, err ? undefined : res.result);
});
};

/**
* Publish a realtime message
*
Expand Down Expand Up @@ -752,6 +802,68 @@ Collection.prototype.scroll = function (scrollId, options, filters, cb) {
return this;
};

/**
* Retrieves next result of a search with scroll query.
*
* @param {string} scrollId
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
*/
Collection.prototype.scrollSpecifications = function (scrollId, options, cb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other scroll methods return a KuzzleSearchResult object, shouldn't this one do the same?

var
data = { scrollId: scrollId };

if (!scrollId) {
throw new Error('Collection.scrollSpecifications: scrollId is required');
}

if (!cb && typeof options === 'function') {
cb = options;
options = {};
}

this.kuzzle.callbackRequired('Collection.scrollSpecifications', cb);

if (options && options.scroll) {
data.scroll = options.scroll;
}

this.kuzzle.query(
{ controller: 'collection', action: 'scrollSpecifications'},
this.kuzzle.addHeaders(data, this.headers),
options,
function (err, res) {
cb (err, err ? undefined : res.result);
}
);
};

/**
* Searches specifications across indexes/collections according to the provided filters
*
* @param {object} [filters] - Optional filters in ElasticSearch Query DSL format
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
*/
Collection.prototype.searchSpecifications = function (filters, options, cb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other search methods return a KuzzleSearchResult object, shouldn't this one do the same?

var
data = { body: { query: filters } },
self = this;

if (!cb && typeof options === 'function') {
cb = options;
options = {};
}

self.kuzzle.callbackRequired('Collection.searchSpecifications', cb);

data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query({ controller: 'collection', action: 'searchSpecifications' }, data, options, function (err, res) {
cb(err, err ? undefined : res.result);
});
};

/**
* Subscribes to this data collection with a set of filters.
* To subscribe to the entire data collection, simply provide an empty filter.
Expand Down Expand Up @@ -847,6 +959,65 @@ Collection.prototype.updateDocument = function (documentId, content, options, cb
return self;
};

/**
* Updates the current specifications of this collection
*
* @param {object} specifications - Specifications content
* @param {object} [options] - Optional parameters
* @param {responseCallback} [cb] - Handles the query response
* @return {object} this
*/
Collection.prototype.updateSpecifications = function (specifications, options, cb) {
var
collection = {},
data = { body: {} },
self = this;

collection[this.collection] = specifications;
data.body[this.index] = collection;

if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('collection', 'updateSpecifications'), data, options, cb && function (err, res) {
cb(err, err ? undefined : res.result);
});

return self;
};

/**
* Validates the provided specifications
*
* @param {object} specifications - Specifications content
* @param {object} [options] - Optional parameters
* @param {responseCallback} cb - Handles the query response
*/
Collection.prototype.validateSpecifications = function (specifications, options, cb) {
var
collection = {},
data = { body: {} },
self = this;

collection[this.collection] = specifications;
data.body[this.index] = collection;

if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

self.kuzzle.callbackRequired('Collection.validateSpecifications', cb);
data = self.kuzzle.addHeaders(data, this.headers);

self.kuzzle.query(this.buildQueryArgs('collection', 'validateSpecifications'), data, options, function (err, res) {
cb(err, err ? undefined : res.result.valid);
});
};

/**
* Instantiate a new Document object. Workaround to the module.exports limitation, preventing multiple
Expand Down
2 changes: 0 additions & 2 deletions src/security/Security.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ Security.prototype.scrollProfiles = function (scrollId, options, cb) {
scrollId: scrollId
});
});

return this;
};

/**
Expand Down
6 changes: 6 additions & 0 deletions test/Collection/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ describe('Collection constructor', function () {
should.exist(collection.createPromise);
should.exist(collection.createDocumentPromise);
should.exist(collection.deleteDocumentPromise);
should.exist(collection.deleteSpecificationsPromise);
should.exist(collection.documentExistsPromise);
should.exist(collection.fetchDocumentPromise);
should.exist(collection.getMappingPromise);
should.exist(collection.getSpecificationsPromise);
should.exist(collection.mCreateDocumentPromise);
should.exist(collection.mCreateOrReplaceDocumentPromise);
should.exist(collection.mDeleteDocumentPromise);
Expand All @@ -54,10 +56,14 @@ describe('Collection constructor', function () {
should.exist(collection.mUpdateDocumentPromise);
should.not.exist(collection.publishPromise);
should.exist(collection.replaceDocumentPromise);
should.exist(collection.scrollSpecificationsPromise);
should.exist(collection.searchSpecificationsPromise);
should.not.exist(collection.setHeadersPromise);
should.not.exist(collection.subscribePromise);
should.exist(collection.truncatePromise);
should.exist(collection.updateDocumentPromise);
should.exist(collection.updateSpecificationsPromise);
should.exist(collection.validateSpecificationsPromise);
});

it('should set headers using setHeaders', function () {
Expand Down
Loading