From 6568280c6d0e03dc69c554f8bef4417fa224d978 Mon Sep 17 00:00:00 2001
From: Assaf Vayner
Date: Fri, 2 May 2025 11:49:13 +0200
Subject: [PATCH 1/5] add token refresher
---
cas_client/src/http_client.rs | 2 +
cas_client/src/interface.rs | 5 +-
data/src/migration_tool/hub_client.rs | 3 +-
hf_xet/src/token_refresh.rs | 3 +-
hf_xet_wasm/Cargo.lock | 64 +++++------
hf_xet_wasm/Cargo.toml | 9 +-
hf_xet_wasm/examples/simple.rs | 2 +-
hf_xet_wasm/src/interface.rs | 2 +
hf_xet_wasm/src/interface/auth.rs | 60 +++++++++++
hf_xet_wasm/src/interface/session.rs | 101 ++++++++++++++++++
hf_xet_wasm/src/lib.rs | 9 ++
.../src/wasm_deduplication_interface.rs | 4 +-
hf_xet_wasm/src/wasm_file_cleaner.rs | 5 +-
hf_xet_wasm/src/wasm_file_upload_session.rs | 10 +-
hf_xet_wasm/src/xorb_uploader.rs | 4 +-
utils/src/auth.rs | 14 +--
16 files changed, 240 insertions(+), 57 deletions(-)
create mode 100644 hf_xet_wasm/src/interface.rs
create mode 100644 hf_xet_wasm/src/interface/auth.rs
create mode 100644 hf_xet_wasm/src/interface/session.rs
diff --git a/cas_client/src/http_client.rs b/cas_client/src/http_client.rs
index 566265f6..47cb0a9f 100644
--- a/cas_client/src/http_client.rs
+++ b/cas_client/src/http_client.rs
@@ -78,6 +78,7 @@ impl RetryConfig {
/// Builds authenticated HTTP Client to talk to CAS.
/// Includes retry middleware with exponential backoff.
+#[allow(unused_variables)]
pub fn build_auth_http_client(
auth_config: &Option,
retry_config: RetryConfig,
@@ -106,6 +107,7 @@ pub fn build_auth_http_client(
/// Builds HTTP Client to talk to CAS.
/// Includes retry middleware with exponential backoff.
+#[allow(unused_variables)]
pub fn build_http_client(
retry_config: RetryConfig,
) -> std::result::Result {
diff --git a/cas_client/src/interface.rs b/cas_client/src/interface.rs
index d4ba036b..6c1e595c 100644
--- a/cas_client/src/interface.rs
+++ b/cas_client/src/interface.rs
@@ -1,6 +1,7 @@
-use mdb_shard::shard_file_reconstructor::FileReconstructor;
-
+#[cfg(not(target_family = "wasm"))]
use crate::CasClientError;
+#[cfg(not(target_family = "wasm"))]
+use mdb_shard::shard_file_reconstructor::FileReconstructor;
/// A Client to the Shard service. The shard service
/// provides for
diff --git a/data/src/migration_tool/hub_client.rs b/data/src/migration_tool/hub_client.rs
index 5a97aff7..04e8de13 100644
--- a/data/src/migration_tool/hub_client.rs
+++ b/data/src/migration_tool/hub_client.rs
@@ -78,7 +78,8 @@ pub struct HubClientTokenRefresher {
pub client: Arc,
}
-#[async_trait]
+#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
+#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
impl TokenRefresher for HubClientTokenRefresher {
async fn refresh(&self) -> std::result::Result {
let client = self.client.clone();
diff --git a/hf_xet/src/token_refresh.rs b/hf_xet/src/token_refresh.rs
index 786a219c..3665b144 100644
--- a/hf_xet/src/token_refresh.rs
+++ b/hf_xet/src/token_refresh.rs
@@ -49,7 +49,8 @@ impl WrappedTokenRefresher {
}
}
-#[async_trait]
+#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
+#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
impl TokenRefresher for WrappedTokenRefresher {
async fn refresh(&self) -> Result {
Python::with_gil(|py| {
diff --git a/hf_xet_wasm/Cargo.lock b/hf_xet_wasm/Cargo.lock
index 929c1a1c..972fb420 100644
--- a/hf_xet_wasm/Cargo.lock
+++ b/hf_xet_wasm/Cargo.lock
@@ -1021,6 +1021,39 @@ dependencies = [
"libc",
]
+[[package]]
+name = "hf_xet_wasm"
+version = "0.0.1"
+dependencies = [
+ "async-channel",
+ "async-trait",
+ "blake3",
+ "cas_client",
+ "cas_object",
+ "cas_types",
+ "console_error_panic_hook",
+ "console_log",
+ "deduplication",
+ "env_logger",
+ "futures",
+ "futures-io",
+ "getrandom 0.3.2",
+ "js-sys",
+ "log",
+ "mdb_shard",
+ "merkledb",
+ "merklehash",
+ "serde",
+ "sha2",
+ "thiserror 2.0.12",
+ "tokio",
+ "utils",
+ "wasm-bindgen",
+ "wasm-bindgen-futures",
+ "wasm_thread",
+ "web-sys",
+]
+
[[package]]
name = "http"
version = "1.3.1"
@@ -2892,37 +2925,6 @@ dependencies = [
"web-sys",
]
-[[package]]
-name = "wasm_xet"
-version = "0.0.1"
-dependencies = [
- "async-channel",
- "async-trait",
- "blake3",
- "cas_client",
- "cas_object",
- "console_error_panic_hook",
- "console_log",
- "deduplication",
- "env_logger",
- "futures",
- "futures-io",
- "getrandom 0.3.2",
- "js-sys",
- "log",
- "mdb_shard",
- "merkledb",
- "merklehash",
- "sha2",
- "thiserror 2.0.12",
- "tokio",
- "utils",
- "wasm-bindgen",
- "wasm-bindgen-futures",
- "wasm_thread",
- "web-sys",
-]
-
[[package]]
name = "web-sys"
version = "0.3.77"
diff --git a/hf_xet_wasm/Cargo.toml b/hf_xet_wasm/Cargo.toml
index ef9c7cba..8b19b2b3 100644
--- a/hf_xet_wasm/Cargo.toml
+++ b/hf_xet_wasm/Cargo.toml
@@ -1,11 +1,10 @@
[package]
-name = "wasm_xet"
+name = "hf_xet_wasm"
version = "0.0.1"
edition = "2021"
-#[features]
-#default = ["es_modules"]
-#es_modules = []
+[lib]
+crate-type = ["cdylib", "rlib"]
[dependencies]
wasm-bindgen = "0.2.95"
@@ -47,7 +46,9 @@ mdb_shard = { path = "../mdb_shard" }
merkledb = { path = "../merkledb" }
cas_object = { path = "../cas_object" }
cas_client = { path = "../cas_client" }
+cas_types = { path = "../cas_types" }
utils = { path = "../utils" }
+serde = { version = "1.0.217", features = ["derive"] }
[package.metadata.docs.rs]
diff --git a/hf_xet_wasm/examples/simple.rs b/hf_xet_wasm/examples/simple.rs
index 9bcd2589..c6375f8f 100644
--- a/hf_xet_wasm/examples/simple.rs
+++ b/hf_xet_wasm/examples/simple.rs
@@ -142,7 +142,7 @@ pub async fn clean_file(file: web_sys::File, endpoint: String, jwt_token: String
let upload_session = Arc::new(FileUploadSession::new(Arc::new(config)));
- let mut handle = upload_session.start_clean();
+ let mut handle = upload_session.start_clean("".to_string());
const READ_BUF_SIZE: usize = 8 * 1024 * 1024;
let mut buf = vec![0u8; READ_BUF_SIZE];
diff --git a/hf_xet_wasm/src/interface.rs b/hf_xet_wasm/src/interface.rs
new file mode 100644
index 00000000..c2ff86bd
--- /dev/null
+++ b/hf_xet_wasm/src/interface.rs
@@ -0,0 +1,2 @@
+pub(crate) mod auth;
+pub(crate) mod session;
\ No newline at end of file
diff --git a/hf_xet_wasm/src/interface/auth.rs b/hf_xet_wasm/src/interface/auth.rs
new file mode 100644
index 00000000..814213b3
--- /dev/null
+++ b/hf_xet_wasm/src/interface/auth.rs
@@ -0,0 +1,60 @@
+
+use std::fmt::{Debug, Formatter};
+use std::sync::Arc;
+use tokio::sync::Mutex;
+use wasm_bindgen::JsValue;
+use wasm_bindgen::prelude::*;
+
+#[wasm_bindgen]
+extern "C" {
+ pub type TokenInfo;
+ #[wasm_bindgen(method, getter)]
+ pub fn token(this: &TokenInfo) -> String;
+ #[wasm_bindgen(method, getter)]
+ pub fn expiration(this: &TokenInfo) -> u64;
+
+ pub type TokenRefresher;
+ #[wasm_bindgen(method, catch)]
+ pub async fn refresh_token(this: &TokenRefresher) -> Result;
+}
+
+/// interface TokenRefresher {
+/// refresh_token(): Promise;
+/// }
+
+impl From for utils::auth::TokenInfo {
+ fn from(value: TokenInfo) -> Self {
+ (value.token(), value.expiration())
+ }
+}
+
+impl Debug for TokenRefresher {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ write!(f, "TokenRefresher")
+ }
+}
+
+#[derive(Debug, Clone)]
+pub(crate) struct WrappedTokenRefresher(Arc>);
+
+unsafe impl Send for WrappedTokenRefresher {}
+unsafe impl Sync for WrappedTokenRefresher {}
+
+impl From for WrappedTokenRefresher {
+ fn from(value: TokenRefresher) -> Self {
+ WrappedTokenRefresher(Arc::new(Mutex::new(value)))
+ }
+}
+
+#[async_trait::async_trait(?Send)]
+impl utils::auth::TokenRefresher for WrappedTokenRefresher {
+ async fn refresh(&self) -> Result {
+ self.0
+ .lock()
+ .await
+ .refresh_token()
+ .await
+ .map(utils::auth::TokenInfo::from)
+ .map_err(|e| utils::errors::AuthError::token_refresh_failure(format!("{e:?}")))
+ }
+}
diff --git a/hf_xet_wasm/src/interface/session.rs b/hf_xet_wasm/src/interface/session.rs
new file mode 100644
index 00000000..73952ab6
--- /dev/null
+++ b/hf_xet_wasm/src/interface/session.rs
@@ -0,0 +1,101 @@
+#![allow(dead_code)]
+
+use std::sync::Arc;
+
+use cas_object::CompressionScheme;
+use cas_types::HexMerkleHash;
+use futures::AsyncReadExt;
+use serde::{Deserialize, Serialize};
+use utils::auth::AuthConfig;
+use wasm_bindgen::prelude::*;
+use web_sys::Blob;
+
+use crate::blob_reader::BlobReader;
+use crate::configurations::{DataConfig, RepoSalt, ShardConfig, TranslatorConfig};
+use crate::interface::auth::WrappedTokenRefresher;
+
+fn convert_error(e: impl std::error::Error) -> JsValue {
+ JsValue::from(format!("{e:?}"))
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+struct PointerFile {
+ pub file_size: u64,
+ pub file_hash: HexMerkleHash,
+}
+
+#[wasm_bindgen]
+pub struct XetSession {
+ upload: Arc,
+}
+
+#[wasm_bindgen]
+impl XetSession {
+ #[wasm_bindgen(constructor)]
+ pub fn new(
+ endpoint: String,
+ token_info: super::auth::TokenInfo,
+ token_refresher: super::auth::TokenRefresher,
+ ) -> Self {
+ let (token, token_expiration): utils::auth::TokenInfo = token_info.into();
+ let auth = AuthConfig {
+ token,
+ token_expiration,
+ token_refresher: Arc::new(WrappedTokenRefresher::from(token_refresher)),
+ };
+
+ let config = TranslatorConfig {
+ data_config: DataConfig {
+ endpoint,
+ compression: Some(CompressionScheme::LZ4),
+ auth: Some(auth),
+ prefix: "default".to_owned(),
+ },
+ shard_config: ShardConfig {
+ prefix: "default-merkledb".to_owned(),
+ repo_salt: RepoSalt::default(),
+ },
+ };
+ let upload = crate::wasm_file_upload_session::FileUploadSession::new(Arc::new(config));
+
+ Self {
+ upload: Arc::new(upload),
+ }
+ }
+
+ #[wasm_bindgen(js_name = "uploadFileFromRawData")]
+ pub async fn upload_file_from_raw(&self, tracker_id: String, file: Vec) -> Result<(), JsValue> {
+ let blob = Blob::new_with_u8_array_sequence(&js_sys::Uint8Array::from(file.as_slice()))?;
+ self.upload_file_from_blob(tracker_id, blob).await
+ }
+
+ #[wasm_bindgen(js_name = "uploadFileFromBlob")]
+ pub async fn upload_file_from_blob(&self, tracker_id: String, blob: Blob) -> Result<(), JsValue> {
+ // read from blob async
+ let mut cleaner = self.upload.start_clean(tracker_id);
+
+ let mut reader = BlobReader::new(blob)?;
+
+ let mut buf = vec![0u8; 1024 * 10]; // 10KB buffer
+
+ loop {
+ let num_read = reader.read(&mut buf).await.map_err(convert_error)?;
+ if num_read == 0 {
+ break;
+ }
+ cleaner.add_data(&buf[0..num_read]).await.map_err(convert_error)?;
+ }
+
+ Ok(())
+ }
+
+ #[wasm_bindgen]
+ pub async fn finalize(self) -> Result<(), JsValue> {
+ // flush the session
+ self.upload
+ .finalize()
+ .await
+ .map_err(|e| JsValue::from_str(&format!("{:?}", e)))?;
+ Ok(())
+ }
+}
diff --git a/hf_xet_wasm/src/lib.rs b/hf_xet_wasm/src/lib.rs
index e3cab8c2..43e99af4 100644
--- a/hf_xet_wasm/src/lib.rs
+++ b/hf_xet_wasm/src/lib.rs
@@ -1,3 +1,6 @@
+#[cfg(not(target_family = "wasm"))]
+compile_error!("This crate is only meant to be used on the WebAssembly target");
+
pub mod blob_reader;
pub mod configurations;
mod errors;
@@ -6,3 +9,9 @@ mod wasm_deduplication_interface;
mod wasm_file_cleaner;
pub mod wasm_file_upload_session;
mod xorb_uploader;
+mod interface;
+
+pub use interface::{
+ auth::{TokenInfo, TokenRefresher},
+ session::XetSession,
+};
diff --git a/hf_xet_wasm/src/wasm_deduplication_interface.rs b/hf_xet_wasm/src/wasm_deduplication_interface.rs
index 7d42ba1a..7c2a5054 100644
--- a/hf_xet_wasm/src/wasm_deduplication_interface.rs
+++ b/hf_xet_wasm/src/wasm_deduplication_interface.rs
@@ -84,10 +84,10 @@ impl DeduplicationDataInterface for UploadSessionDataManager {
let keyed_shard = self.shard.entry(hmac_key).or_insert(MDBInMemoryShard::default());
for ci in cas_info {
- keyed_shard.add_cas_block(ci);
+ keyed_shard.add_cas_block(ci)?;
}
- any_result = true;
+ any_result = true
}
}
diff --git a/hf_xet_wasm/src/wasm_file_cleaner.rs b/hf_xet_wasm/src/wasm_file_cleaner.rs
index 401b6d4e..a491f4a4 100644
--- a/hf_xet_wasm/src/wasm_file_cleaner.rs
+++ b/hf_xet_wasm/src/wasm_file_cleaner.rs
@@ -11,6 +11,8 @@ use super::wasm_file_upload_session::FileUploadSession;
/// A class that encapsulates the clean and data task around a single file for wasm runtime.
pub struct SingleFileCleaner {
+ _tracker: String,
+
// Common state
session: Arc,
@@ -25,8 +27,9 @@ pub struct SingleFileCleaner {
}
impl SingleFileCleaner {
- pub fn new(session: Arc) -> Self {
+ pub fn new(session: Arc, _tracker: String) -> Self {
Self {
+ _tracker,
session: session.clone(),
chunker: Chunker::default(),
dedup_manager: FileDeduper::new(UploadSessionDataManager::new(session)),
diff --git a/hf_xet_wasm/src/wasm_file_upload_session.rs b/hf_xet_wasm/src/wasm_file_upload_session.rs
index 41201ea9..df4d3d9b 100644
--- a/hf_xet_wasm/src/wasm_file_upload_session.rs
+++ b/hf_xet_wasm/src/wasm_file_upload_session.rs
@@ -12,7 +12,7 @@ use tokio::sync::Mutex;
use super::configurations::TranslatorConfig;
use super::errors::*;
use crate::wasm_file_cleaner::SingleFileCleaner;
-use crate::xorb_uploader::{self, XorbUploader};
+use crate::xorb_uploader::XorbUploader;
static UPLOAD_CONCURRENCY: usize = 1;
@@ -58,15 +58,15 @@ impl FileUploadSession {
}
}
- pub fn start_clean(self: &Arc) -> SingleFileCleaner {
- SingleFileCleaner::new(self.clone())
+ pub fn start_clean(self: &Arc, tracker: String) -> SingleFileCleaner {
+ SingleFileCleaner::new(self.clone(), tracker)
}
pub(crate) async fn register_single_file_clean_completion(
self: &Arc,
mut file_data: DataAggregator,
- dedup_metrics: &DeduplicationMetrics,
- xorbs_dependencies: Vec,
+ _dedup_metrics: &DeduplicationMetrics,
+ _xorbs_dependencies: Vec,
) -> Result<()> {
// Merge in the remaining file data; uploading a new xorb if need be.
{
diff --git a/hf_xet_wasm/src/xorb_uploader.rs b/hf_xet_wasm/src/xorb_uploader.rs
index 93559954..920c0c7f 100644
--- a/hf_xet_wasm/src/xorb_uploader.rs
+++ b/hf_xet_wasm/src/xorb_uploader.rs
@@ -65,7 +65,7 @@ impl XorbUploader {
self.input_queues[self.index]
.send(input)
.await
- .map_err(DataProcessingError::internal);
+ .map_err(DataProcessingError::internal)?;
self.index = (self.index + 1) % self.workers.len();
@@ -108,7 +108,7 @@ fn upload_worker(
log::info!("worker get value message, uploading");
let ret = client.put(&cas_prefix, &xorb_hash, xorb_data, chunks_and_boundaries).await;
- output.send(ret).await;
+ let _ = output.send(ret).await;
}
})
})
diff --git a/utils/src/auth.rs b/utils/src/auth.rs
index bf1f5956..329d008a 100644
--- a/utils/src/auth.rs
+++ b/utils/src/auth.rs
@@ -2,8 +2,6 @@ use std::fmt::Debug;
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
-use async_trait::async_trait;
-
use crate::errors::AuthError;
/// Helper type for information about an auth token.
@@ -11,7 +9,8 @@ use crate::errors::AuthError;
pub type TokenInfo = (String, u64);
/// Helper to provide auth tokens to CAS.
-#[async_trait]
+#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
+#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
pub trait TokenRefresher: Debug + Send + Sync {
/// Get a new auth token for CAS and the unixtime (in seconds) for expiration
async fn refresh(&self) -> Result;
@@ -20,7 +19,8 @@ pub trait TokenRefresher: Debug + Send + Sync {
#[derive(Debug)]
pub struct NoOpTokenRefresher;
-#[async_trait]
+#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
+#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
impl TokenRefresher for NoOpTokenRefresher {
async fn refresh(&self) -> Result {
Ok(("token".to_string(), 0))
@@ -30,7 +30,8 @@ impl TokenRefresher for NoOpTokenRefresher {
#[derive(Debug)]
pub struct ErrTokenRefresher;
-#[async_trait]
+#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
+#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
impl TokenRefresher for ErrTokenRefresher {
async fn refresh(&self) -> Result {
Err(AuthError::RefreshFunctionNotCallable("Token refresh not expected".to_string()))
@@ -90,7 +91,6 @@ impl TokenProvider {
}
pub async fn get_valid_token(&mut self) -> Result {
- #[cfg(not(target_family = "wasm"))]
if self.is_expired() {
let (new_token, new_expiry) = self.refresher.refresh().await?;
self.token = new_token;
@@ -99,7 +99,7 @@ impl TokenProvider {
Ok(self.token.clone())
}
- #[cfg(not(target_family = "wasm"))]
+ // #[cfg(not(target_family = "wasm"))]
fn is_expired(&self) -> bool {
let cur_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
From e4ee6e40aba065f98354d7adbcbcb4642e5027ef Mon Sep 17 00:00:00 2001
From: Assaf Vayner
Date: Fri, 2 May 2025 17:14:07 +0200
Subject: [PATCH 2/5] session
---
hf_xet_wasm/Cargo.lock | 8 +-
hf_xet_wasm/Cargo.toml | 2 +-
hf_xet_wasm/build_wasm.sh | 1 +
hf_xet_wasm/examples/simple.rs | 13 +-
hf_xet_wasm/examples/xet_meta.js | 140 ++++++++++-----------
hf_xet_wasm/src/{interface => }/auth.rs | 2 +-
hf_xet_wasm/src/interface.rs | 2 -
hf_xet_wasm/src/lib.rs | 8 +-
hf_xet_wasm/src/{interface => }/session.rs | 17 ++-
utils/src/auth.rs | 11 +-
10 files changed, 99 insertions(+), 105 deletions(-)
rename hf_xet_wasm/src/{interface => }/auth.rs (96%)
delete mode 100644 hf_xet_wasm/src/interface.rs
rename hf_xet_wasm/src/{interface => }/session.rs (86%)
diff --git a/hf_xet_wasm/Cargo.lock b/hf_xet_wasm/Cargo.lock
index 972fb420..8c6a2766 100644
--- a/hf_xet_wasm/Cargo.lock
+++ b/hf_xet_wasm/Cargo.lock
@@ -1367,9 +1367,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "jiff"
-version = "0.2.10"
+version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a064218214dc6a10fbae5ec5fa888d80c45d611aba169222fc272072bf7aef6"
+checksum = "27e77966151130221b079bcec80f1f34a9e414fa489d99152a201c07fd2182bc"
dependencies = [
"jiff-static",
"log",
@@ -1380,9 +1380,9 @@ dependencies = [
[[package]]
name = "jiff-static"
-version = "0.2.10"
+version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "199b7932d97e325aff3a7030e141eafe7f2c6268e1d1b24859b753a627f45254"
+checksum = "97265751f8a9a4228476f2fc17874a9e7e70e96b893368e42619880fe143b48a"
dependencies = [
"proc-macro2",
"quote",
diff --git a/hf_xet_wasm/Cargo.toml b/hf_xet_wasm/Cargo.toml
index 8b19b2b3..6dbdde3a 100644
--- a/hf_xet_wasm/Cargo.toml
+++ b/hf_xet_wasm/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]
[dependencies]
-wasm-bindgen = "0.2.95"
+wasm-bindgen = "0.2.100"
wasm-bindgen-futures = "0.4.50"
tokio = { version = "1.44", features = ["sync"] }
futures-io = "0.3.31"
diff --git a/hf_xet_wasm/build_wasm.sh b/hf_xet_wasm/build_wasm.sh
index 4517e5aa..4efa5819 100755
--- a/hf_xet_wasm/build_wasm.sh
+++ b/hf_xet_wasm/build_wasm.sh
@@ -18,4 +18,5 @@ RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals --cfg getran
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' wasm-bindgen \
target/wasm32-unknown-unknown/release/examples/simple.wasm \
--out-dir ./examples/target/ \
+ --typescript \
--target web
diff --git a/hf_xet_wasm/examples/simple.rs b/hf_xet_wasm/examples/simple.rs
index c6375f8f..b69b8e7c 100644
--- a/hf_xet_wasm/examples/simple.rs
+++ b/hf_xet_wasm/examples/simple.rs
@@ -6,9 +6,9 @@ use tokio::sync::mpsc;
use utils::auth::AuthConfig;
use wasm_bindgen::prelude::*;
use wasm_thread as thread;
-use wasm_xet::blob_reader::BlobReader;
-use wasm_xet::configurations::{DataConfig, RepoSalt, ShardConfig, TranslatorConfig};
-use wasm_xet::wasm_file_upload_session::FileUploadSession;
+use hf_xet_wasm::blob_reader::BlobReader;
+use hf_xet_wasm::configurations::{DataConfig, RepoSalt, ShardConfig, TranslatorConfig};
+use hf_xet_wasm::wasm_file_upload_session::FileUploadSession;
fn main() {
#[cfg(target_arch = "wasm32")]
@@ -20,7 +20,7 @@ fn main() {
#[cfg(not(target_arch = "wasm32"))]
env_logger::init_from_env(env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"));
- log::info!("Starting init wasm_xet...");
+ log::info!("Starting init hf_xet_wasm...");
log::info!("Done");
}
@@ -80,7 +80,7 @@ pub async fn test_async_blob_reader(file: web_sys::File) -> String {
let s: u32 = data_local.iter().map(|&x| x as u32).sum();
sum += s;
}
- o_tx.send(sum).await;
+ let _ = o_tx.send(sum).await;
})
}));
let Ok(()) = tx.send(data_local).await else {
@@ -91,7 +91,6 @@ pub async fn test_async_blob_reader(file: web_sys::File) -> String {
log::info!("data sent");
}
- let mut id = inputs.len() - 1;
for (id, input) in inputs.into_iter().enumerate() {
log::info!("closing input {id}");
drop(input);
@@ -167,7 +166,7 @@ pub async fn clean_file(file: web_sys::File, endpoint: String, jwt_token: String
log::info!("processed {total_read} bytes");
}
- let Ok((file_hash, metrics)) = handle.finish().await else {
+ let Ok((file_hash, _metrics)) = handle.finish().await else {
log::info!("failed to finish cleaner");
return "".to_owned();
};
diff --git a/hf_xet_wasm/examples/xet_meta.js b/hf_xet_wasm/examples/xet_meta.js
index 5703ff13..ba3d22e9 100644
--- a/hf_xet_wasm/examples/xet_meta.js
+++ b/hf_xet_wasm/examples/xet_meta.js
@@ -1,90 +1,90 @@
function xetMetadataOrNone(jsonData) {
- /**
- * Extract XET metadata from the HTTP body or return null if not found.
- *
- * @param {jsonData} - HTTP body in JSON to extract the XET metadata from.
- * @returns {XetMetadata|null} The extracted metadata or null if missing.
- */
+ /**
+ * Extract XET metadata from the HTTP body or return null if not found.
+ *
+ * @param {jsonData} - HTTP body in JSON to extract the XET metadata from.
+ * @returns {XetMetadata|null} The extracted metadata or null if missing.
+ */
- const xetEndpoint = jsonData.casUrl;
- const accessToken = jsonData.accessToken;
- const expiration = jsonData.exp;
+ const xetEndpoint = jsonData.casUrl;
+ const accessToken = jsonData.accessToken;
+ const expiration = jsonData.exp;
- if (xetEndpoint == undefined || accessToken == undefined || expiration == undefined) {
- return null;
- }
+ if (xetEndpoint == undefined || accessToken == undefined || expiration == undefined) {
+ return null;
+ }
- const expirationUnixEpoch = parseInt(expiration, 10);
- if (isNaN(expirationUnixEpoch)) {
- return null;
- }
+ const expirationUnixEpoch = parseInt(expiration, 10);
+ if (isNaN(expirationUnixEpoch)) {
+ return null;
+ }
- return {
- endpoint: xetEndpoint,
- accessToken: accessToken,
- expirationUnixEpoch: expirationUnixEpoch,
- };
+ return {
+ endpoint: xetEndpoint,
+ accessToken: accessToken,
+ expirationUnixEpoch: expirationUnixEpoch,
+ };
}
async function fetchXetMetadataFromRepoInfo({
- tokenType,
- repoId,
- repoType,
- headers,
- params = null
-}) {
- /**
- * Uses the repo info to request a XET access token from Hub.
- *
- * @param {string} tokenType - Type of the token to request: "read" or "write".
- * @param {string} repoId - A namespace (user or an organization) and a repo name separated by a `/`.
- * @param {string} repoType - Type of the repo to upload to: "model", "dataset", or "space".
- * @param {Object} headers - Headers to use for the request, including authorization headers and user agent.
- * @param {Object|null} params - Additional parameters to pass with the request.
- * @returns {Promise