|
1 | 1 | import { PluginAspect } from "./plugin-aspect";
|
2 | 2 |
|
| 3 | +/** |
| 4 | + * The common interface definiton that plugin classes can use to inherit from |
| 5 | + * when defining their own options interface for their constructors. |
| 6 | + * |
| 7 | + * Not all plugins need to have a unique plugin ID, so if the plugin you are |
| 8 | + * working does not, it is okay to provide a dummy implementation, but it is |
| 9 | + * not really recommended. Instead the constructor of your plugin should |
| 10 | + * generate one automatically at runtime if you definitely do not want the |
| 11 | + * caller of your plugin class to have to provide an instanceID. |
| 12 | + * |
| 13 | + * For example if you have a ledger called `FooBar` then this could be seen as |
| 14 | + * a recommended implementation: |
| 15 | + * |
| 16 | + * ```typescript |
| 17 | + * |
| 18 | + * interface IPluginLedgerConnectorFooBarOptions extends ICactusPluginOptions { |
| 19 | + * logLevel?: LogLevelDesc; |
| 20 | + * // your other FooBar specific parameters here |
| 21 | + * } |
| 22 | + * |
| 23 | + * class PluginLedgerConnectorFooBar implements ICactusPlugin { |
| 24 | + * constructor(public readonly options: IPluginLedgerConnectorFooBarOptions) { |
| 25 | + * // your constructor logic here |
| 26 | + * } |
| 27 | + * |
| 28 | + * public getInstanceId(): string { |
| 29 | + * // this works because your {IPluginLedgerConnectorFooBarOptions} |
| 30 | + * // inherits from the ICactusPluginOptions interface. |
| 31 | + * return this.options.instanceId; |
| 32 | + * } |
| 33 | + * ``` |
| 34 | + * |
| 35 | + */ |
| 36 | +export interface ICactusPluginOptions { |
| 37 | + instanceId: string; |
| 38 | +} |
| 39 | + |
3 | 40 | /**
|
4 | 41 | * This is the common base for all other plugin interface definitions to have as a parent.
|
5 | 42 | */
|
6 | 43 | export interface ICactusPlugin {
|
| 44 | + /** |
| 45 | + * Returns a string that uniquely identifies the specific instance of a plugin |
| 46 | + * from other instances that may have been created from the exact same class. |
| 47 | + * We need this to cover scenarios where identical plugin implementations |
| 48 | + * need to be used because for example you have two different deployments of |
| 49 | + * the same kind of ledger, leading to you needing two separate instances of |
| 50 | + * the same kind of plugin in the plugin registry as well. |
| 51 | + * |
| 52 | + * @see {ICactusPluginOptions} For further details relevant to the instanceId |
| 53 | + */ |
| 54 | + getInstanceId(): string; |
| 55 | + |
7 | 56 | /**
|
8 | 57 | * Returns the NodeJS/npm package name of the plugin which is used to identify
|
9 | 58 | * plugin instances at runtime and differentiate them from other types of plugins.
|
|
0 commit comments