sparql update and query for Tauri

pull/37/head
Niko PLP 5 months ago
parent 029276e205
commit 9659f1bbd2
  1. 1
      Cargo.lock
  2. 9
      ng-app/package.json
  3. 1
      ng-app/src-tauri/Cargo.toml
  4. 73
      ng-app/src-tauri/src/lib.rs
  5. 2
      ng-app/src/api.ts
  6. 10
      ng-app/vite.config.ts
  7. 2
      ng-sdk-js/src/lib.rs
  8. 11
      package.json
  9. 22
      pnpm-lock.yaml

1
Cargo.lock generated

@ -3312,6 +3312,7 @@ dependencies = [
"ng-net", "ng-net",
"ng-repo", "ng-repo",
"ng-wallet", "ng-wallet",
"oxrdf",
"serde", "serde",
"serde_bare", "serde_bare",
"serde_bytes", "serde_bytes",

@ -16,20 +16,25 @@
"tauri": "tauri" "tauri": "tauri"
}, },
"dependencies": { "dependencies": {
"@codemirror/autocomplete": "^6.17.0",
"@codemirror/commands": "^6.6.0",
"@codemirror/language": "^6.10.2", "@codemirror/language": "^6.10.2",
"@codemirror/legacy-modes": "^6.4.0", "@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", "@popperjs/core": "^2.11.8",
"@tauri-apps/api": "2.0.0-alpha.8", "@tauri-apps/api": "2.0.0-alpha.8",
"@tauri-apps/plugin-barcode-scanner": "2.0.0-alpha.0", "@tauri-apps/plugin-barcode-scanner": "2.0.0-alpha.0",
"@tauri-apps/plugin-window": "2.0.0-alpha.1", "@tauri-apps/plugin-window": "2.0.0-alpha.1",
"async-proxy": "^0.4.1", "async-proxy": "^0.4.1",
"classnames": "^2.3.2", "classnames": "^2.3.2",
"codemirror": "^6.0.0", "codemirror": "^6.0.1",
"flowbite": "^1.6.5", "flowbite": "^1.6.5",
"flowbite-svelte": "^0.43.3", "flowbite-svelte": "^0.43.3",
"html5-qrcode": "^2.3.8", "html5-qrcode": "^2.3.8",
"ng-sdk-js": "workspace:^0.1.0-preview.1", "ng-sdk-js": "workspace:^0.1.0-preview.1",
"sparql": "link:@codemirror/legacy-modes/mode/sparql",
"svelte-codemirror-editor": "^1.4.0", "svelte-codemirror-editor": "^1.4.0",
"svelte-i18n": "^4.0.0", "svelte-i18n": "^4.0.0",
"svelte-inview": "^4.0.2", "svelte-inview": "^4.0.2",

@ -41,6 +41,7 @@ ng-repo = { path = "../../ng-repo" }
ng-net = { path = "../../ng-net" } ng-net = { path = "../../ng-net" }
ng-wallet = { path = "../../ng-wallet" } ng-wallet = { path = "../../ng-wallet" }
nextgraph = { path = "../../nextgraph" } nextgraph = { path = "../../nextgraph" }
oxrdf = { git = "https://git.nextgraph.org/NextGraph/oxigraph.git", branch="main", features = ["rdf-star", "oxsdatatypes"] }
[features] [features]
# this feature is used for production builds or when `devPath` points to the filesystem # this feature is used for production builds or when `devPath` points to the filesystem

@ -11,6 +11,7 @@ use std::collections::HashMap;
use std::fs::write; use std::fs::write;
use async_std::stream::StreamExt; use async_std::stream::StreamExt;
use oxrdf::Triple;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use sys_locale::get_locales; use sys_locale::get_locales;
@ -401,6 +402,76 @@ async fn doc_fetch_repo_subscribe(repo_o: String) -> Result<AppRequest, String>
Ok(request) 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<String>,
) -> Result<Value, String> {
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<Triple> = 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")] #[tauri::command(rename_all = "snake_case")]
async fn app_request(request: AppRequest, _app: tauri::AppHandle) -> Result<AppResponse, String> { async fn app_request(request: AppRequest, _app: tauri::AppHandle) -> Result<AppResponse, String> {
//log_debug!("app request {:?}", request); //log_debug!("app request {:?}", request);
@ -636,6 +707,8 @@ impl AppBuilder {
app_request, app_request,
upload_chunk, upload_chunk,
get_device_name, get_device_name,
sparql_query,
sparql_update,
]) ])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");

@ -39,6 +39,8 @@ const mapping = {
"user_connect": ["info","user_id","location"], "user_connect": ["info","user_id","location"],
"user_disconnect": ["user_id"], "user_disconnect": ["user_id"],
"app_request": ["request"], "app_request": ["request"],
"sparql_query": ["session_id","sparql","nuri"],
"sparql_update": ["session_id","sparql","nuri"],
"test": [ ], "test": [ ],
"get_device_name": [], "get_device_name": [],
"doc_fetch_private_subscribe": [], "doc_fetch_private_subscribe": [],

@ -11,9 +11,9 @@ import topLevelAwait from "vite-plugin-top-level-await";
export default defineConfig(async () => { export default defineConfig(async () => {
const host = await internalIpV4() const host = await internalIpV4()
const config = { const config = {
// optimizeDeps: { optimizeDeps: {
// exclude: ["codemirror", "@codemirror/legacy-modes/mode/sparql"] exclude: ["codemirror", "@codemirror/*", "@codemirror/language", "@codemirror/state", "@codemirror/view","@codemirror/legacy-modes/mode/sparql"]
// }, },
worker: { worker: {
format: 'es', format: 'es',
plugins : [ plugins : [
@ -68,6 +68,10 @@ export default defineConfig(async () => {
port: process.env.NG_APP_WEB ? 1421 : 1420, port: process.env.NG_APP_WEB ? 1421 : 1420,
host: '0.0.0.0', host: '0.0.0.0',
strictPort: true, strictPort: true,
fs: {
// Allow serving files from one level up to the project root
allow: ['..'],
},
hmr: { hmr: {
protocol: 'ws', protocol: 'ws',
host, host,

@ -259,7 +259,7 @@ pub async fn session_headless_stop(session_id: JsValue, force_close: bool) -> Re
Ok(()) Ok(())
} }
/*let app_response = nextgraph::verifier::prepare_app_response_for_js(app_response)?; */
#[cfg(wasmpack_target = "nodejs")] #[cfg(wasmpack_target = "nodejs")]
#[wasm_bindgen] #[wasm_bindgen]
pub async fn sparql_query( pub async fn sparql_query(

@ -12,5 +12,16 @@
"devDependencies": { "devDependencies": {
"prettier": "^3.3.2", "prettier": "^3.3.2",
"prettier-plugin-svelte": "^3.2.5" "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"
} }
} }

@ -12,8 +12,14 @@ importers:
ng-app: ng-app:
specifiers: specifiers:
'@codemirror/autocomplete': ^6.17.0
'@codemirror/commands': ^6.6.0
'@codemirror/language': ^6.10.2 '@codemirror/language': ^6.10.2
'@codemirror/legacy-modes': ^6.4.0 '@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 '@popperjs/core': ^2.11.8
'@sveltejs/vite-plugin-svelte': ^2.0.0 '@sveltejs/vite-plugin-svelte': ^2.0.0
'@tauri-apps/api': 2.0.0-alpha.8 '@tauri-apps/api': 2.0.0-alpha.8
@ -25,7 +31,7 @@ importers:
async-proxy: ^0.4.1 async-proxy: ^0.4.1
autoprefixer: ^10.4.14 autoprefixer: ^10.4.14
classnames: ^2.3.2 classnames: ^2.3.2
codemirror: ^6.0.0 codemirror: ^6.0.1
cross-env: ^7.0.3 cross-env: ^7.0.3
dayjs: ^1.11.10 dayjs: ^1.11.10
flowbite: ^1.6.5 flowbite: ^1.6.5
@ -38,7 +44,6 @@ importers:
postcss: ^8.4.23 postcss: ^8.4.23
postcss-load-config: ^4.0.1 postcss-load-config: ^4.0.1
shx: ^0.3.4 shx: ^0.3.4
sparql: link:@codemirror/legacy-modes/mode/sparql
svelte: ^3.54.0 svelte: ^3.54.0
svelte-check: ^3.0.0 svelte-check: ^3.0.0
svelte-codemirror-editor: ^1.4.0 svelte-codemirror-editor: ^1.4.0
@ -58,8 +63,14 @@ importers:
vite-plugin-top-level-await: ^1.3.1 vite-plugin-top-level-await: ^1.3.1
vite-plugin-wasm: ^3.2.2 vite-plugin-wasm: ^3.2.2
dependencies: dependencies:
'@codemirror/autocomplete': 6.17.0_d2gatnekun5qqgvovsxsi7nnwi
'@codemirror/commands': 6.6.0
'@codemirror/language': 6.10.2 '@codemirror/language': 6.10.2
'@codemirror/legacy-modes': 6.4.0 '@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 '@popperjs/core': 2.11.8
'@tauri-apps/api': 2.0.0-alpha.8 '@tauri-apps/api': 2.0.0-alpha.8
'@tauri-apps/plugin-barcode-scanner': 2.0.0-alpha.0 '@tauri-apps/plugin-barcode-scanner': 2.0.0-alpha.0
@ -71,7 +82,6 @@ importers:
flowbite-svelte: 0.43.3_svelte@3.59.1 flowbite-svelte: 0.43.3_svelte@3.59.1
html5-qrcode: 2.3.8 html5-qrcode: 2.3.8
ng-sdk-js: link:../ng-sdk-js/pkg ng-sdk-js: link:../ng-sdk-js/pkg
sparql: link:@codemirror/legacy-modes/mode/sparql
svelte-codemirror-editor: 1.4.0_5sa7ksvb6ejctmkumffbkxbvpi svelte-codemirror-editor: 1.4.0_5sa7ksvb6ejctmkumffbkxbvpi
svelte-i18n: 4.0.0_svelte@3.59.1 svelte-i18n: 4.0.0_svelte@3.59.1
svelte-inview: 4.0.2_svelte@3.59.1 svelte-inview: 4.0.2_svelte@3.59.1
@ -144,10 +154,12 @@ packages:
engines: {node: '>=10'} engines: {node: '>=10'}
dev: true dev: true
/@codemirror/autocomplete/6.17.0_gts4chaxc3fh6p7x3saco74w5y: /@codemirror/autocomplete/6.17.0_d2gatnekun5qqgvovsxsi7nnwi:
resolution: {integrity: sha512-fdfj6e6ZxZf8yrkMHUSJJir7OJkHkZKaOZGzLWIYp2PZ3jd+d+UjG8zVPqJF6d3bKxkhvXTPan/UZ1t7Bqm0gA==} resolution: {integrity: sha512-fdfj6e6ZxZf8yrkMHUSJJir7OJkHkZKaOZGzLWIYp2PZ3jd+d+UjG8zVPqJF6d3bKxkhvXTPan/UZ1t7Bqm0gA==}
peerDependencies: peerDependencies:
'@codemirror/language': ^6.0.0 '@codemirror/language': ^6.0.0
'@codemirror/state': ^6.0.0
'@codemirror/view': ^6.0.0
dependencies: dependencies:
'@codemirror/language': 6.10.2 '@codemirror/language': 6.10.2
'@codemirror/state': 6.4.1 '@codemirror/state': 6.4.1
@ -1148,7 +1160,7 @@ packages:
/codemirror/6.0.1: /codemirror/6.0.1:
resolution: {integrity: sha512-J8j+nZ+CdWmIeFIGXEFbFPtpiYacFMDR8GlHK3IyHQJMCaVRfGx9NT+Hxivv1ckLWPvNdZqndbr/7lVhrf/Svg==} resolution: {integrity: sha512-J8j+nZ+CdWmIeFIGXEFbFPtpiYacFMDR8GlHK3IyHQJMCaVRfGx9NT+Hxivv1ckLWPvNdZqndbr/7lVhrf/Svg==}
dependencies: dependencies:
'@codemirror/autocomplete': 6.17.0_gts4chaxc3fh6p7x3saco74w5y '@codemirror/autocomplete': 6.17.0_d2gatnekun5qqgvovsxsi7nnwi
'@codemirror/commands': 6.6.0 '@codemirror/commands': 6.6.0
'@codemirror/language': 6.10.2 '@codemirror/language': 6.10.2
'@codemirror/lint': 6.8.1 '@codemirror/lint': 6.8.1

Loading…
Cancel
Save