From e453c8998f3852d7b3af2405443e3324f2d6b0f1 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Tue, 13 Aug 2024 13:55:56 +0300 Subject: [PATCH] RDF resource identifier is without overlay id --- ng-app/src/apps/ContainerView.svelte | 4 ++-- ng-app/src/lib/panes/Files.svelte | 6 +++--- ng-app/src/lib/panes/History.svelte | 6 +++--- ng-app/src/store.ts | 12 ++++++------ ng-app/src/tab.ts | 5 +++-- ng-net/src/app_protocol.rs | 8 ++++++++ ng-net/src/broker.rs | 1 - ng-repo/src/event.rs | 1 - ng-sdk-js/app-node/index.js | 6 +++--- ng-sdk-js/src/lib.rs | 4 +++- ng-verifier/src/request_processor.rs | 3 +-- 11 files changed, 32 insertions(+), 24 deletions(-) diff --git a/ng-app/src/apps/ContainerView.svelte b/ng-app/src/apps/ContainerView.svelte index ba0ca0e..f244318 100644 --- a/ng-app/src/apps/ContainerView.svelte +++ b/ng-app/src/apps/ContainerView.svelte @@ -28,8 +28,8 @@ function contained(graph) { let ret = []; for (const g of graph) { - if (g.substring(104,137) === "http://www.w3.org/ns/ldp#contains") { - let nuri = g.substring(140,240); + if (g.substring(57,90) === "http://www.w3.org/ns/ldp#contains") { + let nuri = g.substring(93,193); let hash = nuri.substring(9,16); ret.push({nuri,hash}); } diff --git a/ng-app/src/lib/panes/Files.svelte b/ng-app/src/lib/panes/Files.svelte index 5ff03b5..f146c10 100644 --- a/ng-app/src/lib/panes/Files.svelte +++ b/ng-app/src/lib/panes/Files.svelte @@ -31,7 +31,7 @@ let upload_progress: null | { total: number; current: number; error?: any } = null; - let commits = $active_session && branch_subscribe($cur_tab.branch.nuri, false); + let commits = $active_session && branch_subscribe($cur_tab.branch.nuri+":"+$cur_tab.store.overlay, false); let fileinput; let file_urls = {}; @@ -46,7 +46,7 @@ const download = async (file) => { if (is_tauri) { - await ng.file_save_to_downloads($active_session.session_id, file.reference, file.name, "did:ng:"+$cur_tab.branch.nuri); + await ng.file_save_to_downloads($active_session.session_id, file.reference, file.name, "did:ng:"+$cur_tab.branch.nuri+":"+$cur_tab.store.overlay); } else { file_urls[file.nuri].url = await get_blob(file, false); //console.log(file.name); @@ -144,7 +144,7 @@ let start_request_payload = { RandomAccessFilePut: image.type, }; - let nuri = "did:ng:"+$cur_tab.branch.nuri; + let nuri = "did:ng:"+$cur_tab.branch.nuri+":"+$cur_tab.store.overlay; let start_res = await ng.app_request_with_nuri_command(nuri, "FilePut", $active_session.session_id, start_request_payload); let upload_id = start_res.V0.FileUploading; diff --git a/ng-app/src/lib/panes/History.svelte b/ng-app/src/lib/panes/History.svelte index 0782396..ab2db91 100644 --- a/ng-app/src/lib/panes/History.svelte +++ b/ng-app/src/lib/panes/History.svelte @@ -55,7 +55,7 @@ commit: { message: { displayAuthor: false, displayHash: false } }, }), }); - let res = await ng.branch_history($active_session.session_id, "did:ng:"+$cur_tab.branch.nuri); + let res = await ng.branch_history($active_session.session_id, "did:ng:"+$cur_tab.branch.nuri+":"+$cur_tab.store.overlay); // for (const h of res.history) { // console.log(h[0], h[1]); // } @@ -75,7 +75,7 @@ onMessageClick:()=>openCommit(h[0]) };})); - let branch = branch_subscribe($cur_tab.branch.nuri,false); + let branch = branch_subscribe($cur_tab.branch.nuri+":"+$cur_tab.store.overlay,false); unsub(); unsub = branch.subscribe((b) => { //console.log("subscription callbak",b.history.commits); @@ -100,7 +100,7 @@ }); onDestroy( ()=>{ - let branch = branch_subscribe($cur_tab.branch.nuri,false); + let branch = branch_subscribe($cur_tab.branch.nuri+":"+$cur_tab.store.overlay,false); get(branch).history.stop(); unsub(); }); diff --git a/ng-app/src/store.ts b/ng-app/src/store.ts index 79f3c27..0038791 100644 --- a/ng-app/src/store.ts +++ b/ng-app/src/store.ts @@ -420,7 +420,7 @@ export const live_discrete_update = async (update, crdt, heads) => { }); throw new Error("no session"); } - let nuri = "did:ng:"+get(cur_tab).branch.nuri; + let nuri = "did:ng:"+get(cur_tab).doc.nuri+":"+get(cur_tab).store.overlay; await ng.discrete_update(session.session_id, update, heads, crdt, nuri); } @@ -433,9 +433,9 @@ export const sparql_query = async function(sparql:string, union:boolean) { }); throw new Error("no session"); } - let base = "did:ng:"+get(cur_tab).branch.nuri; - console.log(base) - let nuri = union ? undefined : base; + let base = "did:ng:"+get(cur_tab).doc.nuri; + //console.log("BASE",base) + let nuri = union ? undefined : (base+":"+get(cur_tab).store.overlay); return await ng.sparql_query(session.session_id, sparql, base, nuri); } @@ -448,7 +448,7 @@ export const sparql_update = async function(sparql:string) { }); throw new Error("no session"); } - let nuri = "did:ng:"+get(cur_tab).branch.nuri; + let nuri = "did:ng:"+get(cur_tab).doc.nuri+":"+get(cur_tab).store.overlay; await ng.sparql_update(session.session_id, sparql, nuri); } @@ -723,7 +723,7 @@ export async function get_blob(ref: { nuri: string; reference: { key: any; id: a try { let final_blob; let content_type; - let branch_nuri = "did:ng:"+get(cur_tab).branch.nuri; + let branch_nuri = "did:ng:"+get(cur_tab).doc.nuri+":"+get(cur_tab).store.overlay; let cancel = await ng.file_get(get(active_session).session_id, ref.reference, branch_nuri, async (blob) => { //console.log("GOT APP RESPONSE", blob); if (blob.V0.FileMeta) { diff --git a/ng-app/src/tab.ts b/ng-app/src/tab.ts index 3a25a02..2368670 100644 --- a/ng-app/src/tab.ts +++ b/ng-app/src/tab.ts @@ -173,7 +173,8 @@ export const open_branch = (nuri: string, in_tab: boolean) => { if (!old[nuri]) { //console.log("creating tab for ",nuri) old[nuri] = JSON.parse(JSON.stringify(old[""])); - old[nuri].branch.nuri = nuri; + old[nuri].branch.nuri = nuri.substring(0,nuri.length-47); // we remove the ":v:[char;44]" part + old[nuri].store.overlay = nuri.substring(nuri.length-47); // and put it in store.overlay } return old; }); @@ -245,7 +246,7 @@ export const all_tabs = writable({ can_edit: false, }, branch: { - nuri: "", // :o:v or :o:v:b + nuri: "", // :o or :o:b readcap: "", // "r:" comment_branch: "", // nuri class: "", diff --git a/ng-net/src/app_protocol.rs b/ng-net/src/app_protocol.rs index bb607ef..653a9ca 100644 --- a/ng-net/src/app_protocol.rs +++ b/ng-net/src/app_protocol.rs @@ -259,6 +259,14 @@ impl NuriV0 { Ok(format!("{DID_PREFIX}:o:{repo_id}:u:{sko}")) } + pub fn repo(&self) -> String { + Self::repo_id(self.target.repo_id()) + } + + pub fn repo_id(repo_id: &RepoId) -> String { + format!("{DID_PREFIX}:o:{}", repo_id) + } + pub fn overlay_id(overlay_id: &OverlayId) -> String { format!("{DID_PREFIX}:v:{overlay_id}") } diff --git a/ng-net/src/broker.rs b/ng-net/src/broker.rs index cb0d104..db466c6 100644 --- a/ng-net/src/broker.rs +++ b/ng-net/src/broker.rs @@ -29,7 +29,6 @@ use ng_repo::errors::*; use ng_repo::log::*; use ng_repo::types::*; -use crate::actor::EActor; use crate::actor::SoS; use crate::connection::*; use crate::server_broker::IServerBroker; diff --git a/ng-repo/src/event.rs b/ng-repo/src/event.rs index 66933d9..c65a46b 100644 --- a/ng-repo/src/event.rs +++ b/ng-repo/src/event.rs @@ -16,7 +16,6 @@ use chacha20::ChaCha20; use zeroize::Zeroize; use crate::errors::*; -use crate::log::*; use crate::repo::{BranchInfo, Repo}; use crate::store::Store; use crate::types::*; diff --git a/ng-sdk-js/app-node/index.js b/ng-sdk-js/app-node/index.js index c0d89ab..bc599af 100644 --- a/ng-sdk-js/app-node/index.js +++ b/ng-sdk-js/app-node/index.js @@ -65,10 +65,10 @@ ng.init_headless(config).then( async() => { //await ng.sparql_update(session.session_id, "INSERT { _:_ . } WHERE { _:_ } "); //await ng.sparql_update(session.session_id, "INSERT DATA { _:_ . _:_a . }"); - //await ng.sparql_update(session.session_id, "INSERT DATA { <> . }",base); + await ng.sparql_update(session.session_id, "INSERT DATA { <> . }",base); - await ng.sparql_update(session.session_id, "INSERT DATA { _:_ . _:_ . }"); - await ng.sparql_update(session.session_id, "INSERT DATA { [ ]. }"); + //await ng.sparql_update(session.session_id, "INSERT DATA { _:_ . _:_ . }"); + //await ng.sparql_update(session.session_id, "INSERT DATA { [ ]. }"); sparql_result = await ng.sparql_query(session.session_id, "SELECT ?a WHERE { ?a _:abc. _:abc }", base); console.log(sparql_result); diff --git a/ng-sdk-js/src/lib.rs b/ng-sdk-js/src/lib.rs index e06a28f..b0e39fc 100644 --- a/ng-sdk-js/src/lib.rs +++ b/ng-sdk-js/src/lib.rs @@ -375,7 +375,9 @@ pub async fn sparql_update( let (nuri, base) = if nuri.is_string() { let n = nuri.as_string().unwrap(); - (NuriV0::new_from(&n).map_err(|e| e.to_string())?, Some(n)) + let nuri = NuriV0::new_from(&n).map_err(|e| e.to_string())?; + let b = nuri.repo(); + (nuri, Some(b)) } else { (NuriV0::new_private_store_target(), None) }; diff --git a/ng-verifier/src/request_processor.rs b/ng-verifier/src/request_processor.rs index 7ba42cf..226db1e 100644 --- a/ng-verifier/src/request_processor.rs +++ b/ng-verifier/src/request_processor.rs @@ -269,8 +269,7 @@ impl Verifier { let overlay_id = doc_create.store.outer_overlay(); let nuri = NuriV0::repo_graph_name(&repo_id, &overlay_id); let store_nuri = NuriV0::from_store_repo(&doc_create.store); - let store_nuri_string = - NuriV0::repo_graph_name(doc_create.store.repo_id(), &overlay_id); + let store_nuri_string = NuriV0::repo_id(doc_create.store.repo_id()); let query = format!("INSERT DATA {{ <{store_nuri_string}> <{nuri}>. }}"); let ret = self