Skip to content

godspeedsystems/gs-plugins

Repository files navigation

Godspeed

Godspeed

Open Source Plugins Development Ecosystem

contributions welcome Discord


Godspeed Plug-in 🔗

Godspeed Plugins are the way to extend the core godspeed framework. Currently we support adding Event Source and Data Source as plugin.

A brief description of how we write new plug-in in godspeed framework.

Steps to create new plug-in in our godspeed framework:

Certainly, here are the provided steps rephrased:

  1. Begin by installing the godspeed-plugin-generator globally using the following commands:

    npm install -g generator-godspeed-plugin
    npm install -g yo
  2. To initiate the creation of your plugin, execute the following command in your terminal:

    yo godspeed-plugin
  3. After running the above command, you'll be prompted to enter your desired plugin name. Proceed by typing it in:

    ? Enter your plugin name: (your-plugin-name)
  4. Select the type of plugin that aligns with your project's requirements. You can choose from the following options:

    ? Select the type of plugin: (Use arrow keys)
    ❯ DataSource 
      EventSource 
      DataSource-As-EventSource 
  5. Depending on your selection, the plugin generator will generate a template with your chosen plugin name, such as "your-plugin-name-as-datasource." The structure of the generated files will be as follows:

    .
    ├── src
    |   └── index.ts
    |
    ├── package.json
    |
    ├── README.md
    |
    ├── tsconfig.json
    |
    ├── .gitignore
    |
    └── .npmignore
    
  6. To customize your plugin, navigate to the index.ts file located in the src directory. You can modify the content within this file to meet your specific plugin requirements. There's no need to make changes to any other files outside of index.ts.

If you opt for DataSource, the index.ts file appears as follows:


  import { GSContext,  GSDataSource, GSStatus, PlainObject,} from "@godspeedsystems/core";

  export default class DataSource extends GSDataSource {
  protected async initClient(): Promise<object> {
      try {
        // initialize your client
      } catch (error) {
      throw error;
      }
  }

  async execute(ctx: GSContext, args: PlainObject): Promise<any> {
      
      try {
        // execute methods
        
      } catch (error) {
        throw error;
      }
  }
  }
  const SourceType = 'DS';
  const Type = "y"; // this is the loader file of the plugin, So the final loader file will be `types/${Type.js}`
  const CONFIG_FILE_NAME = "y"; // in case of event source, this also works as event identifier, and in case of datasource works as datasource name
  const DEFAULT_CONFIG = {};

  export {
    DataSource,
    SourceType,
    Type,
    CONFIG_FILE_NAME,
    DEFAULT_CONFIG
  }

If you opt for EventSource, the index.ts file appears as follows:

  import { PlainObject, GSActor, GSCloudEvent, GSStatus, GSEventSource, GSDataSource, GSContext } from "@godspeedsystems/core";


  class EventSource extends GSEventSource {

  protected initClient(): Promise<PlainObject> {
      // initialize your client
  }
  async subscribeToEvent(eventRoute: string, eventConfig: PlainObject, processEvent: (event: GSCloudEvent, eventConfig: PlainObject) => Promise<GSStatus>): Promise<void> {
      try {
        //  subscribeToEvent
        
      } catch (error) {
        throw error;
      }
  }
  }

  const SourceType = 'ES';
  const Type = "p"; // this is the loader file of the plugin, So the final loader file will be `types/${Type.js}`
  const CONFIG_FILE_NAME = "p"; // in case of event source, this also works as event identifier, and in case of datasource works as datasource name
  const DEFAULT_CONFIG = {};

  export {
    EventSource,
    SourceType,
    Type,
    CONFIG_FILE_NAME,
    DEFAULT_CONFIG
  }

If you opt for DataSource-As-EventSource , the index.ts file appears as follows:


  import { GSContext, GSDataSource, PlainObject, GSDataSourceAsEventSource, GSCloudEvent, GSStatus, GSActor} from "@godspeedsystems/core";

  class DataSource extends GSDataSource {
    protected async initClient(): Promise<PlainObject> {
      try {
        
        // initialize your client
      } catch (error) {
        throw error;
      }

    }

    async execute(ctx: GSContext, args: PlainObject): Promise<any> {
      try {
        // execute methods
        
      } catch (error) {
        throw error;
      }
    }
  }

  class EventSource extends GSDataSourceAsEventSource {
    async subscribeToEvent(
      eventKey: string,
      eventConfig: PlainObject,
      processEvent: (
        event: GSCloudEvent,
        eventConfig: PlainObject
      ) => Promise<GSStatus>
    ): Promise<void> {

      //  subscribeToEvent
    }
  }
  const SourceType = 'BOTH';
  const Type = "shirisha"; // this is the loader file of the plugin, So the final loader file will be `types/${Type.js}`
  const CONFIG_FILE_NAME = "shirisha"; // in case of event source, this also works as event identifier, and in case of datasource works as datasource name
  const DEFAULT_CONFIG = {};

  export {
    DataSource,
    EventSource,
    SourceType,
    Type,
    CONFIG_FILE_NAME,
    DEFAULT_CONFIG
  }
  1. For better understanding checkout Examples.

    AWS (DataSource)

    CRON (EventSource)

    KAFKA (DataSource-As-EventSource)

  2. Watch the below videos on

a. How to create plugins using Godspeed framework Part 1 | Godspeed part 1

b.Create and use plugins using Godspeed framework Part 2| Godspeed part 2

List of Plugins

No Plugin Name Type npm package link Documentation Maintained by
1 Express Eventsource npm readme Godspeed
2 Prisma Datasource npm readme Godspeed
3 Apache Kafka DS & ES npm readme Godspeed
4 CRON Eventsource Eventsource npm readme Godspeed
5 Amazon S3 Datasource npm readme Godspeed
6 Excel Datasource npm readme Godspeed
7 Redis Datasource npm readme Godspeed
8 Mailer Datasource npm readme Godspeed
9 Axios Datasource npm readme Godspeed
10 Fastify Eventsource npm readme Godspeed
11 Apollo GraphQL Eventsource npm readme Godspeed