Skip to content

Commit

Permalink
Plugins: Finish integrating plugin in system (prototyping)
Browse files Browse the repository at this point in the history
* Parser plugins for commands is working directly from chipmunk without
  any workaround.
* Change configurations of plugins in the front-end to make it
  compatible with rust types. This change include delivering the plugin
  binary path instead its directory and change naming to snake case
* Ignore general setting of plugins on rust side temporally.
  • Loading branch information
AmmarAbouZor committed Dec 19, 2024
1 parent e641021 commit e121414
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
5 changes: 4 additions & 1 deletion application/apps/indexer/sources/src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PluginParserSettings {
pub plugin_path: PathBuf,
//TODO AAZ: Temp solution.
//Check if Default implementation should be removed on General Setting once this temp is done.
#[serde(default)]
pub general_settings: PluginParserGeneralSettings,
pub plugin_configs: Vec<ConfigItem>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
/// General settings for all parsers as plugins
pub struct PluginParserGeneralSettings {
pub placeholder: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export class State extends Base {
return;
}

const item = conf.configuration.pluginConfigs.find((item) => item.id === id);
const item = conf.configuration.plugin_configs.find((item) => item.id === id);
if (item !== undefined) {
item.value = value;
} else {
conf.configuration.pluginConfigs.push({ id, value });
conf.configuration.plugin_configs.push({ id, value });
}
}

Expand All @@ -61,10 +61,12 @@ export class State extends Base {
return;
}

if (conf.configuration.pluginDirPath !== this.selectedParser?.dir_path) {
conf.configuration.pluginDirPath = this.selectedParser?.dir_path ?? '';
const pluginPath = this.selectedParser?.state.Active?.wasm_file_path ?? '';

if (conf.configuration.plugin_path !== pluginPath) {
conf.configuration.plugin_path = pluginPath;
// Clear configurations on plugin change.
conf.configuration.pluginConfigs = [];
conf.configuration.plugin_configs = [];
}
}

Expand Down
22 changes: 12 additions & 10 deletions application/platform/types/observe/parser/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import * as Files from '../../types/file';
import { ConfigItem, ConfigValue } from '../../../../types/plugins';

export interface IConfiguration {
pluginDirPath: string;
pluginConfigs: ConfigItem[];
plugin_path: string;
plugin_configs: ConfigItem[];
}

@Statics<ConfigurationStaticDesc<IConfiguration, Protocol>>()
Expand All @@ -36,11 +36,13 @@ export class Configuration

static validate(configuration: IConfiguration): Error | IConfiguration {
try {
const dirPath = obj.getAsString(configuration, 'pluginDirPath');
if (dirPath.length == 0) {
return Error('No Plugin Parser is selected.');
const pluginPath = obj.getAsString(configuration, 'plugin_path');
if (pluginPath.length == 0) {
return Error('No Valid Plugin Parser is selected.');
}
const arr = obj.getAsArray(configuration, 'pluginConfigs');

obj.getAsArray(configuration, 'plugin_configs');

return configuration;
} catch (e) {
return new Error(error(e));
Expand All @@ -50,8 +52,8 @@ export class Configuration
// Gives initial settings. Not necessarily valid.
static initial(): IConfiguration {
return {
pluginDirPath: '',
pluginConfigs: [],
plugin_path: '',
plugin_configs: [],
};
}

Expand Down Expand Up @@ -80,9 +82,9 @@ export class Configuration
}

public override hash(): number {
const configs = this.configuration.pluginConfigs.map(
const configs = this.configuration.plugin_configs.map(
(item) => `${item.id}:${this.getConfigVal(item.value)}`,
);
return str.hash(`${this.configuration.pluginDirPath}; ${configs.join(';')}`);
return str.hash(`${this.configuration.plugin_path}; ${configs.join(';')}`);
}
}

0 comments on commit e121414

Please sign in to comment.