Write your own

Each plugin is nothing more than an async function that can perform customizations at either agent level, collection level, or both.

export async function removeTimestamps(dataSource, collection, options) {
  // ... call customization methods here
}

Three parameters are provided:

Name
Description

dataSource (api-reference ↗)

An object that allows customizing the whole agent. It has the same interface than the Agent you manipulate outside of plugins

collection (api-reference ↗)

An object that allows customizing the collection that the plugin was called from (null if the plugin was called on the agent). It is the same object than is passed when you call customizeCollection

options

Options which are provided to the plugin. There is no set structure for this parameter, as each plugin can use different options.

Making your plugin act differently depending on the collection

When making a plugin, you may want it to generalize to many different collections.

This can be achieved by adopting different behavior depending on the schema of the collection which is being targeted.

Relevant documentation:

export async function removeTimestamps(dataSource, collection, options) {
  for (const currentCollection of dataSource.collections) {
    if (currentCollection.schema.fields.createdAt) {
      currentCollection.removeField('createdAt');
    }

    if (currentCollection.schema.fields.updatedAt) {
      currentCollection.removeField('updatedAt');
    }
  }
}

Last updated

Revision created

docs(datasource-sql): document introspection process