Skip to content

Commit 7dcbc4e

Browse files
lannrylev
authored andcommitted
factors: Remove InstanceFactors
Signed-off-by: Lann Martin <[email protected]>
1 parent 1d0c79e commit 7dcbc4e

File tree

15 files changed

+52
-84
lines changed

15 files changed

+52
-84
lines changed

crates/factor-key-value/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use std::{
1010
use anyhow::ensure;
1111
use host::KEY_VALUE_STORES_KEY;
1212
use spin_factors::{
13-
ConfigureAppContext, Factor, FactorInstanceBuilder, InitContext, PrepareContext,
14-
PreparedInstanceBuilders, RuntimeFactors,
13+
ConfigureAppContext, Factor, FactorInstanceBuilder, InitContext, PrepareContext, RuntimeFactors,
1514
};
1615
use util::{CachingStoreManager, DefaultManagerGetter};
1716

@@ -89,8 +88,7 @@ impl Factor for KeyValueFactor {
8988

9089
fn prepare<T: RuntimeFactors>(
9190
&self,
92-
ctx: PrepareContext<Self>,
93-
_builders: &mut PreparedInstanceBuilders<T>,
91+
ctx: PrepareContext<T, Self>,
9492
) -> anyhow::Result<InstanceBuilder> {
9593
let app_state = ctx.app_state();
9694
let allowed_stores = app_state

crates/factor-llm/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use std::sync::Arc;
66

77
use async_trait::async_trait;
88
use spin_factors::{
9-
ConfigureAppContext, Factor, PrepareContext, PreparedInstanceBuilders, RuntimeFactors,
10-
SelfInstanceBuilder,
9+
ConfigureAppContext, Factor, PrepareContext, RuntimeFactors, SelfInstanceBuilder,
1110
};
1211
use spin_locked_app::MetadataKey;
1312
use spin_world::v1::llm::{self as v1};
@@ -77,8 +76,7 @@ impl Factor for LlmFactor {
7776

7877
fn prepare<T: RuntimeFactors>(
7978
&self,
80-
ctx: PrepareContext<Self>,
81-
_builders: &mut PreparedInstanceBuilders<T>,
79+
ctx: PrepareContext<T, Self>,
8280
) -> anyhow::Result<Self::InstanceBuilder> {
8381
let allowed_models = ctx
8482
.app_state()

crates/factor-outbound-http/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use spin_factor_outbound_networking::{
1414
ComponentTlsConfigs, OutboundAllowedHosts, OutboundNetworkingFactor,
1515
};
1616
use spin_factors::{
17-
anyhow, ConfigureAppContext, Factor, PrepareContext, PreparedInstanceBuilders, RuntimeFactors,
18-
SelfInstanceBuilder,
17+
anyhow, ConfigureAppContext, Factor, PrepareContext, RuntimeFactors, SelfInstanceBuilder,
1918
};
2019
use wasmtime_wasi_http::WasiHttpCtx;
2120

@@ -59,10 +58,9 @@ impl Factor for OutboundHttpFactor {
5958

6059
fn prepare<T: RuntimeFactors>(
6160
&self,
62-
_ctx: PrepareContext<Self>,
63-
builders: &mut PreparedInstanceBuilders<T>,
61+
mut ctx: PrepareContext<T, Self>,
6462
) -> anyhow::Result<Self::InstanceBuilder> {
65-
let outbound_networking = builders.get_mut::<OutboundNetworkingFactor>()?;
63+
let outbound_networking = ctx.instance_builder::<OutboundNetworkingFactor>()?;
6664
let allowed_hosts = outbound_networking.allowed_hosts();
6765
let component_tls_configs = outbound_networking.component_tls_configs().clone();
6866
Ok(InstanceState {

crates/factor-outbound-mqtt/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use rumqttc::{AsyncClient, Event, Incoming, Outgoing, QoS};
99
use spin_core::async_trait;
1010
use spin_factor_outbound_networking::OutboundNetworkingFactor;
1111
use spin_factors::{
12-
ConfigureAppContext, Factor, PrepareContext, PreparedInstanceBuilders, RuntimeFactors,
13-
SelfInstanceBuilder,
12+
ConfigureAppContext, Factor, PrepareContext, RuntimeFactors, SelfInstanceBuilder,
1413
};
1514
use spin_world::v2::mqtt::{self as v2, Error, Qos};
1615
use tokio::sync::Mutex;
@@ -49,11 +48,10 @@ impl Factor for OutboundMqttFactor {
4948

5049
fn prepare<T: RuntimeFactors>(
5150
&self,
52-
_ctx: PrepareContext<Self>,
53-
builders: &mut PreparedInstanceBuilders<T>,
51+
mut ctx: PrepareContext<T, Self>,
5452
) -> anyhow::Result<Self::InstanceBuilder> {
55-
let allowed_hosts = builders
56-
.get_mut::<OutboundNetworkingFactor>()?
53+
let allowed_hosts = ctx
54+
.instance_builder::<OutboundNetworkingFactor>()?
5755
.allowed_hosts();
5856
Ok(InstanceState::new(
5957
allowed_hosts,

crates/factor-outbound-mysql/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ impl<C: Send + Sync + Client + 'static> Factor for OutboundMysqlFactor<C> {
3232

3333
fn prepare<T: spin_factors::RuntimeFactors>(
3434
&self,
35-
_ctx: spin_factors::PrepareContext<Self>,
36-
builders: &mut spin_factors::PreparedInstanceBuilders<T>,
35+
mut ctx: spin_factors::PrepareContext<T, Self>,
3736
) -> anyhow::Result<Self::InstanceBuilder> {
38-
let allowed_hosts = builders
39-
.get_mut::<OutboundNetworkingFactor>()?
37+
let allowed_hosts = ctx
38+
.instance_builder::<OutboundNetworkingFactor>()?
4039
.allowed_hosts();
4140
Ok(InstanceState {
4241
allowed_hosts,

crates/factor-outbound-networking/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use spin_factor_variables::VariablesFactor;
1313
use spin_factor_wasi::{SocketAddrUse, WasiFactor};
1414
use spin_factors::{
1515
anyhow::{self, Context},
16-
ConfigureAppContext, Error, Factor, FactorInstanceBuilder, PrepareContext,
17-
PreparedInstanceBuilders, RuntimeFactors,
16+
ConfigureAppContext, Error, Factor, FactorInstanceBuilder, PrepareContext, RuntimeFactors,
1817
};
1918

2019
pub use config::{
@@ -82,17 +81,16 @@ impl Factor for OutboundNetworkingFactor {
8281

8382
fn prepare<T: RuntimeFactors>(
8483
&self,
85-
ctx: PrepareContext<Self>,
86-
builders: &mut PreparedInstanceBuilders<T>,
84+
mut ctx: PrepareContext<T, Self>,
8785
) -> anyhow::Result<Self::InstanceBuilder> {
8886
let hosts = ctx
8987
.app_state()
9088
.component_allowed_hosts
9189
.get(ctx.app_component().id())
9290
.cloned()
9391
.context("missing component allowed hosts")?;
94-
let resolver = builders
95-
.get_mut::<VariablesFactor>()?
92+
let resolver = ctx
93+
.instance_builder::<VariablesFactor>()?
9694
.expression_resolver()
9795
.clone();
9896
let allowed_hosts_future = async move {
@@ -103,7 +101,7 @@ impl Factor for OutboundNetworkingFactor {
103101
.boxed()
104102
.shared();
105103

106-
match builders.get_mut::<WasiFactor>() {
104+
match ctx.instance_builder::<WasiFactor>() {
107105
Ok(wasi_builder) => {
108106
// Update Wasi socket allowed ports
109107
let allowed_hosts = OutboundAllowedHosts {

crates/factor-outbound-pg/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ mod host;
44
use client::Client;
55
use spin_factor_outbound_networking::{OutboundAllowedHosts, OutboundNetworkingFactor};
66
use spin_factors::{
7-
anyhow, ConfigureAppContext, Factor, PrepareContext, PreparedInstanceBuilders, RuntimeFactors,
8-
SelfInstanceBuilder,
7+
anyhow, ConfigureAppContext, Factor, PrepareContext, RuntimeFactors, SelfInstanceBuilder,
98
};
109
use tokio_postgres::Client as PgClient;
1110

@@ -36,11 +35,10 @@ impl<C: Send + Sync + Client + 'static> Factor for OutboundPgFactor<C> {
3635

3736
fn prepare<T: RuntimeFactors>(
3837
&self,
39-
_ctx: PrepareContext<Self>,
40-
builders: &mut PreparedInstanceBuilders<T>,
38+
mut ctx: PrepareContext<T, Self>,
4139
) -> anyhow::Result<Self::InstanceBuilder> {
42-
let allowed_hosts = builders
43-
.get_mut::<OutboundNetworkingFactor>()?
40+
let allowed_hosts = ctx
41+
.instance_builder::<OutboundNetworkingFactor>()?
4442
.allowed_hosts();
4543
Ok(InstanceState {
4644
allowed_hosts,

crates/factor-outbound-redis/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ mod host;
33
use host::InstanceState;
44
use spin_factor_outbound_networking::OutboundNetworkingFactor;
55
use spin_factors::{
6-
anyhow, ConfigureAppContext, Factor, PrepareContext, PreparedInstanceBuilders, RuntimeFactors,
7-
SelfInstanceBuilder,
6+
anyhow, ConfigureAppContext, Factor, PrepareContext, RuntimeFactors, SelfInstanceBuilder,
87
};
98

109
/// The [`Factor`] for `fermyon:spin/outbound-redis`.
@@ -42,11 +41,10 @@ impl Factor for OutboundRedisFactor {
4241

4342
fn prepare<T: RuntimeFactors>(
4443
&self,
45-
_ctx: PrepareContext<Self>,
46-
builders: &mut PreparedInstanceBuilders<T>,
44+
mut ctx: PrepareContext<T, Self>,
4745
) -> anyhow::Result<Self::InstanceBuilder> {
48-
let allowed_hosts = builders
49-
.get_mut::<OutboundNetworkingFactor>()?
46+
let allowed_hosts = ctx
47+
.instance_builder::<OutboundNetworkingFactor>()?
5048
.allowed_hosts();
5149
Ok(InstanceState {
5250
allowed_hosts,

crates/factor-sqlite/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ impl Factor for SqliteFactor {
8686

8787
fn prepare<T: spin_factors::RuntimeFactors>(
8888
&self,
89-
ctx: spin_factors::PrepareContext<Self>,
90-
_builders: &mut spin_factors::PreparedInstanceBuilders<T>,
89+
ctx: spin_factors::PrepareContext<T, Self>,
9190
) -> spin_factors::anyhow::Result<Self::InstanceBuilder> {
9291
let allowed_databases = ctx
9392
.app_state()

crates/factor-variables/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::sync::Arc;
77
use runtime_config::RuntimeConfig;
88
use spin_expressions::{ProviderResolver as ExpressionResolver, Template};
99
use spin_factors::{
10-
anyhow, ConfigureAppContext, Factor, InitContext, PrepareContext, PreparedInstanceBuilders,
11-
RuntimeFactors, SelfInstanceBuilder,
10+
anyhow, ConfigureAppContext, Factor, InitContext, PrepareContext, RuntimeFactors,
11+
SelfInstanceBuilder,
1212
};
1313

1414
/// A factor for providing variables to components.
@@ -54,8 +54,7 @@ impl Factor for VariablesFactor {
5454

5555
fn prepare<T: RuntimeFactors>(
5656
&self,
57-
ctx: PrepareContext<Self>,
58-
_builders: &mut PreparedInstanceBuilders<T>,
57+
ctx: PrepareContext<T, Self>,
5958
) -> anyhow::Result<InstanceState> {
6059
let component_id = ctx.app_component().id().to_string();
6160
let expression_resolver = ctx.app_state().expression_resolver.clone();

0 commit comments

Comments
 (0)