diff --git a/Cargo.lock b/Cargo.lock index 3055355..e40078e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3312,6 +3312,7 @@ dependencies = [ "ng-net", "ng-repo", "ng-wallet", + "oxrdf", "serde", "serde_bare", "serde_bytes", diff --git a/ng-app/package.json b/ng-app/package.json index a932bb0..eab6288 100644 --- a/ng-app/package.json +++ b/ng-app/package.json @@ -16,20 +16,25 @@ "tauri": "tauri" }, "dependencies": { + "@codemirror/autocomplete": "^6.17.0", + "@codemirror/commands": "^6.6.0", "@codemirror/language": "^6.10.2", "@codemirror/legacy-modes": "^6.4.0", + "@codemirror/lint": "^6.8.1", + "@codemirror/search": "^6.5.6", + "@codemirror/state": "^6.4.1", + "@codemirror/view": "^6.28.6", "@popperjs/core": "^2.11.8", "@tauri-apps/api": "2.0.0-alpha.8", "@tauri-apps/plugin-barcode-scanner": "2.0.0-alpha.0", "@tauri-apps/plugin-window": "2.0.0-alpha.1", "async-proxy": "^0.4.1", "classnames": "^2.3.2", - "codemirror": "^6.0.0", + "codemirror": "^6.0.1", "flowbite": "^1.6.5", "flowbite-svelte": "^0.43.3", "html5-qrcode": "^2.3.8", "ng-sdk-js": "workspace:^0.1.0-preview.1", - "sparql": "link:@codemirror/legacy-modes/mode/sparql", "svelte-codemirror-editor": "^1.4.0", "svelte-i18n": "^4.0.0", "svelte-inview": "^4.0.2", diff --git a/ng-app/src-tauri/Cargo.toml b/ng-app/src-tauri/Cargo.toml index 5f09d44..2a694fc 100644 --- a/ng-app/src-tauri/Cargo.toml +++ b/ng-app/src-tauri/Cargo.toml @@ -41,6 +41,7 @@ ng-repo = { path = "../../ng-repo" } ng-net = { path = "../../ng-net" } ng-wallet = { path = "../../ng-wallet" } nextgraph = { path = "../../nextgraph" } +oxrdf = { git = "https://git.nextgraph.org/NextGraph/oxigraph.git", branch="main", features = ["rdf-star", "oxsdatatypes"] } [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/ng-app/src-tauri/src/lib.rs b/ng-app/src-tauri/src/lib.rs index 892da77..0c34dcc 100644 --- a/ng-app/src-tauri/src/lib.rs +++ b/ng-app/src-tauri/src/lib.rs @@ -11,6 +11,7 @@ use std::collections::HashMap; use std::fs::write; use async_std::stream::StreamExt; +use oxrdf::Triple; use serde::{Deserialize, Serialize}; use serde_json::Value; use sys_locale::get_locales; @@ -401,6 +402,76 @@ async fn doc_fetch_repo_subscribe(repo_o: String) -> Result Ok(request) } +#[tauri::command(rename_all = "snake_case")] +async fn sparql_update(session_id: u64, sparql: String, nuri: String) -> Result<(), String> { + let nuri = NuriV0::new_from(&nuri).map_err(|_| "Deserialization error of Nuri".to_string())?; + + let request = AppRequest::V0(AppRequestV0 { + command: AppRequestCommandV0::new_write_query(), + nuri, + payload: Some(AppRequestPayload::new_sparql_query(sparql)), + session_id, + }); + + let res = nextgraph::local_broker::app_request(request) + .await + .map_err(|e: NgError| e.to_string())?; + if let AppResponse::V0(AppResponseV0::Error(e)) = res { + Err(e) + } else { + Ok(()) + } +} + +#[tauri::command(rename_all = "snake_case")] +async fn sparql_query( + session_id: u64, + sparql: String, + nuri: Option, +) -> Result { + let nuri = if nuri.is_some() { + NuriV0::new_from(&nuri.unwrap()).map_err(|_| "Deserialization error of Nuri".to_string())? + } else { + NuriV0::new_entire_user_site() + }; + + let request = AppRequest::V0(AppRequestV0 { + command: AppRequestCommandV0::new_read_query(), + nuri, + payload: Some(AppRequestPayload::new_sparql_query(sparql)), + session_id, + }); + + let response = nextgraph::local_broker::app_request(request) + .await + .map_err(|e: NgError| e.to_string())?; + + let AppResponse::V0(res) = response; + match res { + AppResponseV0::False => return Ok(Value::Bool(false)), + AppResponseV0::True => return Ok(Value::Bool(true)), + AppResponseV0::Graph(graph) => { + let triples: Vec = serde_bare::from_slice(&graph) + .map_err(|_| "Deserialization error of graph".to_string())?; + + Ok(Value::Array( + triples + .into_iter() + .map(|t| Value::String(t.to_string())) + .collect(), + )) + } + AppResponseV0::QueryResult(buf) => { + let string = String::from_utf8(buf) + .map_err(|_| "Deserialization error of JSON QueryResult String".to_string())?; + Ok(serde_json::from_str(&string) + .map_err(|_| "Parsing error of JSON QueryResult String".to_string())?) + } + AppResponseV0::Error(e) => Err(e.to_string().into()), + _ => Err("invalid AppResponse".to_string().into()), + } +} + #[tauri::command(rename_all = "snake_case")] async fn app_request(request: AppRequest, _app: tauri::AppHandle) -> Result { //log_debug!("app request {:?}", request); @@ -636,6 +707,8 @@ impl AppBuilder { app_request, upload_chunk, get_device_name, + sparql_query, + sparql_update, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/ng-app/src/api.ts b/ng-app/src/api.ts index 97a2354..4178292 100644 --- a/ng-app/src/api.ts +++ b/ng-app/src/api.ts @@ -39,6 +39,8 @@ const mapping = { "user_connect": ["info","user_id","location"], "user_disconnect": ["user_id"], "app_request": ["request"], + "sparql_query": ["session_id","sparql","nuri"], + "sparql_update": ["session_id","sparql","nuri"], "test": [ ], "get_device_name": [], "doc_fetch_private_subscribe": [], diff --git a/ng-app/vite.config.ts b/ng-app/vite.config.ts index 5301091..8eeb94c 100644 --- a/ng-app/vite.config.ts +++ b/ng-app/vite.config.ts @@ -11,9 +11,9 @@ import topLevelAwait from "vite-plugin-top-level-await"; export default defineConfig(async () => { const host = await internalIpV4() const config = { - // optimizeDeps: { - // exclude: ["codemirror", "@codemirror/legacy-modes/mode/sparql"] - // }, + optimizeDeps: { + exclude: ["codemirror", "@codemirror/*", "@codemirror/language", "@codemirror/state", "@codemirror/view","@codemirror/legacy-modes/mode/sparql"] + }, worker: { format: 'es', plugins : [ @@ -68,6 +68,10 @@ export default defineConfig(async () => { port: process.env.NG_APP_WEB ? 1421 : 1420, host: '0.0.0.0', strictPort: true, + fs: { + // Allow serving files from one level up to the project root + allow: ['..'], + }, hmr: { protocol: 'ws', host, diff --git a/ng-sdk-js/src/lib.rs b/ng-sdk-js/src/lib.rs index 273ea5e..28f1591 100644 --- a/ng-sdk-js/src/lib.rs +++ b/ng-sdk-js/src/lib.rs @@ -259,7 +259,7 @@ pub async fn session_headless_stop(session_id: JsValue, force_close: bool) -> Re Ok(()) } -/*let app_response = nextgraph::verifier::prepare_app_response_for_js(app_response)?; */ + #[cfg(wasmpack_target = "nodejs")] #[wasm_bindgen] pub async fn sparql_query( diff --git a/package.json b/package.json index 096780e..b24e7b9 100644 --- a/package.json +++ b/package.json @@ -12,5 +12,16 @@ "devDependencies": { "prettier": "^3.3.2", "prettier-plugin-svelte": "^3.2.5" + }, + "dependencies": { + "@codemirror/autocomplete": "^6.17.0", + "@codemirror/commands": "^6.6.0", + "@codemirror/language": "^6.10.2", + "@codemirror/legacy-modes": "^6.4.0", + "@codemirror/lint": "^6.8.1", + "@codemirror/search": "^6.5.6", + "@codemirror/state": "^6.4.1", + "@codemirror/view": "^6.28.6", + "codemirror": "^6.0.1" } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c0e313..99604f7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,14 @@ importers: ng-app: specifiers: + '@codemirror/autocomplete': ^6.17.0 + '@codemirror/commands': ^6.6.0 '@codemirror/language': ^6.10.2 '@codemirror/legacy-modes': ^6.4.0 + '@codemirror/lint': ^6.8.1 + '@codemirror/search': ^6.5.6 + '@codemirror/state': ^6.4.1 + '@codemirror/view': ^6.28.6 '@popperjs/core': ^2.11.8 '@sveltejs/vite-plugin-svelte': ^2.0.0 '@tauri-apps/api': 2.0.0-alpha.8 @@ -25,7 +31,7 @@ importers: async-proxy: ^0.4.1 autoprefixer: ^10.4.14 classnames: ^2.3.2 - codemirror: ^6.0.0 + codemirror: ^6.0.1 cross-env: ^7.0.3 dayjs: ^1.11.10 flowbite: ^1.6.5 @@ -38,7 +44,6 @@ importers: postcss: ^8.4.23 postcss-load-config: ^4.0.1 shx: ^0.3.4 - sparql: link:@codemirror/legacy-modes/mode/sparql svelte: ^3.54.0 svelte-check: ^3.0.0 svelte-codemirror-editor: ^1.4.0 @@ -58,8 +63,14 @@ importers: vite-plugin-top-level-await: ^1.3.1 vite-plugin-wasm: ^3.2.2 dependencies: + '@codemirror/autocomplete': 6.17.0_d2gatnekun5qqgvovsxsi7nnwi + '@codemirror/commands': 6.6.0 '@codemirror/language': 6.10.2 '@codemirror/legacy-modes': 6.4.0 + '@codemirror/lint': 6.8.1 + '@codemirror/search': 6.5.6 + '@codemirror/state': 6.4.1 + '@codemirror/view': 6.28.6 '@popperjs/core': 2.11.8 '@tauri-apps/api': 2.0.0-alpha.8 '@tauri-apps/plugin-barcode-scanner': 2.0.0-alpha.0 @@ -71,7 +82,6 @@ importers: flowbite-svelte: 0.43.3_svelte@3.59.1 html5-qrcode: 2.3.8 ng-sdk-js: link:../ng-sdk-js/pkg - sparql: link:@codemirror/legacy-modes/mode/sparql svelte-codemirror-editor: 1.4.0_5sa7ksvb6ejctmkumffbkxbvpi svelte-i18n: 4.0.0_svelte@3.59.1 svelte-inview: 4.0.2_svelte@3.59.1 @@ -144,10 +154,12 @@ packages: engines: {node: '>=10'} dev: true - /@codemirror/autocomplete/6.17.0_gts4chaxc3fh6p7x3saco74w5y: + /@codemirror/autocomplete/6.17.0_d2gatnekun5qqgvovsxsi7nnwi: resolution: {integrity: sha512-fdfj6e6ZxZf8yrkMHUSJJir7OJkHkZKaOZGzLWIYp2PZ3jd+d+UjG8zVPqJF6d3bKxkhvXTPan/UZ1t7Bqm0gA==} peerDependencies: '@codemirror/language': ^6.0.0 + '@codemirror/state': ^6.0.0 + '@codemirror/view': ^6.0.0 dependencies: '@codemirror/language': 6.10.2 '@codemirror/state': 6.4.1 @@ -1148,7 +1160,7 @@ packages: /codemirror/6.0.1: resolution: {integrity: sha512-J8j+nZ+CdWmIeFIGXEFbFPtpiYacFMDR8GlHK3IyHQJMCaVRfGx9NT+Hxivv1ckLWPvNdZqndbr/7lVhrf/Svg==} dependencies: - '@codemirror/autocomplete': 6.17.0_gts4chaxc3fh6p7x3saco74w5y + '@codemirror/autocomplete': 6.17.0_d2gatnekun5qqgvovsxsi7nnwi '@codemirror/commands': 6.6.0 '@codemirror/language': 6.10.2 '@codemirror/lint': 6.8.1