Skip to main content

Mountain/IPC/WindServiceHandlers/Storage/
StorageGetItems.rs

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