Skip to main content

Mountain/IPC/WindServiceHandlers/Storage/
StorageGetItems.rs

1//! Bulk-read every key/value pair as `[key, value]` tuples.
2//! VS Code's `NativeWorkbenchStorageService` calls this exactly
3//! once at boot to hydrate its in-memory cache. Stringifies
4//! non-string values for wire-shape compatibility with the
5//! upstream `StorageDatabase` contract.
6
7use std::sync::Arc;
8
9use CommonLibrary::{Environment::Requires::Requires, Storage::StorageProvider::StorageProvider};
10use serde_json::{Value, json};
11
12use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
13
14pub async fn Fn(RunTime:Arc<ApplicationRunTime>, _Arguments:Vec<Value>) -> Result<Value, String> {
15	let provider:Arc<dyn StorageProvider> = RunTime.Environment.Require();
16
17	match provider.GetAllStorage(true).await {
18		Ok(State) => {
19			if let Some(Obj) = State.as_object() {
20				let Tuples:Vec<Value> = Obj
21					.iter()
22					.map(|(K, V)| {
23						let ValStr = match V {
24							Value::String(S) => S.clone(),
25							_ => V.to_string(),
26						};
27
28						json!([K, ValStr])
29					})
30					.collect();
31
32				Ok(json!(Tuples))
33			} else {
34				Ok(json!([]))
35			}
36		},
37
38		Err(_) => Ok(json!([])),
39	}
40}