How to use kuzzle-common-objects - 10 common examples

To help you get started, we’ve selected a few kuzzle-common-objects examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kuzzleio / kuzzle / lib / services / elasticsearch.js View on Github external
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);
}
github kuzzleio / kuzzle / lib / services / garbageCollector.js View on Github external
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 [];
      });
  }
}
github kuzzleio / kuzzle / lib / core / entrypoints / protocols / mqtt.js View on Github external
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);
      }
    }
  }
github kuzzleio / kuzzle / lib / core / hotelClerk.js View on Github external
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 });
github kuzzleio / kuzzle / lib / core / hotelClerk.js View on Github external
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
github kuzzleio / kuzzle / test / api / controllers / security / index.js View on Github external
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'});

    });
github kuzzleio / kuzzle / test / api / controllers / security / index.js View on Github external
.onSecondCall().yields(null, (() => {
          const req = new Request({_id: 'bar'});
          req.setError(error);
          return req;
        })());
github kuzzleio / kuzzle / lib / api / core / janitor.js View on Github external
.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;
          });
github kuzzleio / kuzzle / lib / api / core / indexCache.js View on Github external
_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);
      });
  }
github kuzzleio / kuzzle / lib / api / core / janitor.js View on Github external
.then(() => {
            const indexRequest = new Request({ index: request.input.resource.index });

            return this.kuzzle.services.list.storageEngine.refreshIndex(indexRequest);
          });
      });

kuzzle-common-objects

Common objects shared to various Kuzzle components and plugins

Apache-2.0
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis

Popular kuzzle-common-objects functions

Similar packages