Generic Document Events

Available since 1.9.0

Some actions in the document controller trigger generic events. Generic events are used to apply modifications on the documents in the request or result of these actions.

Generic "before" events (generic:document:before*) are triggered before the regular document:before* event.
Generic "after" events (generic:document:after*) are triggered after the regular document:after* event.

All the pipes triggered by generic events have the same signature and should resolves the array of the updated documents from parameters.

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:<event>': async (documents, request) => {
        // some random change on documents

        return documents;
      }
    };
  }

}

generic:document:beforeWrite

Arguments Type Description
documents Array Array of documents (containing a document's _id and _source fields)
request Request Kuzzle API Request

generic:document:beforeWrite generic events allow to intercept the Request lifecycle before all the actions related to document writing.

Example

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:beforeWrite': async documents => {
        // some random change
        documents[0]._source.foo = 'bar';

        return documents;
      }
    };
  }

}

Associated controller actions:

generic:document:afterWrite

Arguments Type Description
documents Array Array of documents (containing a document _id and _source fields)
request Request Kuzzle API Request

generic:document:afterWrite generic events allow to intercept the request lifecycle after all the actions related to document writing.

Example

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:afterWrite': async documents => {
        // some random change
        documents[0]._source.foo = 'bar';

        return documents;
      }
    };
  }

}

Associated controller actions:

generic:document:beforeUpdate

Arguments Type Description
documents Array Array of documents (containing a document _id and _source fields)
request Request Kuzzle API Request

generic:document:beforeUpdate generic events allow to intercept the Request lifecycle before all the actions related to document updating.

Example

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:beforeUpdate': async documents => {
        // some random change
        documents[0]._source.foo = 'bar';

        return documents;
      }
    };
  }

}

Associated controller actions:

generic:document:afterUpdate

Arguments Type Description
documents Array Array of documents (containing a document _id and _source fields)
request Request Kuzzle API Request

generic:document:afterUpdate generic events allos to intercept the Request lifecycle after all the actions related to document updating.

Example

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:afterUpdate': async documents => {
        // some random change
        documents[0]._source.foo = 'bar';

        return documents;
      }
    };
  }

}

Associated controller actions:

generic:document:beforeDelete

Arguments Type Description
documents Array Array of documents (containing document _id)
request Request Kuzzle API Request

generic:document:beforeDelete generic events allow to intercept the Request lifecycle before all the actions related to document deleting.

Example

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:beforeDelete': async documents => {
        // some random change
        documents[0]._id += 'foo';

        return documents;
      }
    };
  }

}

Associated controller actions:

generic:document:afterDelete

Arguments Type Description
documents Array Array of documents (containing document _id)
request Request Kuzzle API Request

generic:document:afterDelete generic events allow to intercept the Request lifecycle after all the actions related to document deleting.

Example

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:afterDelete': async documents => {
        // some random change
        documents[0]._id += 'foo';

        return documents;
      }
    };
  }

}

Associated controller actions:

generic:document:beforeGet

Arguments Type Description
documents Array Array of documents (containing document _id)
request Request Kuzzle API Request

generic:document:beforeGet generic events allow to intercept the Request liecycle before all the actions related to document getting.

Example

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:beforeGet': async documents => {
        // some random change
        documents[0]._id += 'foo';

        return documents;
      }
    };
  }

}

Associated controller actions:

generic:document:afterGet

Arguments Type Description
documents Array Array of documents (containing document _id)
request Request Kuzzle API Request

generic:document:afterGet generic events allow to intercept the Request lifecycle after all the actions related to document getting.

Example

Copied to clipboard!
class PipePlugin {

  init(customConfig, context) {
    this.pipes = {
      'generic:document:beforeGet': async documents => {
        // some random change
        documents[0]._id += 'foo';

        return documents;
      }
    };
  }

}

Associated controller actions: