Skip to the content
Gridkiln
Menu
Guide contents

Guide Plugins

Writing a plugin

A plugin adds to Gridkiln what it does not do by itself: a connector to a system it cannot read, a step type, a check kind, an output that delivers rows somewhere new, or a workflow action. This page explains what a plugin is, how to write and install one, and how its contributions are used in a pipeline.

What a plugin is#

A plugin is a folder with two things in it:

  • plugin.yaml, the manifest: the plugin’s id, name and version, its entry file, the capabilities it asks for, and what it contributes, each with a title and a JSON Schema for its settings.
  • An ES module (index.mjs, or .js, .mts, .ts) whose default export is definePlugin({ … }) from @gridkiln/plugin-api.
acme-geocoder/
  plugin.yaml
  index.mjs

The app runs each plugin in its own Node process, never inside the app or its engine, with no network, no files beyond its own folder and the tables it is handed, and no other programs, unless the person installing it allows more. A plugin that crashes fails the step that called it, not the app.

What a plugin can contribute#

Contribution The plugin gives In a pipeline it is
Connector read(config, request), and optionally list and schema A source whose location is kind: plugin
Step type compileSql(config, inputs), which stays inspectable in the SQL tab, or transform(config, tables); optionally schema A Plugin step (custom.plugin)
Check kind evaluate(config, table) → pass, warn or fail, with the failing rows A check From a plugin (plugin)
Output kind plan(config, table) and write(config, table, target) An output of kind plugin
Workflow action run(config, run) A workflow step with action: plugin

The manifest can also list template files the plugin ships. It accepts file formats too, but no code can serve them yet, so a plugin cannot add a file format.

A first plugin#

A check that every value of a column is a valid UK VAT number. plugin.yaml:

id: example.vat-check
name: VAT numbers
version: 1.0.0
main: index.mjs
contributes:
  checks:
    - name: vatNumber
      title: Valid UK VAT numbers
      configSchema:
        type: object
        properties:
          column: { type: string, minLength: 1, title: Column }
        required: [column]

index.mjs:

import { definePlugin } from '@gridkiln/plugin-api';

export default definePlugin({
  checks: {
    vatNumber: {
      evaluate(config, table) {
        const failing = [];
        table.rows.forEach((row, i) => {
          if (!/^(GB)?\d{9}$/.test(String(row[config.column] ?? '').replace(/\s+/g, ''))) failing.push(i);
        });
        return {
          status: failing.length === 0 ? 'pass' : 'fail',
          observed: `${failing.length} of ${table.rows.length} values are not valid VAT numbers`,
          failing,
        };
      },
    },
  },
});

gridkiln: plugin and schemaVersion: 1 may be left out of the manifest; they are filled in. The import of @gridkiln/plugin-api always resolves to the app’s own copy, so the folder needs no node_modules for it. The complete version of this plugin, with the real check digits, is fixtures/plugins/vat-check/ in the source code.

Installing a plugin#

  1. Open Settings › Plugins and choose Install plugin….
  2. In Install a plugin, give the Plugin folder, its plugin.yaml, or a .zip file (“The full path. Nothing is installed until you confirm.”) and choose Look at it.
  3. The dialog shows What it adds and What it asks to do. A manifest with problems says so, one sentence per problem: “This plugin cannot be installed”.
  4. Choose Install for: This computer (“Every project on this computer can use it”) or This project, which copies it into the project’s plugins/ folder so it travels with the project.
  5. If the plugin asks for capabilities, tick I trust {name} with this access, then Allow and install. Otherwise Install.

Installing a newer version replaces the old one in one step. Plugins from the gallery install from Install a plugin from the gallery. In Settings › Plugins each plugin shows its version, what it adds, the access it has (confirmed or not), its folder, and whether its process is running, with a switch to turn it on or off, Review and confirm… and Remove….

A project’s plugin that arrives from a colleague (in the project’s plugins/ folder, through a shared folder or git) never runs until someone on this computer confirms it: Review and confirm…. A project that uses a plugin this computer does not have lists it in Settings › Plugins, with Where to get it.

Using a plugin’s contributions#

  • A step: Add step › Plugin step (or “Add step: Plugin step” in the command palette). Its editor takes the settings as JSON: the plugin’s id, the step’s name and its settings.

    { "pluginId": "example.text-tools", "step": "upper", "config": { "column": "Customer" } }
    

    A step that gives compileSql shows its SQL in the SQL tab like any other step.

  • A check: Add check › From a plugin: Plugin (its id), Its check (the name) and Settings as JSON.

  • An output, a connector or a workflow action: the app has no form for these yet. Add them to the project’s documents, which are plain YAML files; the app reads the change within a few seconds:

    # pipelines/<pipeline>.pipeline.yaml, under outputs:
    - id: out_markdown01
      kind: plugin
      from: stp_last000001
      settings: { pluginId: example.markdown, output: markdown, config: { path: /Users/me/Reports/report.md } }
    
    # sources/<source>.source.yaml:
    location: { kind: plugin, pluginId: example.calendar, connector: days, config: {} }
    
    # workflows/<workflow>.workflow.yaml, under nodes:
    - id: nod_stamp00001
      action: plugin
      pluginId: example.stamp
      actionName: stamp
      config: {}
    # and under edges, after the step it follows:
    - { from: nod_deliver001, to: nod_stamp00001 }
    

The settings are checked against the contribution’s JSON Schema before the plugin is called, and refused with the reason when they do not fit.

Sharing a plugin#

Zip the folder (with plugin.yaml at the top of the zip, or in a single folder inside it) and send it, or put it in a project’s plugins/ folder. Give it a homepage in the manifest: a project that needs the plugin shows it to whoever opens the project without it. Raise version with every change, and use requires (such as >=1.0) for the oldest app version it works with.

The examples in the source code#

fixtures/plugins/ holds one plugin of each kind:

Folder Shows
text-tools Two step types: one compiled to SQL, one that runs code. Explained file by file
vat-check A check that names its failing rows
calendar A connector that lists what it can read and declares its columns
markdown-output An output that plans its targets and writes them
stamp-action A workflow action
misbehaving Every way a plugin can break the rules, and what the sandbox does about it