diff --git a/ng-net/src/app_protocol.rs b/ng-net/src/app_protocol.rs index cefd749..993586a 100644 --- a/ng-net/src/app_protocol.rs +++ b/ng-net/src/app_protocol.rs @@ -222,12 +222,14 @@ impl NuriV0 { pub fn get_first_commit_ref(&self) -> Result { let commit_id = match &self.branch { - Some(TargetBranchV0::Commits(commits)) => commits.get(0).ok_or(NgError::CommitNotFound)?, - _ => return Err(NgError::InvalidNuri) + Some(TargetBranchV0::Commits(commits)) => { + commits.get(0).ok_or(NgError::CommitNotFound)? + } + _ => return Err(NgError::InvalidNuri), }; let commit_key = match self.access.get(0) { Some(NgAccessV0::Key(key)) => key, - _ => return Err(NgError::InvalidNuri) + _ => return Err(NgError::InvalidNuri), }; Ok(ObjectRef::from_id_key(*commit_id, commit_key.clone())) } @@ -335,7 +337,7 @@ impl NuriV0 { StoreRepoV0::ProtectedStore(id) => NuriV0::protected_profile(id), StoreRepoV0::PrivateStore(id) => NuriV0::private_store(id), StoreRepoV0::Group(id) => NuriV0::group_store(id), - StoreRepoV0::Dialog((id,_)) => NuriV0::dialog_store(id), + StoreRepoV0::Dialog((id, _)) => NuriV0::dialog_store(id), }, } } @@ -514,11 +516,9 @@ impl NuriV0 { } } - pub fn from_inbox_into_id(from: &String) -> Result { + pub fn from_inbox_into_id(from: &String) -> Result { let c = RE_INBOX.captures(&from); - if c.is_some() - && c.as_ref().unwrap().get(1).is_some() - { + if c.is_some() && c.as_ref().unwrap().get(1).is_some() { let cap = c.unwrap(); let d = cap.get(1).unwrap().as_str(); let to_inbox = decode_key(d)?; @@ -529,9 +529,7 @@ impl NuriV0 { pub fn from_profile_into_overlay_id(from: &String) -> Result { let c = RE_PROFILE.captures(&from); - if c.is_some() - && c.as_ref().unwrap().get(1).is_some() - { + if c.is_some() && c.as_ref().unwrap().get(1).is_some() { let cap = c.unwrap(); let o = cap.get(1).unwrap().as_str(); let to_profile_id = decode_key(o)?; @@ -562,7 +560,6 @@ impl NuriV0 { Err(NgError::InvalidNuri) } - pub fn new_from_repo_nuri(from: &String) -> Result { let repo_id = Self::from_repo_nuri_to_id(from)?; let mut n = Self::new_empty(); @@ -570,9 +567,7 @@ impl NuriV0 { return Ok(n); } - pub fn new_from_commit(from: &String) -> Result { - let c = RE_COMMIT.captures(&from); if c.is_some() && c.as_ref().unwrap().get(1).is_some() @@ -659,7 +654,6 @@ impl NuriV0 { locator: None, }) } else { - if let Ok(n) = NuriV0::new_from_repo_graph(from) { Ok(n) } else { @@ -810,12 +804,14 @@ impl AppRequest { session_id: 0, }) } - + pub fn new_orm_start(scope: NuriV0, shape_type: OrmShapeType) -> Self { AppRequest::new( AppRequestCommandV0::OrmStart, scope, - Some(AppRequestPayload::V0(AppRequestPayloadV0::OrmStart(shape_type))), + Some(AppRequestPayload::V0(AppRequestPayloadV0::OrmStart( + shape_type, + ))), ) } @@ -823,12 +819,13 @@ impl AppRequest { AppRequest::new( AppRequestCommandV0::OrmUpdate, scope, - Some(AppRequestPayload::V0(AppRequestPayloadV0::OrmUpdate((diff,shape_type_name)))), + Some(AppRequestPayload::V0(AppRequestPayloadV0::OrmUpdate(( + diff, + shape_type_name, + )))), ) } - - pub fn inbox_post(post: InboxPost) -> Self { AppRequest::new( AppRequestCommandV0::InboxPost, @@ -838,30 +835,26 @@ impl AppRequest { } pub fn social_query_start( - from_profile: NuriV0, - query: NuriV0, - contacts: String, + from_profile: NuriV0, + query: NuriV0, + contacts: String, degree: u16, ) -> Self { AppRequest::new( AppRequestCommandV0::SocialQueryStart, query, - Some(AppRequestPayload::V0(AppRequestPayloadV0::SocialQueryStart{ - from_profile, - contacts, - degree - })), + Some(AppRequestPayload::V0( + AppRequestPayloadV0::SocialQueryStart { + from_profile, + contacts, + degree, + }, + )), ) } - pub fn social_query_cancel( - query: NuriV0, - ) -> Self { - AppRequest::new( - AppRequestCommandV0::SocialQueryCancel, - query, - None - ) + pub fn social_query_cancel(query: NuriV0) -> Self { + AppRequest::new(AppRequestCommandV0::SocialQueryCancel, query, None) } pub fn doc_fetch_repo_subscribe(repo_o: String) -> Result { @@ -1054,8 +1047,8 @@ pub enum AppRequestPayloadV0 { InboxPost(InboxPost), SocialQueryStart { - from_profile: NuriV0, - contacts: String, + from_profile: NuriV0, + contacts: String, degree: u16, }, //RemoveFile @@ -1064,7 +1057,7 @@ pub enum AppRequestPayloadV0 { QrCodeProfileImport(String), OrmStart(OrmShapeType), OrmUpdate((OrmDiff, String)), // ShapeID - OrmStop(String), //ShapeID + OrmStop(String), //ShapeID } #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/ng-net/src/orm.rs b/ng-net/src/orm.rs index 84376b7..f378b99 100644 --- a/ng-net/src/orm.rs +++ b/ng-net/src/orm.rs @@ -9,6 +9,8 @@ * according to those terms. */ +#![allow(non_snake_case)] + use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -19,6 +21,25 @@ pub struct OrmShapeType { } #[derive(Clone, Debug, Serialize, Deserialize)] -pub struct OrmDiff { +#[allow(non_camel_case_types)] +pub enum OrmDiffOpType { + add, + remove, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +#[allow(non_camel_case_types)] +pub enum OrmDiffType { + set, + object, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct OrmDiffOp { + pub op: OrmDiffOpType, + pub valType: Option, + pub path: String, + pub value: Option, +} -} \ No newline at end of file +pub type OrmDiff = Vec; diff --git a/ng-verifier/src/orm.rs b/ng-verifier/src/orm.rs index 2e1e806..824f391 100644 --- a/ng-verifier/src/orm.rs +++ b/ng-verifier/src/orm.rs @@ -12,35 +12,35 @@ use std::collections::HashMap; use futures::channel::mpsc; use futures::SinkExt; -pub use ng_net::orm::OrmShapeType; -pub use ng_net::orm::OrmDiff; -use ng_oxigraph::oxigraph::sparql::{results::*, Query, QueryResults}; -use ng_oxigraph::oxrdf::Term; -use ng_oxigraph::oxrdf::Triple; -use ng_repo::log::*; use ng_net::app_protocol::*; +pub use ng_net::orm::OrmDiff; +pub use ng_net::orm::OrmShapeType; use ng_net::{ connection::NoiseFSM, types::*, utils::{Receiver, Sender}, }; +use ng_oxigraph::oxigraph::sparql::{results::*, Query, QueryResults}; +use ng_oxigraph::oxrdf::Term; +use ng_oxigraph::oxrdf::Triple; use ng_repo::errors::NgError; +use ng_repo::log::*; use crate::types::*; use crate::verifier::*; impl Verifier { - fn sparql_construct(&self, query: String) -> Result, NgError> { let oxistore = self.graph_dataset.as_ref().unwrap(); - + // let graph_nuri = NuriV0::repo_graph_name( // &update.repo_id, // &update.overlay_id, // ); //let base = NuriV0::repo_id(&repo.id); - let parsed = Query::parse(&query, None).map_err(|e| NgError::OxiGraphError(e.to_string()))?; + let parsed = + Query::parse(&query, None).map_err(|e| NgError::OxiGraphError(e.to_string()))?; let results = oxistore .query(parsed, None) .map_err(|e| NgError::OxiGraphError(e.to_string()))?; @@ -49,7 +49,10 @@ impl Verifier { let mut results = vec![]; for t in triples { match t { - Err(e) => { log_err!("{}",e.to_string()); return Err(NgError::SparqlError(e.to_string()))}, + Err(e) => { + log_err!("{}", e.to_string()); + return Err(NgError::SparqlError(e.to_string())); + } Ok(triple) => results.push(triple), } } @@ -61,14 +64,15 @@ impl Verifier { fn sparql_select(&self, query: String) -> Result>>, NgError> { let oxistore = self.graph_dataset.as_ref().unwrap(); - + // let graph_nuri = NuriV0::repo_graph_name( // &update.repo_id, // &update.overlay_id, // ); //let base = NuriV0::repo_id(&repo.id); - let parsed = Query::parse(&query, None).map_err(|e| NgError::OxiGraphError(e.to_string()))?; + let parsed = + Query::parse(&query, None).map_err(|e| NgError::OxiGraphError(e.to_string()))?; let results = oxistore .query(parsed, None) .map_err(|e| NgError::OxiGraphError(e.to_string()))?; @@ -77,7 +81,10 @@ impl Verifier { let mut results = vec![]; for t in sols { match t { - Err(e) => { log_err!("{}",e.to_string()); return Err(NgError::SparqlError(e.to_string()))}, + Err(e) => { + log_err!("{}", e.to_string()); + return Err(NgError::SparqlError(e.to_string())); + } Ok(querysol) => results.push(querysol.values().to_vec()), } } @@ -87,15 +94,23 @@ impl Verifier { } } - pub(crate) async fn orm_update(&mut self, scope: &NuriV0, patch: GraphQuadsPatch) { - - } - - pub(crate) async fn frontend_update_orm(&mut self, scope: &NuriV0, shape_id: String, diff: OrmDiff) { + pub(crate) async fn orm_update(&mut self, scope: &NuriV0, patch: GraphQuadsPatch) {} + pub(crate) async fn frontend_update_orm( + &mut self, + scope: &NuriV0, + shape_id: String, + diff: OrmDiff, + ) { + log_info!("frontend_update_orm {:?} {} {:?}", scope, shape_id, diff); } - pub(crate) async fn push_orm_response(&mut self, scope: &NuriV0, schema_iri: &String, response: AppResponse) { + pub(crate) async fn push_orm_response( + &mut self, + scope: &NuriV0, + schema_iri: &String, + response: AppResponse, + ) { log_info!( "push_orm_response {:?} {} {:?}", scope, @@ -104,7 +119,7 @@ impl Verifier { ); if let Some(shapes) = self.orm_subscriptions.get_mut(scope) { if let Some(sessions) = shapes.get_mut(schema_iri) { - let mut sessions_to_close : Vec = vec![]; + let mut sessions_to_close: Vec = vec![]; for (session_id, sender) in sessions.iter_mut() { if sender.is_closed() { log_debug!("closed so removing session {}", session_id); @@ -126,10 +141,15 @@ impl Verifier { schema: &OrmShapeType, session_id: u64, ) -> Result<(Receiver, CancelFn), NgError> { - let (tx, rx) = mpsc::unbounded::(); - self.orm_subscriptions.insert(nuri.clone(), HashMap::from([(schema.iri.clone(), HashMap::from([(session_id, tx.clone())]))])); + self.orm_subscriptions.insert( + nuri.clone(), + HashMap::from([( + schema.iri.clone(), + HashMap::from([(session_id, tx.clone())]), + )]), + ); //self.push_orm_response().await; @@ -141,4 +161,4 @@ impl Verifier { }); Ok((rx, close)) } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f2a7be0..05b3cdc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,6 +41,9 @@ importers: '@nextgraph-monorepo/ng-alien-deepsignals': specifier: workspace:* version: link:../../ng-alien-deepsignals + '@nextgraph-monorepo/ng-sdk-js': + specifier: workspace:* + version: link:../../pkg '@nextgraph-monorepo/ng-shex-orm': specifier: workspace:* version: link:../../ng-shex-orm @@ -80,6 +83,12 @@ importers: svelte: specifier: 5.38.2 version: 5.38.2 + vite-plugin-top-level-await: + specifier: ^1.6.0 + version: 1.6.0(@swc/helpers@0.5.17)(rollup@4.50.2)(vite@7.1.3(@types/node@24.3.0)(jiti@2.5.1)) + vite-plugin-wasm: + specifier: ^3.5.0 + version: 3.5.0(vite@7.1.3(@types/node@24.3.0)(jiti@2.5.1)) vue: specifier: 3.5.19 version: 3.5.19(typescript@5.9.2) @@ -114,7 +123,7 @@ importers: version: 9.11.1(magicast@0.3.5) tsup: specifier: ^8.3.5 - version: 8.5.0(jiti@2.5.1)(postcss@8.5.6)(typescript@5.9.2) + version: 8.5.0(@swc/core@1.13.5(@swc/helpers@0.5.17))(jiti@2.5.1)(postcss@8.5.6)(typescript@5.9.2) typescript: specifier: ^5.4.3 version: 5.9.2 @@ -1055,6 +1064,15 @@ packages: '@rolldown/pluginutils@1.0.0-beta.38': resolution: {integrity: sha512-N/ICGKleNhA5nc9XXQG/kkKHJ7S55u0x0XUJbbkmdCnFuoRkM1Il12q9q0eX19+M7KKUEPw/daUPIRnxhcxAIw==} + '@rollup/plugin-virtual@3.0.2': + resolution: {integrity: sha512-10monEYsBp3scM4/ND4LNH5Rxvh3e/cVeL3jWTgZ2SrQ+BmUoQcopVQvnaMcOnykb1VkxUFuDAN+0FnpTFRy2A==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + '@rollup/pluginutils@5.3.0': resolution: {integrity: sha512-5EdhGZtnu3V88ces7s53hhfK5KSASnJZv8Lulpc04cWO3REESroJXg73DFsOmgbU2BhwV0E20bu2IDZb3VKW4Q==} engines: {node: '>=14.0.0'} @@ -1268,9 +1286,87 @@ packages: svelte: ^5.0.0 vite: ^6.0.0 + '@swc/core-darwin-arm64@1.13.5': + resolution: {integrity: sha512-lKNv7SujeXvKn16gvQqUQI5DdyY8v7xcoO3k06/FJbHJS90zEwZdQiMNRiqpYw/orU543tPaWgz7cIYWhbopiQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [darwin] + + '@swc/core-darwin-x64@1.13.5': + resolution: {integrity: sha512-ILd38Fg/w23vHb0yVjlWvQBoE37ZJTdlLHa8LRCFDdX4WKfnVBiblsCU9ar4QTMNdeTBEX9iUF4IrbNWhaF1Ng==} + engines: {node: '>=10'} + cpu: [x64] + os: [darwin] + + '@swc/core-linux-arm-gnueabihf@1.13.5': + resolution: {integrity: sha512-Q6eS3Pt8GLkXxqz9TAw+AUk9HpVJt8Uzm54MvPsqp2yuGmY0/sNaPPNVqctCX9fu/Nu8eaWUen0si6iEiCsazQ==} + engines: {node: '>=10'} + cpu: [arm] + os: [linux] + + '@swc/core-linux-arm64-gnu@1.13.5': + resolution: {integrity: sha512-aNDfeN+9af+y+M2MYfxCzCy/VDq7Z5YIbMqRI739o8Ganz6ST+27kjQFd8Y/57JN/hcnUEa9xqdS3XY7WaVtSw==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + + '@swc/core-linux-arm64-musl@1.13.5': + resolution: {integrity: sha512-9+ZxFN5GJag4CnYnq6apKTnnezpfJhCumyz0504/JbHLo+Ue+ZtJnf3RhyA9W9TINtLE0bC4hKpWi8ZKoETyOQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + + '@swc/core-linux-x64-gnu@1.13.5': + resolution: {integrity: sha512-WD530qvHrki8Ywt/PloKUjaRKgstQqNGvmZl54g06kA+hqtSE2FTG9gngXr3UJxYu/cNAjJYiBifm7+w4nbHbA==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + + '@swc/core-linux-x64-musl@1.13.5': + resolution: {integrity: sha512-Luj8y4OFYx4DHNQTWjdIuKTq2f5k6uSXICqx+FSabnXptaOBAbJHNbHT/06JZh6NRUouaf0mYXN0mcsqvkhd7Q==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + + '@swc/core-win32-arm64-msvc@1.13.5': + resolution: {integrity: sha512-cZ6UpumhF9SDJvv4DA2fo9WIzlNFuKSkZpZmPG1c+4PFSEMy5DFOjBSllCvnqihCabzXzpn6ykCwBmHpy31vQw==} + engines: {node: '>=10'} + cpu: [arm64] + os: [win32] + + '@swc/core-win32-ia32-msvc@1.13.5': + resolution: {integrity: sha512-C5Yi/xIikrFUzZcyGj9L3RpKljFvKiDMtyDzPKzlsDrKIw2EYY+bF88gB6oGY5RGmv4DAX8dbnpRAqgFD0FMEw==} + engines: {node: '>=10'} + cpu: [ia32] + os: [win32] + + '@swc/core-win32-x64-msvc@1.13.5': + resolution: {integrity: sha512-YrKdMVxbYmlfybCSbRtrilc6UA8GF5aPmGKBdPvjrarvsmf4i7ZHGCEnLtfOMd3Lwbs2WUZq3WdMbozYeLU93Q==} + engines: {node: '>=10'} + cpu: [x64] + os: [win32] + + '@swc/core@1.13.5': + resolution: {integrity: sha512-WezcBo8a0Dg2rnR82zhwoR6aRNxeTGfK5QCD6TQ+kg3xx/zNT02s/0o+81h/3zhvFSB24NtqEr8FTw88O5W/JQ==} + engines: {node: '>=10'} + peerDependencies: + '@swc/helpers': '>=0.5.17' + peerDependenciesMeta: + '@swc/helpers': + optional: true + + '@swc/counter@0.1.3': + resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} + '@swc/helpers@0.5.17': resolution: {integrity: sha512-5IKx/Y13RsYd+sauPb2x+U/xZikHjolzfuDgTAl/Tdf3Q8rslRvC19NKDLgAJQ6wsqADk10ntlv08nPFw/gO/A==} + '@swc/types@0.1.25': + resolution: {integrity: sha512-iAoY/qRhNH8a/hBvm3zKj9qQ4oc2+3w1unPJa2XvTK3XjeLXtzcCingVPw/9e5mn1+0yPqxcBGp9Jf0pkfMb1g==} + + '@swc/wasm@1.13.5': + resolution: {integrity: sha512-ZBZcxieydxNwgEU9eFAXGMaDb1Xoh+ZkZcUQ27LNJzc2lPSByoL6CSVqnYiaVo+n9JgqbYyHlMq+i7z0wRNTfA==} + '@ts-jison/common@0.4.1-alpha.1': resolution: {integrity: sha512-SDbHzq+UMD+V3ciKVBHwCEgVqSeyQPTCjOsd/ZNTGySUVg4x3EauR9ZcEfdVFAsYRR38XWgDI+spq5LDY46KvQ==} @@ -4024,6 +4120,10 @@ packages: util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + uuid@10.0.0: + resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==} + hasBin: true + uuid@8.3.2: resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} hasBin: true @@ -4060,6 +4160,11 @@ packages: '@nuxt/kit': optional: true + vite-plugin-top-level-await@1.6.0: + resolution: {integrity: sha512-bNhUreLamTIkoulCR9aDXbTbhLk6n1YE8NJUTTxl5RYskNRtzOR0ASzSjBVRtNdjIfngDXo11qOsybGLNsrdww==} + peerDependencies: + vite: '>=2.8' + vite-plugin-vue-devtools@7.7.7: resolution: {integrity: sha512-d0fIh3wRcgSlr4Vz7bAk4va1MkdqhQgj9ANE/rBhsAjOnRfTLs2ocjFMvSUOsv6SRRXU9G+VM7yMgqDb6yI4iQ==} engines: {node: '>=v14.21.3'} @@ -4071,6 +4176,11 @@ packages: peerDependencies: vite: ^3.0.0-0 || ^4.0.0-0 || ^5.0.0-0 || ^6.0.0-0 || ^7.0.0-0 + vite-plugin-wasm@3.5.0: + resolution: {integrity: sha512-X5VWgCnqiQEGb+omhlBVsvTfxikKtoOgAzQ95+BZ8gQ+VfMHIjSHr0wyvXFQCa0eKQ0fKyaL0kWcEnYqBac4lQ==} + peerDependencies: + vite: ^2 || ^3 || ^4 || ^5 || ^6 || ^7 + vite@6.3.6: resolution: {integrity: sha512-0msEVHJEScQbhkbVTb/4iHZdJ6SXp/AvxL2sjwYQFfBqleHtnCqv1J3sa9zbWz/6kW1m9Tfzn92vW+kZ1WV6QA==} engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} @@ -5334,6 +5444,10 @@ snapshots: '@rolldown/pluginutils@1.0.0-beta.38': {} + '@rollup/plugin-virtual@3.0.2(rollup@4.50.2)': + optionalDependencies: + rollup: 4.50.2 + '@rollup/pluginutils@5.3.0(rollup@4.50.2)': dependencies: '@types/estree': 1.0.8 @@ -5534,10 +5648,65 @@ snapshots: transitivePeerDependencies: - supports-color + '@swc/core-darwin-arm64@1.13.5': + optional: true + + '@swc/core-darwin-x64@1.13.5': + optional: true + + '@swc/core-linux-arm-gnueabihf@1.13.5': + optional: true + + '@swc/core-linux-arm64-gnu@1.13.5': + optional: true + + '@swc/core-linux-arm64-musl@1.13.5': + optional: true + + '@swc/core-linux-x64-gnu@1.13.5': + optional: true + + '@swc/core-linux-x64-musl@1.13.5': + optional: true + + '@swc/core-win32-arm64-msvc@1.13.5': + optional: true + + '@swc/core-win32-ia32-msvc@1.13.5': + optional: true + + '@swc/core-win32-x64-msvc@1.13.5': + optional: true + + '@swc/core@1.13.5(@swc/helpers@0.5.17)': + dependencies: + '@swc/counter': 0.1.3 + '@swc/types': 0.1.25 + optionalDependencies: + '@swc/core-darwin-arm64': 1.13.5 + '@swc/core-darwin-x64': 1.13.5 + '@swc/core-linux-arm-gnueabihf': 1.13.5 + '@swc/core-linux-arm64-gnu': 1.13.5 + '@swc/core-linux-arm64-musl': 1.13.5 + '@swc/core-linux-x64-gnu': 1.13.5 + '@swc/core-linux-x64-musl': 1.13.5 + '@swc/core-win32-arm64-msvc': 1.13.5 + '@swc/core-win32-ia32-msvc': 1.13.5 + '@swc/core-win32-x64-msvc': 1.13.5 + '@swc/helpers': 0.5.17 + + '@swc/counter@0.1.3': {} + '@swc/helpers@0.5.17': dependencies: tslib: 2.8.1 + '@swc/types@0.1.25': + dependencies: + '@swc/counter': 0.1.3 + + '@swc/wasm@1.13.5': {} + '@ts-jison/common@0.4.1-alpha.1': {} '@ts-jison/lexer@0.4.1-alpha.1': @@ -8761,7 +8930,7 @@ snapshots: tslib@2.8.1: {} - tsup@8.5.0(jiti@2.5.1)(postcss@8.5.6)(typescript@5.9.2): + tsup@8.5.0(@swc/core@1.13.5(@swc/helpers@0.5.17))(jiti@2.5.1)(postcss@8.5.6)(typescript@5.9.2): dependencies: bundle-require: 5.1.0(esbuild@0.25.9) cac: 6.7.14 @@ -8781,6 +8950,7 @@ snapshots: tinyglobby: 0.2.15 tree-kill: 1.2.2 optionalDependencies: + '@swc/core': 1.13.5(@swc/helpers@0.5.17) postcss: 8.5.6 typescript: 5.9.2 transitivePeerDependencies: @@ -8910,6 +9080,8 @@ snapshots: util-deprecate@1.0.2: {} + uuid@10.0.0: {} + uuid@8.3.2: {} validate-iri@1.0.1: {} @@ -8991,6 +9163,17 @@ snapshots: - rollup - supports-color + vite-plugin-top-level-await@1.6.0(@swc/helpers@0.5.17)(rollup@4.50.2)(vite@7.1.3(@types/node@24.3.0)(jiti@2.5.1)): + dependencies: + '@rollup/plugin-virtual': 3.0.2(rollup@4.50.2) + '@swc/core': 1.13.5(@swc/helpers@0.5.17) + '@swc/wasm': 1.13.5 + uuid: 10.0.0 + vite: 7.1.3(@types/node@24.3.0)(jiti@2.5.1) + transitivePeerDependencies: + - '@swc/helpers' + - rollup + vite-plugin-vue-devtools@7.7.7(rollup@4.50.2)(vite@6.3.6(@types/node@24.3.0)(jiti@2.5.1))(vue@3.5.19(typescript@5.9.2)): dependencies: '@vue/devtools-core': 7.7.7(vite@6.3.6(@types/node@24.3.0)(jiti@2.5.1))(vue@3.5.19(typescript@5.9.2)) @@ -9022,6 +9205,10 @@ snapshots: transitivePeerDependencies: - supports-color + vite-plugin-wasm@3.5.0(vite@7.1.3(@types/node@24.3.0)(jiti@2.5.1)): + dependencies: + vite: 7.1.3(@types/node@24.3.0)(jiti@2.5.1) + vite@6.3.6(@types/node@24.3.0)(jiti@2.5.1): dependencies: esbuild: 0.25.9 diff --git a/sdk/ng-sdk-js/examples/multi-framework-signals/astro.config.mjs b/sdk/ng-sdk-js/examples/multi-framework-signals/astro.config.mjs index e7d8371..d81423e 100644 --- a/sdk/ng-sdk-js/examples/multi-framework-signals/astro.config.mjs +++ b/sdk/ng-sdk-js/examples/multi-framework-signals/astro.config.mjs @@ -4,8 +4,14 @@ import react from "@astrojs/react"; import vue from "@astrojs/vue"; import svelte from "@astrojs/svelte"; +import wasm from "vite-plugin-wasm"; +import topLevelAwait from "vite-plugin-top-level-await"; + // https://astro.build/config export default defineConfig({ - integrations: [react(), vue(), svelte()], - srcDir: "./src/app", + integrations: [react(), vue(), svelte()], + srcDir: "./src/app", + vite: { + plugins: [topLevelAwait(), wasm()], + }, }); diff --git a/sdk/ng-sdk-js/examples/multi-framework-signals/package.json b/sdk/ng-sdk-js/examples/multi-framework-signals/package.json index 377ce04..6733498 100644 --- a/sdk/ng-sdk-js/examples/multi-framework-signals/package.json +++ b/sdk/ng-sdk-js/examples/multi-framework-signals/package.json @@ -15,7 +15,10 @@ }, "dependencies": { "@nextgraph-monorepo/ng-signals": "workspace:*", + "@nextgraph-monorepo/ng-sdk-js": "workspace:*", "@astrojs/react": "4.3.0", + "vite-plugin-wasm": "^3.5.0", + "vite-plugin-top-level-await": "^1.6.0", "@astrojs/svelte": "7.1.0", "@astrojs/vue": "^5.1.0", "@gn8/alien-signals-react": "^0.1.1", diff --git a/sdk/ng-sdk-js/examples/multi-framework-signals/src/ng-mock/wasm-land/shapeHandler.ts b/sdk/ng-sdk-js/examples/multi-framework-signals/src/ng-mock/wasm-land/shapeHandler.ts index 61eafab..9648e3e 100644 --- a/sdk/ng-sdk-js/examples/multi-framework-signals/src/ng-mock/wasm-land/shapeHandler.ts +++ b/sdk/ng-sdk-js/examples/multi-framework-signals/src/ng-mock/wasm-land/shapeHandler.ts @@ -99,7 +99,7 @@ communicationChannel.addEventListener( const { type, connectionId, shapeType } = event.data; if (type === "Request") { - + ng.orm_update("", "", {}, 1); /* unsub = await ng.orm_start(scope, shapeType, session_id, async (response) => { //console.log("GOT APP RESPONSE", response); @@ -164,3 +164,10 @@ communicationChannel.addEventListener( ); } ); + +ng.orm_update( + "", + "", + [{ op: "add", valType: "set", value: 1, path: "/foo/bar" }], + 1 +).catch((err) => console.error(err)); diff --git a/sdk/ng-sdk-js/ng-signals/src/connector/applyDiff.ts b/sdk/ng-sdk-js/ng-signals/src/connector/applyDiff.ts index 8e2115e..b6ea79a 100644 --- a/sdk/ng-sdk-js/ng-signals/src/connector/applyDiff.ts +++ b/sdk/ng-sdk-js/ng-signals/src/connector/applyDiff.ts @@ -3,7 +3,7 @@ import { batch } from "@nextgraph-monorepo/ng-alien-deepsignals"; export type Patch = { /** Property path (array indices, object keys, synthetic Set entry ids) from the root to the mutated location. */ path: string; - type?: string & {}; + valType?: string & {}; value?: unknown; } & ( | SetAddPatch @@ -16,7 +16,7 @@ export type Patch = { export interface SetAddPatch { /** Mutation kind applied at the resolved `path`. */ op: "add"; - type: "set"; + valType: "set"; /** * New value for set mutations: * - A single primitive @@ -34,7 +34,7 @@ export interface SetAddPatch { export interface SetRemovePatch { /** Mutation kind applied at the resolved `path`. */ op: "remove"; - type: "set"; + valType: "set"; /** * The value(s) to be removed from the set. Either: * - A single primitive / id @@ -46,7 +46,7 @@ export interface SetRemovePatch { export interface ObjectAddPatch { /** Mutation kind applied at the resolved `path`. */ op: "add"; - type: "object"; + valType: "object"; } export interface RemovePatch { @@ -158,7 +158,7 @@ export function applyDiff( if (parentVal == null || typeof parentVal !== "object") continue; // Handle set additions - if (patch.op === "add" && patch.type === "set") { + if (patch.op === "add" && patch.valType === "set") { const existing = parentVal[key]; // Normalize value @@ -212,7 +212,7 @@ export function applyDiff( } // Handle set removals - if (patch.op === "remove" && patch.type === "set") { + if (patch.op === "remove" && patch.valType === "set") { const existing = parentVal[key]; const raw = (patch as SetRemovePatch).value; if (raw == null) continue; @@ -229,7 +229,7 @@ export function applyDiff( } // Add object (ensure object exists) - if (patch.op === "add" && patch.type === "object") { + if (patch.op === "add" && patch.valType === "object") { const cur = parentVal[key]; if ( cur === undefined || diff --git a/sdk/ng-sdk-js/src/lib.rs b/sdk/ng-sdk-js/src/lib.rs index fe2445e..0a10035 100644 --- a/sdk/ng-sdk-js/src/lib.rs +++ b/sdk/ng-sdk-js/src/lib.rs @@ -41,7 +41,10 @@ use ng_repo::utils::{decode_key, decode_priv_key}; use ng_net::app_protocol::*; use ng_net::broker::*; -use ng_net::types::{BindAddress, ClientInfo, ClientInfoV0, ClientType, CreateAccountBSP, IP, BootstrapContentV0, InboxPost}; +use ng_net::types::{ + BindAddress, BootstrapContentV0, ClientInfo, ClientInfoV0, ClientType, CreateAccountBSP, + InboxPost, IP, +}; use ng_net::utils::{ decode_invitation_string, parse_ip_and_port_for, retrieve_local_bootstrap, retrieve_local_url, spawn_and_log_error, Receiver, ResultSend, Sender, @@ -55,9 +58,8 @@ use ng_wallet::types::*; use ng_wallet::*; use nextgraph::local_broker::*; +use nextgraph::verifier::orm::{OrmDiff, OrmShapeType}; use nextgraph::verifier::CancelFn; -use nextgraph::verifier::orm::{OrmShapeType, OrmDiff}; - use crate::model::*; @@ -73,8 +75,9 @@ pub async fn get_device_name() -> Result { #[wasm_bindgen] pub async fn bootstrap_to_iframe_msgs(bootstrap: JsValue) -> Result { - let content: BootstrapContentV0 = serde_wasm_bindgen::from_value::(bootstrap) - .map_err(|_| "Invalid BootstrapContentV0".to_string())?; + let content: BootstrapContentV0 = + serde_wasm_bindgen::from_value::(bootstrap) + .map_err(|_| "Invalid BootstrapContentV0".to_string())?; let iframe_msg = content.to_iframe_msgs(); Ok(serde_wasm_bindgen::to_value(&iframe_msg).unwrap()) } @@ -453,8 +456,10 @@ pub async fn sparql_update( .map_err(|e: NgError| e.to_string())?; match res { AppResponse::V0(AppResponseV0::Error(e)) => Err(e), - AppResponse::V0(AppResponseV0::Commits(commits)) => Ok(serde_wasm_bindgen::to_value(&commits).unwrap()), - _ => Err(NgError::InvalidResponse.to_string()) + AppResponse::V0(AppResponseV0::Commits(commits)) => { + Ok(serde_wasm_bindgen::to_value(&commits).unwrap()) + } + _ => Err(NgError::InvalidResponse.to_string()), } } @@ -610,26 +615,29 @@ pub async fn rdf_dump(session_id: JsValue) -> Result { /// contacts = did:ng:d:c or a sparql query #[wasm_bindgen] pub async fn social_query_start( - session_id: JsValue, - from_profile_nuri: String, - query_nuri: String, - contacts: String, - degree: JsValue, - ) -> Result<(), String> { + session_id: JsValue, + from_profile_nuri: String, + query_nuri: String, + contacts: String, + degree: JsValue, +) -> Result<(), String> { let session_id: u64 = serde_wasm_bindgen::from_value::(session_id) .map_err(|_| "Invalid session_id".to_string())?; - let degree: u16 = serde_wasm_bindgen::from_value::(degree) - .map_err(|_| "Invalid degree".to_string())?; + let degree: u16 = + serde_wasm_bindgen::from_value::(degree).map_err(|_| "Invalid degree".to_string())?; - let query = NuriV0::new_from_commit(&query_nuri).map_err(|e| format!("Invalid query_nuri {e}"))?; + let query = + NuriV0::new_from_commit(&query_nuri).map_err(|e| format!("Invalid query_nuri {e}"))?; let from_profile = match from_profile_nuri.as_str() { "did:ng:a" => NuriV0::new_public_store_target(), "did:ng:b" => NuriV0::new_protected_store_target(), - _ => return Err("Invalid from_profile_nuri".to_string()) + _ => return Err("Invalid from_profile_nuri".to_string()), }; - if ! (contacts == "did:ng:d:c" || contacts.starts_with("SELECT")) { return Err("Invalid contacts".to_string()); } + if !(contacts == "did:ng:d:c" || contacts.starts_with("SELECT")) { + return Err("Invalid contacts".to_string()); + } let mut request = AppRequest::social_query_start(from_profile, query, contacts, degree); request.set_session_id(session_id); @@ -1054,21 +1062,21 @@ pub async fn wallet_import( Ok(serde_wasm_bindgen::to_value(&client).unwrap()) } - #[wasm_bindgen] pub async fn import_contact_from_qrcode( session_id: JsValue, doc_nuri: String, qrcode: String, ) -> Result<(), String> { - let session_id: u64 = serde_wasm_bindgen::from_value::(session_id) .map_err(|_| "Deserialization error of session_id".to_string())?; let mut request = AppRequest::new( AppRequestCommandV0::QrCodeProfileImport, NuriV0::new_from_repo_nuri(&doc_nuri).map_err(|e| e.to_string())?, - Some(AppRequestPayload::V0(AppRequestPayloadV0::QrCodeProfileImport(qrcode))), + Some(AppRequestPayload::V0( + AppRequestPayloadV0::QrCodeProfileImport(qrcode), + )), ); request.set_session_id(session_id); @@ -1103,7 +1111,9 @@ pub async fn get_qrcode_for_profile( let mut request = AppRequest::new( AppRequestCommandV0::QrCodeProfile, nuri, - Some(AppRequestPayload::V0(AppRequestPayloadV0::QrCodeProfile(size))), + Some(AppRequestPayload::V0(AppRequestPayloadV0::QrCodeProfile( + size, + ))), ); request.set_session_id(session_id); @@ -1455,9 +1465,16 @@ pub async fn doc_create( let store_repo = serde_wasm_bindgen::from_value::>(store_repo) .map_err(|_| "Deserialization error of store_repo".to_string())?; - nextgraph::local_broker::doc_create_with_store_repo(session_id, crdt, class_name, destination, store_repo) - .await - .map_err(|e| e.to_string()).map(|nuri| serde_wasm_bindgen::to_value(&nuri).unwrap()) + nextgraph::local_broker::doc_create_with_store_repo( + session_id, + crdt, + class_name, + destination, + store_repo, + ) + .await + .map_err(|e| e.to_string()) + .map(|nuri| serde_wasm_bindgen::to_value(&nuri).unwrap()) } #[cfg(wasmpack_target = "nodejs")] @@ -1479,9 +1496,17 @@ pub async fn doc_create( let store_repo = serde_wasm_bindgen::from_value::>(store_repo) .map_err(|_| "Deserialization error of store_repo".to_string())?; - nextgraph::local_broker::doc_create(session_id, crdt, class_name, destination, store_type, store_repo) - .await - .map_err(|e| e.to_string()).map(|nuri| serde_wasm_bindgen::to_value(&nuri).unwrap()) + nextgraph::local_broker::doc_create( + session_id, + crdt, + class_name, + destination, + store_type, + store_repo, + ) + .await + .map_err(|e| e.to_string()) + .map(|nuri| serde_wasm_bindgen::to_value(&nuri).unwrap()) } #[wasm_bindgen] @@ -1808,13 +1833,15 @@ pub async fn orm_update( diff: JsValue, session_id: JsValue, ) -> Result<(), String> { - let session_id: u64 = serde_wasm_bindgen::from_value::(session_id) - .map_err(|_| "Deserialization error of session_id".to_string())?; let diff: OrmDiff = serde_wasm_bindgen::from_value::(diff) .map_err(|e| format!("Deserialization error of diff {e}"))?; + log_info!("frontend_update_orm {:?}", diff); + let scope: NuriV0 = serde_wasm_bindgen::from_value::(scope) .map_err(|_| "Deserialization error of scope".to_string())?; let mut request = AppRequest::new_orm_update(scope, shapeTypeName, diff); + let session_id: u64 = serde_wasm_bindgen::from_value::(session_id) + .map_err(|_| "Deserialization error of session_id".to_string())?; request.set_session_id(session_id); let response = nextgraph::local_broker::app_request(request) .await @@ -2074,10 +2101,31 @@ pub async fn user_connect( .unwrap()) } -const EMPTY_IMG: [u8;437] = [137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 150, 0, 0, 0, 150, 8, 6, 0, 0, 0, 60, 1, 113, 226, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, 1, 115, 82, 71, 66, 1, 217, 201, 44, 127, 0, 0, 0, 32, 99, 72, 82, 77, 0, 0, 122, 38, 0, 0, 128, 132, 0, 0, 250, 0, 0, 0, 128, 232, 0, 0, 117, 48, 0, 0, 234, 96, 0, 0, 58, 152, 0, 0, 23, 112, 156, 186, 81, 60, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 3, 0, 0, 0, 3, 0, 1, 217, 203, 178, 96, 0, 0, 1, 30, 73, 68, 65, 84, 120, 218, 237, 210, 49, 17, 0, 0, 8, 196, 48, 192, 191, 231, 199, 0, 35, 99, 34, 161, 215, 78, 146, 130, 103, 35, 1, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 193, 109, 1, 34, 65, 5, 40, 46, 151, 166, 52, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130]; - -#[wasm_bindgen] -pub async fn gen_wallet_for_test(ngd_peer_id: String)-> Result { +const EMPTY_IMG: [u8; 437] = [ + 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 150, 0, 0, 0, 150, 8, 6, + 0, 0, 0, 60, 1, 113, 226, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, + 1, 115, 82, 71, 66, 1, 217, 201, 44, 127, 0, 0, 0, 32, 99, 72, 82, 77, 0, 0, 122, 38, 0, 0, + 128, 132, 0, 0, 250, 0, 0, 0, 128, 232, 0, 0, 117, 48, 0, 0, 234, 96, 0, 0, 58, 152, 0, 0, 23, + 112, 156, 186, 81, 60, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 3, 0, 0, 0, 3, 0, 1, 217, 203, 178, + 96, 0, 0, 1, 30, 73, 68, 65, 84, 120, 218, 237, 210, 49, 17, 0, 0, 8, 196, 48, 192, 191, 231, + 199, 0, 35, 99, 34, 161, 215, 78, 146, 130, 103, 35, 1, 198, 194, 88, 24, 11, 140, 133, 177, + 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, + 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, + 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, + 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, + 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, + 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, + 198, 194, 88, 96, 44, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, + 140, 133, 177, 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, + 24, 11, 140, 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, + 192, 88, 24, 11, 99, 129, 177, 48, 22, 198, 2, 99, 97, 44, 140, 5, 198, 194, 88, 24, 11, 140, + 133, 177, 48, 22, 24, 11, 99, 97, 44, 48, 22, 198, 194, 88, 96, 44, 140, 133, 177, 192, 88, 24, + 11, 99, 193, 109, 1, 34, 65, 5, 40, 46, 151, 166, 52, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, + 130, +]; + +#[wasm_bindgen] +pub async fn gen_wallet_for_test(ngd_peer_id: String) -> Result { init_local_broker_with_lazy(&INIT_LOCAL_BROKER).await; //init_local_broker(Box::new(|| LocalBrokerConfig::InMemory)).await; @@ -2108,9 +2156,8 @@ pub async fn gen_wallet_for_test(ngd_peer_id: String)-> Result mnemonic_words.push(word.clone()); }); - let res = (wallet_result,mnemonic_words); + let res = (wallet_result, mnemonic_words); Ok(serde_wasm_bindgen::to_value(&res).unwrap()) - } #[cfg(test)]