Skip to content

Commit 5adcc5e

Browse files
refactor(Common): Simplify effect dependencies by requiring capabilities directly
- Updated `ActionEffect` to require specific capabilities (e.g., `Arc<dyn CommandExecutor>`) instead of the full runtime - Removed generic `TRunTime` parameter from all effect functions - Simplified effect implementations by directly using required capabilities - Updated `ApplicationRunTime` trait to work with capability-based effects - Adjusted build configuration to set `target-dir` and optimize release builds - Improved artifact management by updating `.gitattributes` and `.gitignore` This change enhances modularity by making effect dependencies explicit and minimal, aligning with Land's capability-based architecture. It also streamlines build artifact handling by excluding generated TypeScript files while keeping compiled Rust libraries.
1 parent 31006e9 commit 5adcc5e

File tree

105 files changed

+344
-1094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+344
-1094
lines changed

.cargo/config.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[build]
2+
target-dir = "Target"
3+
4+
[cargo-new]
5+
vcs = "git"
6+
7+
[profile.release]
8+
opt-level = 3
9+
codegen-units = 1
10+
debug = false
11+
lto = true
12+
panic = "abort"
13+
strip = true

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Target/debug/libCommon.rlib filter=lfs diff=lfs merge=lfs -text
2+
Target/release/libCommon.rlib filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
/target
1+
/Target/*
2+
3+
!/Target/debug
4+
!/Target/release
5+
!/Target/x86_64-pc-windows-msvc
6+
7+
/Target/debug/*
8+
/Target/release/*
9+
/Target/x86_64-pc-windows-msvc/*
10+
11+
!/Target/debug/libCommon.rlib
12+
13+
!/Target/release/libCommon.rlib
14+
15+
!/Target/x86_64-pc-windows-msvc/libCommon.rlib

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-dependencies]
2-
serde = { version = "1.0.219", features = ["derive"] }
3-
toml = { version = "0.8.20" }
2+
serde = { workspace = true }
3+
toml = { workspace = true }
44

55
[dependencies]
66
async-trait = { workspace = true }
@@ -9,7 +9,6 @@ serde_json = { workspace = true }
99
thiserror.workspace = true
1010
url = { workspace = true }
1111

12-
1312
[features]
1413
default = []
1514

Source/Command/ExecuteCommand.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@ use std::sync::Arc;
77
use serde_json::Value;
88

99
use super::CommandExecutor::CommandExecutor;
10-
use crate::{
11-
Effect::{ActionEffect::ActionEffect, ApplicationRunTime::ApplicationRunTime},
12-
Environment::Requires::Requires,
13-
Error::CommonError::CommonError,
14-
};
10+
use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
1511

1612
/// Creates an effect that, when executed, will run a command by its unique
1713
/// identifier.
1814
///
1915
/// It uses the `CommandExecutor` capability from the environment to dispatch
2016
/// the command to the appropriate handler, whether that handler is a native
21-
2217
/// Rust function or a proxied function in an external sidecar process.
2318
///
2419
/// # Parameters
@@ -33,19 +28,13 @@ use crate::{
3328
/// An `ActionEffect` that resolves with the command's return value as a
3429
/// `serde_json::Value`, or a `CommonError` if the command is not found or fails
3530
/// during execution.
36-
pub fn ExecuteCommand<TRunTime>(
31+
pub fn ExecuteCommand(
3732
CommandIdentifier:String,
3833
Argument:Value,
39-
) -> ActionEffect<Arc<TRunTime>, CommonError, Value>
40-
where
41-
TRunTime: ApplicationRunTime + Send + Sync + 'static,
42-
TRunTime: Requires<Arc<dyn CommandExecutor>>, {
43-
ActionEffect::New(Arc::new(move |RunTime:Arc<TRunTime>| {
34+
) -> ActionEffect<Arc<dyn CommandExecutor>, CommonError, Value> {
35+
ActionEffect::New(Arc::new(move |Executor:Arc<dyn CommandExecutor>| {
4436
let CommandIdentifierClone = CommandIdentifier.clone();
4537
let ArgumentClone = Argument.clone();
46-
Box::pin(async move {
47-
let Executor:Arc<dyn CommandExecutor> = RunTime.Require();
48-
Executor.ExecuteCommand(CommandIdentifierClone, ArgumentClone).await
49-
})
38+
Box::pin(async move { Executor.ExecuteCommand(CommandIdentifierClone, ArgumentClone).await })
5039
}))
5140
}

Source/Command/GetAllCommands.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
use std::sync::Arc;
77

88
use super::CommandExecutor::CommandExecutor;
9-
use crate::{
10-
Effect::{ActionEffect::ActionEffect, ApplicationRunTime::ApplicationRunTime},
11-
Environment::Requires::Requires,
12-
Error::CommonError::CommonError,
13-
};
9+
use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
1410

1511
/// Creates an effect that, when executed, will retrieve a list of all currently
1612
/// registered command identifiers.
@@ -22,15 +18,10 @@ use crate::{
2218
/// # Returns
2319
///
2420
/// An `ActionEffect` that resolves with a `Vec<String>` of command
25-
/// identifiers.
26-
pub fn GetAllCommands<TRunTime>() -> ActionEffect<Arc<TRunTime>, CommonError, Vec<String>>
27-
where
28-
TRunTime: ApplicationRunTime + Send + Sync + 'static,
29-
TRunTime: Requires<Arc<dyn CommandExecutor>>, {
30-
ActionEffect::New(Arc::new(move |RunTime:Arc<TRunTime>| {
31-
Box::pin(async move {
32-
let Executor:Arc<dyn CommandExecutor> = RunTime.Require();
33-
Executor.GetAllCommands().await
34-
})
21+
/// identifiers. The capability required to run this effect is an
22+
/// `Arc<dyn CommandExecutor>`.
23+
pub fn GetAllCommands() -> ActionEffect<Arc<dyn CommandExecutor>, CommonError, Vec<String>> {
24+
ActionEffect::New(Arc::new(move |Executor:Arc<dyn CommandExecutor>| {
25+
Box::pin(async move { Executor.GetAllCommands().await })
3526
}))
3627
}

Source/Command/RegisterCommand.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
use std::sync::Arc;
77

88
use super::CommandExecutor::CommandExecutor;
9-
use crate::{
10-
Effect::{ActionEffect::ActionEffect, ApplicationRunTime::ApplicationRunTime},
11-
Environment::Requires::Requires,
12-
Error::CommonError::CommonError,
13-
};
9+
use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
1410

1511
/// Creates an effect that, when executed, will register a command that is
1612
/// implemented in a sidecar process like Cocoon.
@@ -30,19 +26,13 @@ use crate::{
3026
/// # Returns
3127
///
3228
/// An `ActionEffect` that resolves to `()` on success.
33-
pub fn RegisterCommand<TRunTime>(
29+
pub fn RegisterCommand(
3430
SidecarIdentifier:String,
3531
CommandIdentifier:String,
36-
) -> ActionEffect<Arc<TRunTime>, CommonError, ()>
37-
where
38-
TRunTime: ApplicationRunTime + Send + Sync + 'static,
39-
TRunTime: Requires<Arc<dyn CommandExecutor>>, {
40-
ActionEffect::New(Arc::new(move |RunTime:Arc<TRunTime>| {
32+
) -> ActionEffect<Arc<dyn CommandExecutor>, CommonError, ()> {
33+
ActionEffect::New(Arc::new(move |Executor:Arc<dyn CommandExecutor>| {
4134
let SidecarIdentifierClone = SidecarIdentifier.clone();
4235
let CommandIdentifierClone = CommandIdentifier.clone();
43-
Box::pin(async move {
44-
let Executor:Arc<dyn CommandExecutor> = RunTime.Require();
45-
Executor.RegisterCommand(SidecarIdentifierClone, CommandIdentifierClone).await
46-
})
36+
Box::pin(async move { Executor.RegisterCommand(SidecarIdentifierClone, CommandIdentifierClone).await })
4737
}))
4838
}

Source/Command/UnregisterCommand.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
use std::sync::Arc;
77

88
use super::CommandExecutor::CommandExecutor;
9-
use crate::{
10-
Effect::{ActionEffect::ActionEffect, ApplicationRunTime::ApplicationRunTime},
11-
Environment::Requires::Requires,
12-
Error::CommonError::CommonError,
13-
};
9+
use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
1410

1511
/// Creates an effect that, when executed, will unregister a command from the
1612
/// host's command registry.
@@ -27,19 +23,13 @@ use crate::{
2723
/// # Returns
2824
///
2925
/// An `ActionEffect` that resolves to `()` on success.
30-
pub fn UnregisterCommand<TRunTime>(
26+
pub fn UnregisterCommand(
3127
SidecarIdentifier:String,
3228
CommandIdentifier:String,
33-
) -> ActionEffect<Arc<TRunTime>, CommonError, ()>
34-
where
35-
TRunTime: ApplicationRunTime + Send + Sync + 'static,
36-
TRunTime: Requires<Arc<dyn CommandExecutor>>, {
37-
ActionEffect::New(Arc::new(move |RunTime:Arc<TRunTime>| {
29+
) -> ActionEffect<Arc<dyn CommandExecutor>, CommonError, ()> {
30+
ActionEffect::New(Arc::new(move |Executor:Arc<dyn CommandExecutor>| {
3831
let SidecarIdentifierClone = SidecarIdentifier.clone();
3932
let CommandIdentifierClone = CommandIdentifier.clone();
40-
Box::pin(async move {
41-
let Executor:Arc<dyn CommandExecutor> = RunTime.Require();
42-
Executor.UnregisterCommand(SidecarIdentifierClone, CommandIdentifierClone).await
43-
})
33+
Box::pin(async move { Executor.UnregisterCommand(SidecarIdentifierClone, CommandIdentifierClone).await })
4434
}))
4535
}

Source/Configuration/GetConfiguration.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ use std::sync::Arc;
88
use serde_json::Value;
99

1010
use super::{ConfigurationProvider::ConfigurationProvider, DTO::ConfigurationOverridesDTO::ConfigurationOverridesDTO};
11-
use crate::{
12-
Effect::{ActionEffect::ActionEffect, ApplicationRunTime::ApplicationRunTime},
13-
Environment::Requires::Requires,
14-
Error::CommonError::CommonError,
15-
};
11+
use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
1612

1713
/// Creates an effect that, when executed, will retrieve the final, merged
1814
/// configuration value for a given section, applying any specified overrides.
@@ -32,19 +28,14 @@ use crate::{
3228
///
3329
/// An `ActionEffect` that resolves with a `serde_json::Value` containing the
3430
/// requested configuration.
35-
pub fn GetConfiguration<TRunTime>(
31+
pub fn GetConfiguration(
3632
Section:Option<String>,
3733
OverridesValue:Value,
38-
) -> ActionEffect<Arc<TRunTime>, CommonError, Value>
39-
where
40-
TRunTime: ApplicationRunTime + Send + Sync + 'static,
41-
TRunTime: Requires<Arc<dyn ConfigurationProvider>>, {
42-
ActionEffect::New(Arc::new(move |RunTime:Arc<TRunTime>| {
34+
) -> ActionEffect<Arc<dyn ConfigurationProvider>, CommonError, Value> {
35+
ActionEffect::New(Arc::new(move |Provider:Arc<dyn ConfigurationProvider>| {
4336
let SectionClone = Section.clone();
4437
let OverridesValueClone = OverridesValue.clone();
4538
Box::pin(async move {
46-
let Provider:Arc<dyn ConfigurationProvider> = RunTime.Require();
47-
4839
let OverridesParsed:ConfigurationOverridesDTO =
4940
serde_json::from_value(OverridesValueClone).map_err(|e| {
5041
CommonError::InvalidArgument {

Source/Configuration/InspectConfiguration.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ use super::{
1111
ConfigurationInspector::ConfigurationInspector,
1212
DTO::{ConfigurationOverridesDTO::ConfigurationOverridesDTO, InspectResultDataDTO::InspectResultDataDTO},
1313
};
14-
use crate::{
15-
Effect::{ActionEffect::ActionEffect, ApplicationRunTime::ApplicationRunTime},
16-
Environment::Requires::Requires,
17-
Error::CommonError::CommonError,
18-
};
14+
use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
1915

2016
/// Creates an effect that, when executed, will inspect a configuration key to
2117
/// get its value from all relevant sources (e.g., default, user, workspace).
@@ -36,19 +32,14 @@ use crate::{
3632
/// An `ActionEffect` that resolves with an `Option<InspectResultDataDTO>`,
3733
/// containing the detailed breakdown of the configuration value from all
3834
/// scopes.
39-
pub fn InspectConfiguration<TRunTime>(
35+
pub fn InspectConfiguration(
4036
Key:String,
4137
OverridesValue:Value,
42-
) -> ActionEffect<Arc<TRunTime>, CommonError, Option<InspectResultDataDTO>>
43-
where
44-
TRunTime: ApplicationRunTime + Send + Sync + 'static,
45-
TRunTime: Requires<Arc<dyn ConfigurationInspector>>, {
46-
ActionEffect::New(Arc::new(move |RunTime:Arc<TRunTime>| {
38+
) -> ActionEffect<Arc<dyn ConfigurationInspector>, CommonError, Option<InspectResultDataDTO>> {
39+
ActionEffect::New(Arc::new(move |Inspector:Arc<dyn ConfigurationInspector>| {
4740
let KeyClone = Key.clone();
4841
let OverridesValueClone = OverridesValue.clone();
4942
Box::pin(async move {
50-
let Inspector:Arc<dyn ConfigurationInspector> = RunTime.Require();
51-
5243
let OverridesParsed:ConfigurationOverridesDTO =
5344
serde_json::from_value(OverridesValueClone).map_err(|e| {
5445
CommonError::InvalidArgument {

0 commit comments

Comments
 (0)