style: cargo fmt after Phase A

Whitespace + import-grouping fixups in the 9 SDK modules touched by
F-Q-002. No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-06-07 20:02:19 +02:00
parent ae5cf80426
commit 6f2bd3e949
8 changed files with 76 additions and 41 deletions

View File

@@ -16,9 +16,9 @@
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use super::bridge::block_on;
use picloud_shared::{DeadLetterId, SdkCallCx, Services}; use picloud_shared::{DeadLetterId, SdkCallCx, Services};
use rhai::{Engine as RhaiEngine, EvalAltResult, Module}; use rhai::{Engine as RhaiEngine, EvalAltResult, Module};
use super::bridge::block_on;
use uuid::Uuid; use uuid::Uuid;
pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<SdkCallCx>) { pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<SdkCallCx>) {
@@ -47,7 +47,9 @@ pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<Sdk
let reason = reason.to_string(); let reason = reason.to_string();
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
block_on("dead_letters", async move { svc.resolve(&cx, dl_id, &reason).await }) block_on("dead_letters", async move {
svc.resolve(&cx, dl_id, &reason).await
})
}, },
); );
} }
@@ -65,4 +67,3 @@ fn parse_dl_id(s: &str) -> Result<DeadLetterId, Box<EvalAltResult>> {
.into() .into()
}) })
} }

View File

@@ -78,7 +78,9 @@ fn register_create(engine: &mut RhaiEngine) {
|handle: &mut DocsHandle, data: Map| -> Result<String, Box<EvalAltResult>> { |handle: &mut DocsHandle, data: Map| -> Result<String, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let json = dynamic_to_json(&Dynamic::from(data)); let json = dynamic_to_json(&Dynamic::from(data));
let id = block_on("docs", async move { h.service.create(&h.cx, &h.collection, json).await })?; let id = block_on("docs", async move {
h.service.create(&h.cx, &h.collection, json).await
})?;
Ok(id.to_string()) Ok(id.to_string())
}, },
); );
@@ -90,8 +92,9 @@ fn register_get(engine: &mut RhaiEngine) {
|handle: &mut DocsHandle, id: &str| -> Result<Dynamic, Box<EvalAltResult>> { |handle: &mut DocsHandle, id: &str| -> Result<Dynamic, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let parsed_id = parse_doc_id(id)?; let parsed_id = parse_doc_id(id)?;
let row = let row = block_on("docs", async move {
block_on("docs", async move { h.service.get(&h.cx, &h.collection, parsed_id).await })?; h.service.get(&h.cx, &h.collection, parsed_id).await
})?;
Ok(row.map_or(Dynamic::UNIT, |d| Dynamic::from(doc_to_map(&d)))) Ok(row.map_or(Dynamic::UNIT, |d| Dynamic::from(doc_to_map(&d))))
}, },
); );
@@ -103,7 +106,9 @@ fn register_find(engine: &mut RhaiEngine) {
|handle: &mut DocsHandle, filter: Map| -> Result<Array, Box<EvalAltResult>> { |handle: &mut DocsHandle, filter: Map| -> Result<Array, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let json = dynamic_to_json(&Dynamic::from(filter)); let json = dynamic_to_json(&Dynamic::from(filter));
let rows = block_on("docs", async move { h.service.find(&h.cx, &h.collection, json).await })?; let rows = block_on("docs", async move {
h.service.find(&h.cx, &h.collection, json).await
})?;
Ok(rows Ok(rows
.iter() .iter()
.map(|d| Dynamic::from(doc_to_map(d))) .map(|d| Dynamic::from(doc_to_map(d)))
@@ -118,8 +123,9 @@ fn register_find_one(engine: &mut RhaiEngine) {
|handle: &mut DocsHandle, filter: Map| -> Result<Dynamic, Box<EvalAltResult>> { |handle: &mut DocsHandle, filter: Map| -> Result<Dynamic, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let json = dynamic_to_json(&Dynamic::from(filter)); let json = dynamic_to_json(&Dynamic::from(filter));
let row = let row = block_on("docs", async move {
block_on("docs", async move { h.service.find_one(&h.cx, &h.collection, json).await })?; h.service.find_one(&h.cx, &h.collection, json).await
})?;
Ok(row.map_or(Dynamic::UNIT, |d| Dynamic::from(doc_to_map(&d)))) Ok(row.map_or(Dynamic::UNIT, |d| Dynamic::from(doc_to_map(&d))))
}, },
); );
@@ -147,7 +153,9 @@ fn register_delete(engine: &mut RhaiEngine) {
|handle: &mut DocsHandle, id: &str| -> Result<bool, Box<EvalAltResult>> { |handle: &mut DocsHandle, id: &str| -> Result<bool, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let parsed_id = parse_doc_id(id)?; let parsed_id = parse_doc_id(id)?;
block_on("docs", async move { h.service.delete(&h.cx, &h.collection, parsed_id).await }) block_on("docs", async move {
h.service.delete(&h.cx, &h.collection, parsed_id).await
})
}, },
); );
} }
@@ -231,4 +239,3 @@ fn parse_doc_id(id: &str) -> Result<DocId, Box<EvalAltResult>> {
.into() .into()
}) })
} }

View File

@@ -26,9 +26,9 @@
use std::sync::Arc; use std::sync::Arc;
use super::bridge::block_on;
use picloud_shared::{OutboundEmail, SdkCallCx, Services}; use picloud_shared::{OutboundEmail, SdkCallCx, Services};
use rhai::{Array, Engine as RhaiEngine, EvalAltResult, Map, Module}; use rhai::{Array, Engine as RhaiEngine, EvalAltResult, Map, Module};
use super::bridge::block_on;
pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<SdkCallCx>) { pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<SdkCallCx>) {
let svc = services.email.clone(); let svc = services.email.clone();
@@ -129,4 +129,3 @@ fn addresses(opts: &Map, key: &str) -> Result<Vec<String>, Box<EvalAltResult>> {
fn runtime_err(msg: &str) -> Box<EvalAltResult> { fn runtime_err(msg: &str) -> Box<EvalAltResult> {
EvalAltResult::ErrorRuntime(msg.into(), rhai::Position::NONE).into() EvalAltResult::ErrorRuntime(msg.into(), rhai::Position::NONE).into()
} }

View File

@@ -23,9 +23,9 @@
use std::sync::Arc; use std::sync::Arc;
use super::bridge::block_on;
use picloud_shared::{FileMeta, FileUpdate, FilesService, NewFile, SdkCallCx, Services}; use picloud_shared::{FileMeta, FileUpdate, FilesService, NewFile, SdkCallCx, Services};
use rhai::{Array, Dynamic, Engine as RhaiEngine, EvalAltResult, Map, Module}; use rhai::{Array, Dynamic, Engine as RhaiEngine, EvalAltResult, Map, Module};
use super::bridge::block_on;
/// Per-call handle captured by the Rhai SDK. Cheap to clone (two Arcs /// Per-call handle captured by the Rhai SDK. Cheap to clone (two Arcs
/// plus an owned string). /// plus an owned string).
@@ -82,7 +82,9 @@ fn register_create(engine: &mut RhaiEngine) {
content_type, content_type,
data, data,
}; };
let id = block_on("files", async move { h.service.create(&h.cx, &h.collection, new).await })?; let id = block_on("files", async move {
h.service.create(&h.cx, &h.collection, new).await
})?;
Ok(id.to_string()) Ok(id.to_string())
}, },
); );
@@ -94,7 +96,9 @@ fn register_head(engine: &mut RhaiEngine) {
|handle: &mut FilesHandle, id: &str| -> Result<Dynamic, Box<EvalAltResult>> { |handle: &mut FilesHandle, id: &str| -> Result<Dynamic, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let id = id.to_string(); let id = id.to_string();
let meta = block_on("files", async move { h.service.head(&h.cx, &h.collection, &id).await })?; let meta = block_on("files", async move {
h.service.head(&h.cx, &h.collection, &id).await
})?;
Ok(meta.map_or(Dynamic::UNIT, |m| file_meta_to_map(&m).into())) Ok(meta.map_or(Dynamic::UNIT, |m| file_meta_to_map(&m).into()))
}, },
); );
@@ -106,7 +110,9 @@ fn register_get(engine: &mut RhaiEngine) {
|handle: &mut FilesHandle, id: &str| -> Result<Dynamic, Box<EvalAltResult>> { |handle: &mut FilesHandle, id: &str| -> Result<Dynamic, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let id = id.to_string(); let id = id.to_string();
let bytes = block_on("files", async move { h.service.get(&h.cx, &h.collection, &id).await })?; let bytes = block_on("files", async move {
h.service.get(&h.cx, &h.collection, &id).await
})?;
Ok(bytes.map_or(Dynamic::UNIT, Dynamic::from_blob)) Ok(bytes.map_or(Dynamic::UNIT, Dynamic::from_blob))
}, },
); );
@@ -126,7 +132,9 @@ fn register_update(engine: &mut RhaiEngine) {
name, name,
content_type, content_type,
}; };
block_on("files", async move { h.service.update(&h.cx, &h.collection, &id, upd).await }) block_on("files", async move {
h.service.update(&h.cx, &h.collection, &id, upd).await
})
}, },
); );
} }
@@ -137,7 +145,9 @@ fn register_delete(engine: &mut RhaiEngine) {
|handle: &mut FilesHandle, id: &str| -> Result<bool, Box<EvalAltResult>> { |handle: &mut FilesHandle, id: &str| -> Result<bool, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let id = id.to_string(); let id = id.to_string();
block_on("files", async move { h.service.delete(&h.cx, &h.collection, &id).await }) block_on("files", async move {
h.service.delete(&h.cx, &h.collection, &id).await
})
}, },
); );
} }
@@ -257,4 +267,3 @@ fn require_blob(meta: &Map, field: &'static str) -> Result<Vec<u8>, Box<EvalAltR
None => Err(format!("files: missing required field '{field}'").into()), None => Err(format!("files: missing required field '{field}'").into()),
} }
} }

View File

@@ -84,7 +84,9 @@ fn register_get(engine: &mut RhaiEngine) {
"get", "get",
|handle: &mut KvHandle, key: &str| -> Result<Dynamic, Box<EvalAltResult>> { |handle: &mut KvHandle, key: &str| -> Result<Dynamic, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
block_on("kv", async move { h.service.get(&h.cx, &h.collection, key).await }) block_on("kv", async move {
h.service.get(&h.cx, &h.collection, key).await
})
.map(|opt| opt.map_or(Dynamic::UNIT, json_to_dynamic)) .map(|opt| opt.map_or(Dynamic::UNIT, json_to_dynamic))
}, },
); );
@@ -96,7 +98,9 @@ fn register_set(engine: &mut RhaiEngine) {
|handle: &mut KvHandle, key: &str, value: Dynamic| -> Result<(), Box<EvalAltResult>> { |handle: &mut KvHandle, key: &str, value: Dynamic| -> Result<(), Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
let json = dynamic_to_json(&value); let json = dynamic_to_json(&value);
block_on("kv", async move { h.service.set(&h.cx, &h.collection, key, json).await }) block_on("kv", async move {
h.service.set(&h.cx, &h.collection, key, json).await
})
}, },
); );
} }
@@ -106,7 +110,9 @@ fn register_has(engine: &mut RhaiEngine) {
"has", "has",
|handle: &mut KvHandle, key: &str| -> Result<bool, Box<EvalAltResult>> { |handle: &mut KvHandle, key: &str| -> Result<bool, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
block_on("kv", async move { h.service.has(&h.cx, &h.collection, key).await }) block_on("kv", async move {
h.service.has(&h.cx, &h.collection, key).await
})
}, },
); );
} }
@@ -116,7 +122,9 @@ fn register_delete(engine: &mut RhaiEngine) {
"delete", "delete",
|handle: &mut KvHandle, key: &str| -> Result<bool, Box<EvalAltResult>> { |handle: &mut KvHandle, key: &str| -> Result<bool, Box<EvalAltResult>> {
let h = handle.clone(); let h = handle.clone();
block_on("kv", async move { h.service.delete(&h.cx, &h.collection, key).await }) block_on("kv", async move {
h.service.delete(&h.cx, &h.collection, key).await
})
}, },
); );
} }
@@ -166,4 +174,3 @@ fn list_call(
); );
Ok(m) Ok(m)
} }

View File

@@ -38,7 +38,9 @@ pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<Sdk
let json = message_to_json(&message); let json = message_to_json(&message);
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
block_on("pubsub", async move { svc.publish_durable(&cx, topic, json).await }) block_on("pubsub", async move {
svc.publish_durable(&cx, topic, json).await
})
}, },
); );
} }
@@ -158,4 +160,3 @@ fn message_to_json(value: &Dynamic) -> Json {
} }
Json::String(value.to_string()) Json::String(value.to_string())
} }

View File

@@ -81,8 +81,9 @@ pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<Sdk
let (cursor, limit) = parse_list_opts(&opts)?; let (cursor, limit) = parse_list_opts(&opts)?;
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
let page: SecretsListPage = let page: SecretsListPage = block_on("secrets", async move {
block_on("secrets", async move { svc.list(&cx, cursor.as_deref(), limit).await })?; svc.list(&cx, cursor.as_deref(), limit).await
})?;
Ok(list_page_to_map(page)) Ok(list_page_to_map(page))
}, },
); );
@@ -130,4 +131,3 @@ fn list_page_to_map(page: SecretsListPage) -> Map {
fn runtime_err(msg: &str) -> Box<EvalAltResult> { fn runtime_err(msg: &str) -> Box<EvalAltResult> {
EvalAltResult::ErrorRuntime(msg.into(), rhai::Position::NONE).into() EvalAltResult::ErrorRuntime(msg.into(), rhai::Position::NONE).into()
} }

View File

@@ -42,12 +42,12 @@
use std::sync::Arc; use std::sync::Arc;
use super::bridge::block_on;
use picloud_shared::{ use picloud_shared::{
AppUser, AppUserId, CreateUserInput, EmailTemplateOpts, GeneratedAccept, GeneratedSession, AppUser, AppUserId, CreateUserInput, EmailTemplateOpts, GeneratedAccept, GeneratedSession,
InviteOpts, SdkCallCx, Services, UpdateUserInput, UsersListOpts, UsersListPage, UsersService, InviteOpts, SdkCallCx, Services, UpdateUserInput, UsersListOpts, UsersListPage, UsersService,
}; };
use rhai::{Array, Dynamic, Engine as RhaiEngine, EvalAltResult, Map, Module}; use rhai::{Array, Dynamic, Engine as RhaiEngine, EvalAltResult, Map, Module};
use super::bridge::block_on;
pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<SdkCallCx>) { pub(super) fn register(engine: &mut RhaiEngine, services: &Services, cx: Arc<SdkCallCx>) {
let svc = services.users.clone(); let svc = services.users.clone();
@@ -198,8 +198,9 @@ fn bind_list(module: &mut Module, svc: &Arc<dyn UsersService>, cx: &Arc<SdkCallC
}; };
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
let page: UsersListPage = let page: UsersListPage = block_on("users", async move {
block_on("users", async move { svc.list(&cx, UsersListOpts { cursor, limit }).await })?; svc.list(&cx, UsersListOpts { cursor, limit }).await
})?;
Ok(list_page_to_map(&page)) Ok(list_page_to_map(&page))
}, },
); );
@@ -220,7 +221,10 @@ fn bind_login(module: &mut Module, svc: &Arc<dyn UsersService>, cx: &Arc<SdkCall
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
let session_opt: Option<GeneratedSession> = let session_opt: Option<GeneratedSession> =
block_on("users", async move { svc.login(&cx, &email, &password).await })?; block_on(
"users",
async move { svc.login(&cx, &email, &password).await },
)?;
Ok(session_opt.map_or(Dynamic::UNIT, |s| Dynamic::from(s.token))) Ok(session_opt.map_or(Dynamic::UNIT, |s| Dynamic::from(s.token)))
}, },
); );
@@ -273,7 +277,9 @@ fn bind_send_verification_email(
let opts = parse_email_template(&opts, "users::send_verification_email")?; let opts = parse_email_template(&opts, "users::send_verification_email")?;
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
block_on("users", async move { svc.send_verification_email(&cx, id, opts).await }) block_on("users", async move {
svc.send_verification_email(&cx, id, opts).await
})
}, },
); );
} }
@@ -307,7 +313,9 @@ fn bind_request_password_reset(
let opts = parse_email_template(&opts, "users::request_password_reset")?; let opts = parse_email_template(&opts, "users::request_password_reset")?;
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
block_on("users", async move { svc.request_password_reset(&cx, &email, opts).await }) block_on("users", async move {
svc.request_password_reset(&cx, &email, opts).await
})
}, },
); );
} }
@@ -365,8 +373,9 @@ fn bind_accept_invite(module: &mut Module, svc: &Arc<dyn UsersService>, cx: &Arc
let password = password.to_string(); let password = password.to_string();
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
let accept_opt: Option<GeneratedAccept> = let accept_opt: Option<GeneratedAccept> = block_on("users", async move {
block_on("users", async move { svc.accept_invite(&cx, &token, &password, None).await })?; svc.accept_invite(&cx, &token, &password, None).await
})?;
Ok(accept_opt.map_or(Dynamic::UNIT, |a| Dynamic::from(a.session.token))) Ok(accept_opt.map_or(Dynamic::UNIT, |a| Dynamic::from(a.session.token)))
}, },
); );
@@ -428,7 +437,10 @@ fn bind_remove_role(module: &mut Module, svc: &Arc<dyn UsersService>, cx: &Arc<S
let role = role.to_string(); let role = role.to_string();
let svc = svc.clone(); let svc = svc.clone();
let cx = cx.clone(); let cx = cx.clone();
block_on("users", async move { svc.remove_role(&cx, id, &role).await }) block_on(
"users",
async move { svc.remove_role(&cx, id, &role).await },
)
}, },
); );
} }
@@ -586,4 +598,3 @@ fn optional_string(opts: &Map, key: &str) -> Option<String> {
fn runtime_err(msg: &str) -> Box<EvalAltResult> { fn runtime_err(msg: &str) -> Box<EvalAltResult> {
EvalAltResult::ErrorRuntime(msg.into(), rhai::Position::NONE).into() EvalAltResult::ErrorRuntime(msg.into(), rhai::Position::NONE).into()
} }