Core
Write Plugins v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

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.

class PipePlugin {

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

        return documents;
      }
    };
  }

}

generic:document:beforeWrite #

ArgumentsTypeDescription
documentsArrayArray of documents (containing a document's _id and _source fields)
requestRequestKuzzle API Request

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

Example #

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 #

ArgumentsTypeDescription
documentsArrayArray of documents (containing a document _id and _source fields)
requestRequestKuzzle API Request

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

Example #

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 #

ArgumentsTypeDescription
documentsArrayArray of documents (containing a document _id and _source fields)
requestRequestKuzzle API Request

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

Example #

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 #

ArgumentsTypeDescription
documentsArrayArray of documents (containing a document _id and _source fields)
requestRequestKuzzle API Request

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

Example #

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 #

ArgumentsTypeDescription
documentsArrayArray of documents (containing document _id)
requestRequestKuzzle API Request

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

Example #

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 #

ArgumentsTypeDescription
documentsArrayArray of documents (containing document _id)
requestRequestKuzzle API Request

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

Example #

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 #

ArgumentsTypeDescription
documentsArrayArray of documents (containing document _id)
requestRequestKuzzle API Request

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

Example #

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 #

ArgumentsTypeDescription
documentsArrayArray of documents (containing document _id)
requestRequestKuzzle API Request

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

Example #

class PipePlugin {

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

        return documents;
      }
    };
  }

}

Associated controller actions: #