Skip to content

Commit 181c721

Browse files
committed
documentation: add docs to componnet-related modules
Signed-off-by: Jiaxiao Zhou <duibao55328@gmail.com>
1 parent 935ef64 commit 181c721

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

crates/wassette/src/component_storage.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
//! Filesystem helpers that manage component artifacts, metadata, and cache
5+
//! layout for the lifecycle manager.
6+
17
use std::path::{Path, PathBuf};
28
use std::sync::Arc;
39

@@ -158,7 +164,11 @@ impl ComponentStorage {
158164
Ok(())
159165
}
160166

161-
/// Create a validation stamp for a file.
167+
/// Create a validation stamp for a component artifact to track stale data on disk.
168+
///
169+
/// When `include_hash` is `true` the SHA-256 hash of the file is
170+
/// recorded in addition to size and modification time so changes can be
171+
/// detected even when timestamps are unreliable.
162172
pub async fn create_validation_stamp(
163173
path: &Path,
164174
include_hash: bool,

crates/wassette/src/config.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
//! Builder and configuration helpers for constructing
5+
//! [`LifecycleManager`](crate::LifecycleManager).
6+
17
use std::collections::HashMap;
28
use std::path::{Path, PathBuf};
39
use std::time::Duration;
@@ -83,6 +89,8 @@ pub struct LifecycleBuilder {
8389
}
8490

8591
impl LifecycleBuilder {
92+
/// Create a builder with sensible defaults for the provided plugin
93+
/// directory.
8694
pub(crate) fn new(plugin_dir: PathBuf) -> Self {
8795
Self {
8896
plugin_dir,
@@ -163,7 +171,12 @@ impl LifecycleBuilder {
163171
})
164172
}
165173

166-
/// Construct a [`LifecycleManager`], optionally performing eager loading.
174+
/// Construct a [`LifecycleManager`] using the current builder settings.
175+
///
176+
/// If eager loading is enabled the plugin directory is scanned
177+
/// immediately; otherwise the caller can defer loading until a later
178+
/// [`LifecycleManager::load_all_components`](crate::LifecycleManager::load_all_components)
179+
/// invocation.
167180
pub async fn build(self) -> Result<LifecycleManager> {
168181
let config = self.build_config()?;
169182
let eager = config.eager_load();
@@ -175,6 +188,7 @@ impl LifecycleBuilder {
175188
}
176189
}
177190

191+
/// Create the default HTTP client used when none is supplied.
178192
fn default_http_client() -> Result<reqwest::Client> {
179193
let http_timeout = std::env::var("HTTP_TIMEOUT_SECS")
180194
.ok()
@@ -187,6 +201,7 @@ fn default_http_client() -> Result<reqwest::Client> {
187201
.context("Failed to create default HTTP client")
188202
}
189203

204+
/// Create the default OCI client used when none is supplied.
190205
fn default_oci_client() -> Result<oci_client::Client> {
191206
let oci_timeout = std::env::var("OCI_TIMEOUT_SECS")
192207
.ok()
@@ -213,6 +228,8 @@ impl LifecycleConfig {
213228
}
214229
}
215230

231+
/// Internal helper that exposes the decomposed configuration values to the
232+
/// lifecycle manager for initialization.
216233
pub(crate) struct LifecycleConfigParts {
217234
pub plugin_dir: PathBuf,
218235
pub secrets_dir: PathBuf,

crates/wassette/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ pub struct ComponentInstance {
300300
}
301301

302302
impl LifecycleManager {
303-
/// Begin constructing a lifecycle manager with a fluent builder.
303+
/// Begin constructing a lifecycle manager with a fluent builder that
304+
/// validates configuration and applies sensible defaults.
304305
pub fn builder(plugin_dir: impl Into<PathBuf>) -> LifecycleBuilder {
305306
LifecycleBuilder::new(plugin_dir.into())
306307
}
@@ -508,7 +509,8 @@ impl LifecycleManager {
508509
/// Loads a new component from the given URI. This URI can be a file path, an OCI reference, or a URL.
509510
///
510511
/// If a component with the given id already exists, it will be updated with the new component.
511-
/// Returns the new ID and whether or not this component was replaced.
512+
/// Returns rich [`ComponentLoadOutcome`] information describing the loaded
513+
/// component and whether it replaced an existing instance.
512514
#[instrument(skip(self))]
513515
pub async fn load_component(&self, uri: &str) -> Result<ComponentLoadOutcome> {
514516
debug!(uri, "Loading component");

crates/wassette/src/policy_internal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ impl PolicyManager {
146146
self.build_default_template(component_id).await
147147
}
148148

149+
/// Construct a default WASI template enriched with configured environment
150+
/// variables and any stored secrets for the component.
149151
async fn build_default_template(&self, component_id: &str) -> Arc<WasiStateTemplate> {
150152
let mut config_vars = self.environment_vars.as_ref().clone();
151153

@@ -277,6 +279,8 @@ impl PolicyManager {
277279
Ok(())
278280
}
279281

282+
/// Rehydrate policy templates from a co-located policy file on disk, if
283+
/// one exists for the component.
280284
pub(crate) async fn restore_from_disk(&self, component_id: &str) -> Result<()> {
281285
let policy_path = self.policy_path(component_id);
282286
if !policy_path.exists() {

crates/wassette/src/runtime_context.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
//! Support utilities for sharing Wasmtime engine and linker state across lifecycle
5+
//! manager instances.
6+
17
use std::sync::Arc;
28

39
use anyhow::Result;
@@ -42,17 +48,18 @@ impl RuntimeContext {
4248
Arc::clone(&self.engine)
4349
}
4450

45-
/// Lightweight reference to the engine.
51+
/// Borrow the underlying engine reference.
4652
pub fn engine(&self) -> &Engine {
4753
self.engine.as_ref()
4854
}
4955

50-
/// Accessor for the linker handle.
56+
/// Accessor for the linker handle as a shareable pointer.
5157
pub fn linker_handle(&self) -> Arc<Linker<WassetteWasiState<WasiState>>> {
5258
Arc::clone(&self.linker)
5359
}
5460

55-
/// Produce a cached instance-pre handle for the provided component.
61+
/// Produce a cached `InstancePre` handle for the provided component using
62+
/// the shared linker configuration.
5663
pub fn instantiate_pre(
5764
&self,
5865
component: &Component,

0 commit comments

Comments
 (0)