From bee4fb7154f6cf1130d1a8c9e5894a3b9dfb7555 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Sat, 24 May 2025 05:16:14 +0300 Subject: [PATCH] social query from React --- ng-app/src/apps/ProfileEditor.svelte | 2 +- ng-app/src/apps/SocialQueryDemo.svelte | 35 ++- ng-net/src/app_protocol.rs | 5 + ng-net/src/types.rs | 14 +- .../package-lock.json | 96 +++++--- .../package.json | 5 +- .../src/.ldo/socialquery.context.ts | 44 ++++ .../src/.ldo/socialquery.schema.ts | 63 ++++++ .../src/.ldo/socialquery.shapeTypes.ts | 19 ++ .../src/.ldo/socialquery.typings.ts | 23 ++ .../src/.shapes/socialquery.shex | 18 ++ .../src/App.css | 2 +- .../src/App.tsx | 9 +- .../src/Contact.tsx | 21 +- .../src/Contacts.tsx | 7 +- .../src/Header.tsx | 3 +- .../src/MakeContact.tsx | 5 +- .../src/Query.tsx | 212 ++++++++++++++++++ ng-verifier/src/inbox_processor.rs | 57 ++++- ng-verifier/src/request_processor.rs | 30 ++- ng-verifier/src/verifier.rs | 15 +- 21 files changed, 598 insertions(+), 87 deletions(-) create mode 100644 ng-sdk-js/example-webapp-react-socialquery/src/.ldo/socialquery.context.ts create mode 100644 ng-sdk-js/example-webapp-react-socialquery/src/.ldo/socialquery.schema.ts create mode 100644 ng-sdk-js/example-webapp-react-socialquery/src/.ldo/socialquery.shapeTypes.ts create mode 100644 ng-sdk-js/example-webapp-react-socialquery/src/.ldo/socialquery.typings.ts create mode 100644 ng-sdk-js/example-webapp-react-socialquery/src/.shapes/socialquery.shex create mode 100644 ng-sdk-js/example-webapp-react-socialquery/src/Query.tsx diff --git a/ng-app/src/apps/ProfileEditor.svelte b/ng-app/src/apps/ProfileEditor.svelte index 8c1a524..542b5cb 100644 --- a/ng-app/src/apps/ProfileEditor.svelte +++ b/ng-app/src/apps/ProfileEditor.svelte @@ -60,7 +60,7 @@ console.log($cur_tab.doc.nuri); //TODO: more sanitation on the input here! await ng.sparql_update($active_session.session_id, "PREFIX vcard: " - +"INSERT DATA { <> a vcard:Individual . <> vcard:fn \""+name.replace('"',"\\\"")+"\". <> vcard:hasEmail \""+email+"\" }", "did:ng:"+$cur_tab.doc.nuri ); + +"INSERT DATA { <> a vcard:Individual . <> vcard:fn \""+name.trim().replace('"',"\\\"")+"\". <> vcard:hasEmail \""+email.trim()+"\" }", "did:ng:"+$cur_tab.doc.nuri ); toast_success("Your profile was edited successfully!"); set_view_or_edit(true); } catch (e) { diff --git a/ng-app/src/apps/SocialQueryDemo.svelte b/ng-app/src/apps/SocialQueryDemo.svelte index 33582b0..fe06c32 100644 --- a/ng-app/src/apps/SocialQueryDemo.svelte +++ b/ng-app/src/apps/SocialQueryDemo.svelte @@ -66,6 +66,7 @@ ORDER BY DESC(?total)`; $: source = commits.graph.join(" .\r\n") + (commits.graph.length ? " .":""); let results = []; + let already_started = false; $: if (commits.graph.length > 4) { sparql_query(ranking_query, false).then((res) => { @@ -74,6 +75,17 @@ ORDER BY DESC(?total)`; }); } + $: if (commits) { check_if_started(commits.graph) } + + function check_if_started(graph) { + for (const g of graph) { + if (g.substring(57,91) === "did:ng:x:ng#social_query_forwarder") { + already_started = true; + break; + } + } + } + const query = `PREFIX vcard: PREFIX xskills: PREFIX ksp: @@ -120,6 +132,7 @@ WHERE { let session = $active_session; if (!session) return; let request_nuri = "did:ng:"+$cur_tab.doc.nuri+":c:"+commit_id+":k:"+commit_key; + console.log(request_nuri) await ng.social_query_start( session.session_id, "did:ng:a", @@ -145,7 +158,7 @@ WHERE {