Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function refreshIndexIfNeeded(esRequest, response) {
if (esRequest && esRequest.index && this.settings.autoRefresh[esRequest.index]) {
return this.refreshIndex(new Request({index: esRequest.index}))
.then(() => response)
.catch(error => {
// index refresh failures are non-blocking
this.kuzzle.pluginsManager.trigger('log:error', new InternalError('Error refreshing index ' + esRequest.index + ':\n' + error.message));
return Promise.resolve(response);
});
}
return Promise.resolve(response);
}
size: this.kuzzle.config.services.garbageCollector.maxDelete || 10000,
sort: [{ '_kuzzle_info.deletedAt': { unmapped_type: 'date'} }],
query: {
bool: {
should: [
{
term: {
'_kuzzle_info.active': false
}
}
]
}
}
};
const request = new Request({index, collection, body});
return this.kuzzle.services.list.storageEngine.deleteByQueryFromTrash(request)
.then(deletedDocs => deletedDocs.ids)
.catch(error => {
this.kuzzle.log.error(error);
// always resolve the promise, we don't want to break the GC when an error occurs
return [];
});
}
}
onMessage (packet, client) {
debug('[mqtt] onMessage packet: %a', packet);
if (packet.topic === this.config.requestTopic && packet.payload && client.id) {
const connection = this.connections.get(client);
if (connection === undefined) {
debug('[mqtt] no connection id for client id %s', client.id);
return;
}
try {
const payload = JSON.parse(packet.payload.toString());
const request = new Request(payload, {
connection,
// @deprecated - backward compatibility only
connectionId: connection.id,
protocol: this.name
});
return this.entryPoint.execute(
request,
response => this._respond(client, response));
} catch (error) {
return this._respondError(client, error);
}
}
}
try {
this._removeRoomFromRealtimeEngine(roomId);
}
catch(err) {
return Bluebird.reject(err);
}
room.customers = new Set();
}
else {
room.customers.delete(requestContext.connection.id);
}
// even if the room is deleted for this node, another one may need the notification
const request = new Request(
{
controller: 'realtime',
action: 'unsubscribe',
index: room.index,
collection: room.collection,
volatile
},
requestContext);
return this.kuzzle.notifier
.notifyUser(roomId, request, 'out', {count: room.customers.size})
.then(() => {
if (notify) {
return this.kuzzle.pipe(
'core:hotelClerk:removeRoomForCustomer',
{ requestContext, room });
listSubscriptions (request) {
const
list = {},
promises = [];
for (const index of this.kuzzle.koncorde.getIndexes()) {
for (const collection of this.kuzzle.koncorde.getCollections(index)) {
const isAllowedRequest = new Request({
controller: 'document',
action: 'search',
index,
collection
}, request.context);
promises.push(request.context.user.isActionAllowed(isAllowedRequest)
.then(isAllowed => {
if (!isAllowed) {
return;
}
for (const roomId of this.kuzzle.koncorde.getFilterIds(index, collection)) {
const room = this.rooms.get(roomId);
// the room may be currently registered in the real-time engine
// and not in the hotel clerk
it('should fail if the request has no id', () => {
const request = new Request({
body: {}
});
should(() => mDelete(kuzzle, 'type', request))
.throw(BadRequestError, { id: 'api.assert.missing_argument'});
});
.onSecondCall().yields(null, (() => {
const req = new Request({_id: 'bar'});
req.setError(error);
return req;
})());
.each(request => {
const
index = request.input.resource.index,
indexRequest = new Request({index});
return this.kuzzle.services.list.storageEngine.indexExists(indexRequest)
.then(exist => {
if (! exist) {
return this.kuzzle.services.list.storageEngine.createIndex(indexRequest);
}
})
.then(() => this.kuzzle.services.list.storageEngine.updateMapping(request))
.then(() => this.kuzzle.services.list.storageEngine.refreshIndex(indexRequest))
.then(() => {
const collection = request.input.resource.collection;
this.kuzzle.indexCache.add(index, collection);
return null;
});
_indexExists(index, hotReload) {
if (this.indexes[index]) {
return Bluebird.resolve(true);
} else if (!hotReload) {
return Bluebird.resolve(false);
}
const request = new Request({ index });
return this.kuzzle.services.list.storageEngine.indexExists(request)
.then(indexExists => {
if (!indexExists) {
return false;
}
return this.add(index, null, true);
});
}
.then(() => {
const indexRequest = new Request({ index: request.input.resource.index });
return this.kuzzle.services.list.storageEngine.refreshIndex(indexRequest);
});
});