Skip to content

Commit

Permalink
Update stype (added envvars related types)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Dec 19, 2024
1 parent 3a30ee9 commit 285b82c
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 22 deletions.
5 changes: 3 additions & 2 deletions application/apps/indexer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions application/apps/indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ grep-searcher = "0.1"
tempfile = "3.14"
env_logger = "0.11"
walkdir = "2.5"
envvars = "0.1"

## Development Dependencies ##
# Support for `html_reports` needs running the benchmarks via `cargo-criterion` tool.
Expand Down
2 changes: 1 addition & 1 deletion application/apps/indexer/session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ blake3 = "1.5"
crossbeam-channel.workspace = true
dirs.workspace = true
dlt-core = { workspace = true, features = ["statistics"] }
envvars = "0.1"
envvars = { workspace = true }
file-tools = { path = "../addons/file-tools" }
futures.workspace = true
indexer_base = { path = "../indexer_base" }
Expand Down
4 changes: 2 additions & 2 deletions application/apps/indexer/session/src/unbound/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl UnboundSessionAPI {
pub async fn get_shell_profiles(
&self,
id: u64,
) -> Result<stypes::CommandOutcome<String>, stypes::ComputationError> {
) -> Result<stypes::CommandOutcome<stypes::ProfileList>, stypes::ComputationError> {
let (tx_results, rx_results) = oneshot::channel();
self.process_command(id, rx_results, Command::GetShellProfiles(tx_results))
.await
Expand All @@ -175,7 +175,7 @@ impl UnboundSessionAPI {
pub async fn get_context_envvars(
&self,
id: u64,
) -> Result<stypes::CommandOutcome<String>, stypes::ComputationError> {
) -> Result<stypes::CommandOutcome<stypes::MapKeyValue>, stypes::ComputationError> {
let (tx_results, rx_results) = oneshot::channel();
self.process_command(id, rx_results, Command::GetContextEnvvars(tx_results))
.await
Expand Down
8 changes: 6 additions & 2 deletions application/apps/indexer/session/src/unbound/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ pub enum Command {
oneshot::Sender<Result<stypes::CommandOutcome<String>, stypes::ComputationError>>,
),
GetShellProfiles(
oneshot::Sender<Result<stypes::CommandOutcome<String>, stypes::ComputationError>>,
oneshot::Sender<
Result<stypes::CommandOutcome<stypes::ProfileList>, stypes::ComputationError>,
>,
),
GetContextEnvvars(
oneshot::Sender<Result<stypes::CommandOutcome<String>, stypes::ComputationError>>,
oneshot::Sender<
Result<stypes::CommandOutcome<stypes::MapKeyValue>, stypes::ComputationError>,
>,
),
SerialPortsList(
oneshot::Sender<
Expand Down
17 changes: 6 additions & 11 deletions application/apps/indexer/session/src/unbound/commands/shells.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
use crate::unbound::signal::Signal;
use envvars;
use serde_json;

pub fn get_valid_profiles(
_signal: Signal,
) -> Result<stypes::CommandOutcome<String>, stypes::ComputationError> {
) -> Result<stypes::CommandOutcome<stypes::ProfileList>, stypes::ComputationError> {
let mut profiles = envvars::get_profiles()
.map_err(|e| stypes::ComputationError::IoOperation(e.to_string()))?;
for profile in &mut profiles {
if let Err(e) = profile.load() {
log::warn!("Fail to load envvars for \"{}\": {e}", profile.name);
}
}
Ok(stypes::CommandOutcome::Finished(
serde_json::to_string(&profiles)
.map_err(|e| stypes::ComputationError::IoOperation(e.to_string()))?,
))
Ok(stypes::CommandOutcome::Finished(stypes::ProfileList(
profiles.into_iter().map(|p| p.into()).collect(),
)))
}

pub fn get_context_envvars(
_signal: Signal,
) -> Result<stypes::CommandOutcome<String>, stypes::ComputationError> {
) -> Result<stypes::CommandOutcome<stypes::MapKeyValue>, stypes::ComputationError> {
let envvars = envvars::get_context_envvars()
.map_err(|e| stypes::ComputationError::IoOperation(e.to_string()))?;
Ok(stypes::CommandOutcome::Finished(
serde_json::to_string(&envvars)
.map_err(|e| stypes::ComputationError::IoOperation(e.to_string()))?,
))
Ok(stypes::CommandOutcome::Finished(envvars.into()))
}
6 changes: 4 additions & 2 deletions application/apps/indexer/stypes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ edition = "2021"
rustcore = [
"tokio",
"walkdir",
"regex"
"regex",
"envvars"
]
nodejs = [
"node-bindgen"
Expand All @@ -24,7 +25,8 @@ uuid = { workspace = true, features = ["serde"] }
tokio = { workspace = true, optional = true }
node-bindgen = { git = "https://github.com/infinyon/node-bindgen.git", branch="master", optional = true}
thiserror.workspace = true
walkdir = { workspace = true , optional = true}
walkdir = { workspace = true, optional = true }
envvars = { workspace = true, optional = true }

[dev-dependencies]
tokio = { workspace = true }
Expand Down
37 changes: 37 additions & 0 deletions application/apps/indexer/stypes/bindings/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export type CommandOutcomeFoldersScanningResult = { "Finished": FoldersScanningR
*/
export type CommandOutcomeOptionalString = { "Finished": string | null } | "Cancelled";

/**
* Represents the result of a command execution.
* At the core level, this type is used for all commands invoked within an `UnboundSession`.
* It is only used to indicate the successful completion or interruption of a command.
*/
export type CommandOutcomeProfilesResult = { "Finished": ProfileList } | "Cancelled";

/**
* Represents the result of a command execution.
* At the core level, this type is used for all commands invoked within an `UnboundSession`.
Expand Down Expand Up @@ -113,6 +120,36 @@ list: Array<FolderEntity>,
*/
max_len_reached: boolean, };

export type Profile = {
/**
* Suggested name of shell. For unix based systems it will be name of executable file,
* like "bash", "fish" etc. For windows it will be names like "GitBash", "PowerShell"
* etc.
*/
name: string,
/**
* Path to executable file of shell
*/
path: string,
/**
* List of environment variables. Because extracting operation could take some time
* by default `envvars = None`. To load data should be used method `load`, which will
* make attempt to detect environment variables.
*/
envvars: Map<string, string>,
/**
* true - if path to executable file of shell is symlink to another location.
*/
symlink: boolean, };

/**
* Represents a list of serial ports.
*
* This structure contains a vector of strings, where each string represents the name
* or identifier of a serial port available on the system.
*/
export type ProfileList = Array<Profile>;

/**
* Represents a list of serial ports.
*
Expand Down
2 changes: 2 additions & 0 deletions application/apps/indexer/stypes/bindings/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ nature: number, };
*/
export type GrabbedElementList = Array<GrabbedElement>;

export type MapKeyValue = { [key in string]?: string };

/**
* Representation of ranges. We cannot use std ranges as soon as no way
* to derive Serialize, Deserialize
Expand Down
2 changes: 2 additions & 0 deletions application/apps/indexer/stypes/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ mod proptest;
mod ts;

mod folders;
mod profiles;
mod serial;

pub use folders::*;
pub use profiles::*;
pub use serial::*;

use crate::*;
Expand Down
2 changes: 2 additions & 0 deletions application/apps/indexer/stypes/src/command/nodejs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::*;

try_into_js!(CommandOutcome<FoldersScanningResult>);
try_into_js!(CommandOutcome<SerialPortsList>);
try_into_js!(CommandOutcome<ProfileList>);
try_into_js!(CommandOutcome<MapKeyValue>);
try_into_js!(CommandOutcome<()>);
try_into_js!(CommandOutcome<i64>);
try_into_js!(CommandOutcome<Option<String>>);
Expand Down
13 changes: 13 additions & 0 deletions application/apps/indexer/stypes/src/command/profiles/converting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::*;

/// Converts a `envvars::Profile` into an `Profile`.
impl From<envvars::Profile> for Profile {
fn from(pro: envvars::Profile) -> Self {
Profile {
name: pro.name,
path: pro.path,
envvars: pro.envvars,
symlink: pro.symlink,
}
}
}
32 changes: 32 additions & 0 deletions application/apps/indexer/stypes/src/command/profiles/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[cfg(feature = "rustcore")]
mod converting;

use crate::*;

#[derive(Clone, Serialize, Deserialize, Debug)]
#[extend::encode_decode]
#[cfg_attr(test, derive(TS), ts(export, export_to = "command.ts"))]
pub struct Profile {
/// Suggested name of shell. For unix based systems it will be name of executable file,
/// like "bash", "fish" etc. For windows it will be names like "GitBash", "PowerShell"
/// etc.
pub name: String,
/// Path to executable file of shell
pub path: PathBuf,
/// List of environment variables. Because extracting operation could take some time
/// by default `envvars = None`. To load data should be used method `load`, which will
/// make attempt to detect environment variables.
#[cfg_attr(test, ts(type = "Map<string, string>"))]
pub envvars: Option<HashMap<String, String>>,
/// true - if path to executable file of shell is symlink to another location.
pub symlink: bool,
}

/// Represents a list of serial ports.
///
/// This structure contains a vector of strings, where each string represents the name
/// or identifier of a serial port available on the system.
#[derive(Clone, Serialize, Deserialize, Debug)]
#[extend::encode_decode]
#[cfg_attr(test, derive(TS), ts(export, export_to = "command.ts"))]
pub struct ProfileList(pub Vec<Profile>);
12 changes: 12 additions & 0 deletions application/apps/indexer/stypes/src/command/ts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
use crate::*;

/// Represents the result of a command execution.
/// At the core level, this type is used for all commands invoked within an `UnboundSession`.
/// It is only used to indicate the successful completion or interruption of a command.
#[derive(Clone, Serialize, Deserialize, Debug)]
#[cfg_attr(test, derive(TS), ts(export, export_to = "command.ts"))]
pub enum CommandOutcomeProfilesResult {
/// Indicates that the command was successfully completed.
Finished(ProfileList),
/// Indicates that the command execution was interrupted.
Cancelled,
}

/// Represents the result of a command execution.
/// At the core level, this type is used for all commands invoked within an `UnboundSession`.
/// It is only used to indicate the successful completion or interruption of a command.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use crate::*;
use std::ops::RangeInclusive;

impl From<HashMap<String, String>> for MapKeyValue {
fn from(map: HashMap<String, String>) -> Self {
MapKeyValue(map)
}
}

impl From<Vec<GrabbedElement>> for GrabbedElementList {
/// Converts a `Vec<GrabbedElement>` into a `GrabbedElementList`.
///
Expand Down
5 changes: 5 additions & 0 deletions application/apps/indexer/stypes/src/miscellaneous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ mod proptest;

use crate::*;

#[derive(Clone, Serialize, Deserialize, Debug)]
#[extend::encode_decode]
#[cfg_attr(test, derive(TS), ts(export, export_to = "miscellaneous.ts"))]
pub struct MapKeyValue(pub HashMap<String, String>);

/// Representation of ranges. We cannot use std ranges as soon as no way
/// to derive Serialize, Deserialize
#[derive(Clone, Serialize, Deserialize, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions application/apps/protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ gen_encode_decode_fns!(ObserveOrigin);
gen_encode_decode_fns!(FoldersScanningResult);
gen_encode_decode_fns!(CommandOutcome<FoldersScanningResult>);
gen_encode_decode_fns!(CommandOutcome<SerialPortsList>);
gen_encode_decode_fns!(CommandOutcome<ProfileList>);
gen_encode_decode_fns!(CommandOutcome<MapKeyValue>);
gen_encode_decode_fns!(CommandOutcome<()>);
gen_encode_decode_fns!(CommandOutcome<i64>);
gen_encode_decode_fns!(CommandOutcome<Option<String>>);
Expand Down
1 change: 1 addition & 0 deletions application/apps/rustcore/rs-bindings/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions application/apps/rustcore/rs-bindings/src/js/jobs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl UnboundJobs {
async fn get_shell_profiles(
&self,
id: i64,
) -> Result<stypes::CommandOutcome<String>, stypes::ComputationError> {
) -> Result<stypes::CommandOutcome<stypes::ProfileList>, stypes::ComputationError> {
self.api
.as_ref()
.ok_or(stypes::ComputationError::SessionUnavailable)?
Expand All @@ -187,7 +187,7 @@ impl UnboundJobs {
async fn get_context_envvars(
&self,
id: i64,
) -> Result<stypes::CommandOutcome<String>, stypes::ComputationError> {
) -> Result<stypes::CommandOutcome<stypes::MapKeyValue>, stypes::ComputationError> {
self.api
.as_ref()
.ok_or(stypes::ComputationError::SessionUnavailable)?
Expand Down

0 comments on commit 285b82c

Please sign in to comment.