|
| 1 | +# Plugin Schema |
| 2 | + |
| 3 | +- Authors: Ben Sherman |
| 4 | +- Status: accepted |
| 5 | +- Deciders: Ben Sherman, Paolo Di Tommaso |
| 6 | +- Date: 2025-09-22 |
| 7 | +- Tags: plugins |
| 8 | + |
| 9 | +## Summary |
| 10 | + |
| 11 | +Provide a way for external systems to understand key information about third-party plugins. |
| 12 | + |
| 13 | +## Problem Statement |
| 14 | + |
| 15 | +Nextflow plugins need a way to statically declare extensions to the Nextflow language so that external systems can extract information about a plugin without loading it in the JVM. |
| 16 | + |
| 17 | +Primary use cases: |
| 18 | + |
| 19 | +- The Nextflow language server needs to know about any config scopes, custom functions, etc, defined by a plugin, in order to recognize them in Nextflow scripts and config files |
| 20 | + |
| 21 | +- The Nextflow plugin registry (or other user interfaces) can use this information to provide API documentation. |
| 22 | + |
| 23 | +## Goals or Decision Drivers |
| 24 | + |
| 25 | +- External systems (e.g. language server) need to be able to understand plugins without having to load them in the JVM. |
| 26 | + |
| 27 | +## Non-goals |
| 28 | + |
| 29 | +- Defining the schema for the core runtime and core plugins: these definitions are handled separately, although they may reuse some of the structures used for plugin schemas. |
| 30 | + |
| 31 | +## Considered Options |
| 32 | + |
| 33 | +### Nextflow plugin system |
| 34 | + |
| 35 | +Require external systems to use Nextflow's plugin system to load plugins at runtime in order to extract information about them. |
| 36 | + |
| 37 | +- **Pro:** Allows any information to be extracted since the entire plugin is loaded |
| 38 | + |
| 39 | +- **Con:** Requires the entire Nextflow plugin system to be reused or reimplemented. Not ideal for Java applications since the plugin system is implemented in Groovy, incompatible with non-JVM applications |
| 40 | + |
| 41 | +- **Con:** Requires plugins to be downloaded, cached, loaded in the JVM, even though there is no need to use the plugin. |
| 42 | + |
| 43 | +### Plugin schema |
| 44 | + |
| 45 | +Define a plugin schema for every plugin release which is stored and served by the plugin registry as JSON. |
| 46 | + |
| 47 | +- **Pro:** Allows any system to access plugin definitions through a standard JSON format. Does not require downloading plugins or loading them into a JVM. |
| 48 | + |
| 49 | +- **Con:** Requires the plugin schema to be generated at build-time and stored in the plugin registry. |
| 50 | + |
| 51 | +- **Con:** Requires a standard JSON format across all versions of Nextflow, the language server, and third-party plugins. |
| 52 | + |
| 53 | +## Solution |
| 54 | + |
| 55 | +Define a plugin schema for every plugin release which is stored and served by the plugin registry as JSON. |
| 56 | + |
| 57 | +- Plugin developers only need to define [extension points](https://nextflow.io/docs/latest/plugins/developing-plugins.html#extension-points) as usual, and the Gradle plugin will extract the plugin schema and store it in the plugin registry as part of each plugin release. |
| 58 | + |
| 59 | +- The language server can retrieve plugin schemas based on the `plugins` block in a config file. |
| 60 | + |
| 61 | +A plugin schema consists of a list of *definitions*. Each definition has a *type* and a *spec*. |
| 62 | + |
| 63 | +Example: |
| 64 | + |
| 65 | +```json |
| 66 | +[ |
| 67 | + { |
| 68 | + "type": "ConfigScope", |
| 69 | + "spec": { |
| 70 | + // ... |
| 71 | + } |
| 72 | + }, |
| 73 | + { |
| 74 | + "type": "Function", |
| 75 | + "spec": { |
| 76 | + // ... |
| 77 | + } |
| 78 | + }, |
| 79 | +] |
| 80 | +``` |
| 81 | + |
| 82 | +The following types of definitions are allowed: |
| 83 | + |
| 84 | +**ConfigScope** |
| 85 | + |
| 86 | +Defines a top-level config scope. The spec consists of a *name*, an optional *description*, and *children*. |
| 87 | + |
| 88 | +The children should be a mapping of names to schemas, where each name denotes a nested config scope or option. The following nested schemas are allowed: |
| 89 | + |
| 90 | +- **ConfigOption**: Defines a config option. The spec consists of a *description* and *type*. |
| 91 | + |
| 92 | +- **ConfigScope**: Defines a nested config scope, using the same schema as for top-level scopes. |
| 93 | + |
| 94 | +Example: |
| 95 | + |
| 96 | +```json |
| 97 | +{ |
| 98 | + "type": "ConfigScope", |
| 99 | + "spec": { |
| 100 | + "name": "hello", |
| 101 | + "description": "The `hello` scope controls the behavior of the `nf-hello` plugin.", |
| 102 | + "children": { |
| 103 | + "message": { |
| 104 | + "type": "ConfigOption", |
| 105 | + "spec": { |
| 106 | + "description": "Message to print to standard output when the plugin is enabled.", |
| 107 | + "type": "String" |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | +``` |
| 114 | + |
| 115 | +**Factory** |
| 116 | + |
| 117 | +Defines a channel factory that can be included in Nextflow scripts. The spec is the same as for functions. |
| 118 | + |
| 119 | +**Function** |
| 120 | + |
| 121 | +Defines a function that can be included in Nextflow scripts. The spec consists of a *name*, an optional *description*, a *return type*, and a list of *parameters*. Each parameter consists of a *name* and a *type*. |
| 122 | + |
| 123 | +Example: |
| 124 | + |
| 125 | +```json |
| 126 | +{ |
| 127 | + "type": "Function", |
| 128 | + "spec": { |
| 129 | + "name": "sayHello", |
| 130 | + "description": "Say hello to the given target", |
| 131 | + "returnType": "void", |
| 132 | + "parameters": [ |
| 133 | + { |
| 134 | + "name": "target", |
| 135 | + "type": "String" |
| 136 | + } |
| 137 | + ] |
| 138 | + } |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +**Operator** |
| 143 | + |
| 144 | +Defines a channel operator that can be included in Nextflow scripts. The spec is the same as for functions. |
| 145 | + |
| 146 | +## Rationale & discussion |
| 147 | + |
| 148 | +Now that there is a Gradle plugin for building Nextflow plugins, as well as a registry to publish and retrieve plugins, the generation and retrieval of plugin schemas can be implemented in a way that is transparent to plugin developers. |
| 149 | + |
| 150 | +The primary challenge is to ensure that the schema of the plugin schema (i.e. the meta-schema) remains consistent across Nextflow versions, or is versioned so that external systems can understand multiple versions over time as needed. |
0 commit comments