Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@agrarium/plugin

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agrarium/plugin

Base API for Agrarium plugins

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

Agrarium Plugin

Base class for plugins implementations. Every plugin is the simple JS class wich needs to provide some public interface for Agrarium.

Public interface

Both methods gather and seed have the same signature but they have a diffrent time of execution.

gather?: (component: IComponent, context: IContext) => IComponentDataPart

It's async method wich returns simple object any mined data in keys. This method works in parallel in all chunks. Also, order of this method executions in different plugins not garanted.

Example:

const { Plugin } = require('agrarium');
const FormData = require('form-data');

// Fetching data by http request
class MyPlugin extends Plugin {
    async gather({ key }) {
        const form = new FormData();
        form.append('component', key);
        return {
            my: await got.post('myApiWithComponentsInfo.ru', {
                body: form
            })
        };
    }
}

seed?: (component: IComponent, context: IContext) => ISeedResult

It's also async method wich returns simple object any mined data in keys. This method works before main stream of the gather methods and you can use this information in the any gather method of any plugin. Also, order of this method executions in different plugins not garanted.

Example:

const { Plugin } = require('agrarium');

// Collectiong components names
class MyPlugin extends Plugin {
    async seed({ key }, context) {
        return {
            components: context.components ?
                [].concat(context.components, component.key) :
                [component.key]
        };
    }
}

Private interface

It's set of helpers for better plugins writing experience.

readFile?: (options: IReadFileOptions) => Promise<fileSource>

Simple helper for reading files from fs with cache.

walkSources?: (options: IWalkSourcesOptions, cb: (result: IWalkSourcesResult) => void) => void

Iterator for files and thier sources.

License MIT

FAQs

Package last updated on 02 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc