Skip to content

Commit e9b5049

Browse files
authored
Merge pull request #1876 from fermyon/share-host-components
No need for 'legacy host components
2 parents d84dde0 + b8da7a5 commit e9b5049

File tree

7 files changed

+9
-102
lines changed

7 files changed

+9
-102
lines changed

crates/key-value/src/host_component.rs

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ impl HostComponent for KeyValueComponent {
4747
linker: &mut spin_core::Linker<T>,
4848
get: impl Fn(&mut spin_core::Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static,
4949
) -> anyhow::Result<()> {
50-
super::key_value::add_to_linker(linker, get)
50+
super::key_value::add_to_linker(linker, get)?;
51+
spin_world::v1::key_value::add_to_linker(linker, get)
5152
}
5253

5354
fn build_data(&self) -> Self::Data {
@@ -102,36 +103,3 @@ impl DynamicHostComponent for KeyValueComponent {
102103
}
103104
}
104105
}
105-
106-
pub struct LegacyKeyValueComponent(KeyValueComponent);
107-
108-
impl LegacyKeyValueComponent {
109-
pub fn new(new: KeyValueComponent) -> Self {
110-
Self(new)
111-
}
112-
}
113-
114-
impl HostComponent for LegacyKeyValueComponent {
115-
type Data = KeyValueDispatch;
116-
117-
fn add_to_linker<T: Send>(
118-
linker: &mut spin_core::Linker<T>,
119-
get: impl Fn(&mut spin_core::Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static,
120-
) -> anyhow::Result<()> {
121-
spin_world::v1::key_value::add_to_linker(linker, get)
122-
}
123-
124-
fn build_data(&self) -> Self::Data {
125-
self.0.build_data()
126-
}
127-
}
128-
129-
impl DynamicHostComponent for LegacyKeyValueComponent {
130-
fn update_data(&self, data: &mut Self::Data, component: &AppComponent) -> anyhow::Result<()> {
131-
self.0.update_data(data, component)
132-
}
133-
134-
fn validate_app(&self, app: &spin_app::App) -> anyhow::Result<()> {
135-
self.0.validate_app(app)
136-
}
137-
}

crates/key-value/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod host_component;
99
pub mod table;
1010
mod util;
1111

12-
pub use host_component::{manager, KeyValueComponent, LegacyKeyValueComponent};
12+
pub use host_component::{manager, KeyValueComponent};
1313
pub use util::{CachingStoreManager, DelegatingStoreManager, EmptyStoreManager};
1414

1515
pub const KEY_VALUE_STORES_KEY: MetadataKey<Vec<String>> = MetadataKey::new("key_value_stores");

crates/sqlite/src/host_component.rs

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ impl HostComponent for SqliteComponent {
3131
linker: &mut spin_core::Linker<T>,
3232
get: impl Fn(&mut spin_core::Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static,
3333
) -> anyhow::Result<()> {
34-
sqlite::add_to_linker(linker, get)
34+
sqlite::add_to_linker(linker, get)?;
35+
spin_world::v1::sqlite::add_to_linker(linker, get)
3536
}
3637

3738
fn build_data(&self) -> Self::Data {
@@ -98,36 +99,3 @@ impl DynamicHostComponent for SqliteComponent {
9899
}
99100
}
100101
}
101-
102-
pub struct LegacySqliteComponent(SqliteComponent);
103-
104-
impl LegacySqliteComponent {
105-
pub fn new(new: SqliteComponent) -> Self {
106-
Self(new)
107-
}
108-
}
109-
110-
impl HostComponent for LegacySqliteComponent {
111-
type Data = super::SqliteDispatch;
112-
113-
fn add_to_linker<T: Send>(
114-
linker: &mut spin_core::Linker<T>,
115-
get: impl Fn(&mut spin_core::Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static,
116-
) -> anyhow::Result<()> {
117-
spin_world::v1::sqlite::add_to_linker(linker, get)
118-
}
119-
120-
fn build_data(&self) -> Self::Data {
121-
self.0.build_data()
122-
}
123-
}
124-
125-
impl DynamicHostComponent for LegacySqliteComponent {
126-
fn update_data(&self, data: &mut Self::Data, component: &AppComponent) -> anyhow::Result<()> {
127-
self.0.update_data(data, component)
128-
}
129-
130-
fn validate_app(&self, app: &spin_app::App) -> anyhow::Result<()> {
131-
self.0.validate_app(app)
132-
}
133-
}

crates/sqlite/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use spin_key_value::table;
66
use spin_world::v2::sqlite;
77
use std::{collections::HashSet, sync::Arc};
88

9-
pub use host_component::{LegacySqliteComponent, SqliteComponent};
9+
pub use host_component::SqliteComponent;
1010

1111
pub const DATABASES_KEY: MetadataKey<HashSet<String>> = MetadataKey::new("databases");
1212

crates/trigger/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,11 @@ impl<Executor: TriggerExecutor> TriggerExecutorBuilder<Executor> {
128128
)
129129
.await?,
130130
)?;
131-
self.loader.add_dynamic_host_component(
132-
&mut builder,
133-
runtime_config::key_value::build_legacy_key_value_component(
134-
&runtime_config,
135-
&init_data.kv,
136-
)
137-
.await?,
138-
)?;
139131
self.loader.add_dynamic_host_component(
140132
&mut builder,
141133
runtime_config::sqlite::build_component(&runtime_config, &init_data.sqlite)
142134
.await?,
143135
)?;
144-
self.loader.add_dynamic_host_component(
145-
&mut builder,
146-
runtime_config::sqlite::build_legacy_component(&runtime_config).await?,
147-
)?;
148136
self.loader.add_dynamic_host_component(
149137
&mut builder,
150138
outbound_http::OutboundHttpComponent,

crates/trigger/src/runtime_config/key_value.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::{runtime_config::RuntimeConfig, TriggerHooks};
44
use anyhow::{bail, Context, Result};
55
use serde::Deserialize;
66
use spin_key_value::{
7-
CachingStoreManager, DelegatingStoreManager, KeyValueComponent, LegacyKeyValueComponent,
8-
StoreManager, KEY_VALUE_STORES_KEY,
7+
CachingStoreManager, DelegatingStoreManager, KeyValueComponent, StoreManager,
8+
KEY_VALUE_STORES_KEY,
99
};
1010
use spin_key_value_azure::KeyValueAzureCosmos;
1111
use spin_key_value_sqlite::{DatabaseLocation, KeyValueSqlite};
@@ -54,14 +54,6 @@ pub async fn build_key_value_component(
5454
})))
5555
}
5656

57-
pub async fn build_legacy_key_value_component(
58-
runtime_config: &RuntimeConfig,
59-
init_data: &[(String, String)],
60-
) -> Result<LegacyKeyValueComponent> {
61-
let new = build_key_value_component(runtime_config, init_data).await?;
62-
Ok(LegacyKeyValueComponent::new(new))
63-
}
64-
6557
// Holds deserialized options from a `[key_value_store.<name>]` runtime config section.
6658
#[derive(Clone, Debug, Deserialize)]
6759
#[serde(rename_all = "snake_case", tag = "type")]

crates/trigger/src/runtime_config/sqlite.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc};
22

33
use crate::{runtime_config::RuntimeConfig, TriggerHooks};
44
use anyhow::Context;
5-
use spin_sqlite::{
6-
Connection, ConnectionsStore, LegacySqliteComponent, SqliteComponent, DATABASES_KEY,
7-
};
5+
use spin_sqlite::{Connection, ConnectionsStore, SqliteComponent, DATABASES_KEY};
86

97
use super::RuntimeConfigOpts;
108

@@ -25,13 +23,6 @@ pub(crate) async fn build_component(
2523
Ok(SqliteComponent::new(move |_| connections_store.clone()))
2624
}
2725

28-
pub(crate) async fn build_legacy_component(
29-
runtime_config: &RuntimeConfig,
30-
) -> anyhow::Result<LegacySqliteComponent> {
31-
let component = build_component(runtime_config, &[]).await?;
32-
Ok(LegacySqliteComponent::new(component))
33-
}
34-
3526
/// A `ConnectionStore` based on a `HashMap`
3627
struct SimpleConnectionsStore(HashMap<String, Arc<dyn Connection>>);
3728

0 commit comments

Comments
 (0)