Skip to main content

Mountain/IPC/WindServiceHandlers/Storage/
StorageGetItems.rs

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