Skip to content

Commit

Permalink
Merge pull request #644 from linkeddata/removeMetadata
Browse files Browse the repository at this point in the history
Remove metadata
  • Loading branch information
bourgeoa authored Mar 24, 2024
2 parents 3e2aa53 + 694a1c2 commit e72fe6d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 18 deletions.
27 changes: 18 additions & 9 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,27 +875,36 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
* @param doc - The document / graph
*/
removeDocument(doc: Quad_Graph): IndexedFormula {
this.removeMetadata(doc)
// remove document
var sts: Quad[] = this.statementsMatching(undefined, undefined, undefined, doc).slice() // Take a copy as this is the actual index
for (var i = 0; i < sts.length; i++) {
this.removeStatement(sts[i])
}
return this
}

removeMetadata(doc: Quad_Graph): IndexedFormula {
const meta = this.sym('chrome://TheCurrentSession') // or this.rdfFactory.namedNode('chrome://TheCurrentSession')
const linkNamespaceURI = 'http://www.w3.org/2007/ont/link#' // alain
// remove request/response and metadata
const requests = this.statementsMatching(undefined, this.sym(`${linkNamespaceURI}requestedURI`), this.rdfFactory.literal(doc.value), meta).map(st => st.subject)
for (var r = 0; r < requests.length; r++) {
const request = requests[r]
if (request !== undefined) {
this.removeMatches(request, null, null, meta)
if (request != undefined) {
const response = this.any(request, this.sym(`${linkNamespaceURI}response`), null, meta) as Quad_Subject
if (response !== undefined) { // ts
if (response != undefined) { // ts
this.removeMatches(response, null, null, meta)
}
// may be not needed
const status = this.any(request, this.sym(`${linkNamespaceURI}status`), null, meta) as Quad_Subject
if (status != undefined) { // ts
this.removeMatches(status, null, null, meta)
}
this.removeMatches(request, null, null, meta)
}
}
this.removeMatches(this.sym(doc.value), null, null, meta) // content-type

// remove document
var sts: Quad[] = this.statementsMatching(undefined, undefined, undefined, doc).slice() // Take a copy as this is the actual index
for (var i = 0; i < sts.length; i++) {
this.removeStatement(sts[i])
}
return this
}

Expand Down
74 changes: 74 additions & 0 deletions tests/unit/indexed-formula-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import IndexedFormula from '../../src/store'
import NamedNode from '../../src/named-node'
import { RDFArrayRemove } from '../../src/utils-js'
import DataFactory from '../../src/factories/rdflib-data-factory'
import parse from '../../src/parse'
import serialize from '../../src/serialize'

describe('IndexedFormula', () => {
const g0 = NamedNode.fromValue('https://example.com/graph0')
Expand Down Expand Up @@ -340,4 +342,76 @@ describe('IndexedFormula', () => {
expect(store1.holdsStatement(store0)).to.be.true()
})
});
describe('removeDocument', () => {
const store = new IndexedFormula()
const meta = store.sym('chrome://TheCurrentSession')
const prefixes = `@prefix : <#>.
@prefix http: <http://www.w3.org/2007/ont/http#>.
@prefix httph: <http://www.w3.org/2007/ont/httph#>.
@prefix tabont: <http://www.w3.org/2007/ont/link#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix pro: <https://bob.localhost:8443/profile/>.
@prefix tur: <http://www.w3.org/ns/iana/media-types/text/turtle#>.
pro:card a tabont:Document, tabont:RDFDocument, tur:Resource.
`
const metaContent = prefixes + `
[
rdfs:label "[0:16:34] Request for https://bob.localhost:8443/profile/card";
tabont:requestedURI "https://bob.localhost:8443/profile/card";
tabont:response
[
http:status 200;
http:statusText "OK";
httph:accept-patch
"text/n3, application/sparql-update, application/sparql-update-single-match";
httph:accept-post "*/*";
httph:accept-put "*/*";
httph:access-control-allow-credentials "true";
httph:access-control-expose-headers
"Authorization, User, Location, Link, Vary, Last-Modified, ETag, Accept-Patch, Accept-Post, Accept-Put, Updates-Via, Allow, WAC-Allow, Content-Length, WWW-Authenticate, MS-Author-Via, X-Powered-By";
httph:allow "OPTIONS, HEAD, GET, PATCH, POST, PUT, DELETE";
httph:connection "keep-alive";
httph:content-type "text/turtle";
httph:date "Thu, 08 Feb 2024 23:16:35 GMT";
httph:keep-alive "timeout=5";
httph:link
'<card.acl>; rel=\"acl\", <card.meta>; rel=\"describedBy\", <http://www.w3.org/ns/ldp#Resource>; rel=\"type\"';
httph:ms-author-via "SPARQL";
httph:transfer-encoding "chunked";
httph:updates-via "wss://bob.localhost:8443";
httph:vary "Accept, Authorization, Origin";
httph:wac-allow 'user=\"read write append control\",public=\"read\"';
httph:x-powered-by "solid-server/5.7.9-beta"
];
tabont:status
( "[0:16:35.259] N3 parsed: 13 triples in 26 lines."
"[0:16:35.259] Done." )
].
`
const voidDoc = `@prefix : <#>.
`

it ('removeMetada', () => {
parse(metaContent, store, meta.value, 'text/turtle')
store.removeMetadata(store.sym('https://bob.localhost:8443/profile/card'))
expect(serialize(meta, store, meta.uri)).to.eql(voidDoc)
})
it ('removeDocument', () => {
parse(metaContent, store, meta.value, 'text/turtle')
const doc = store.sym('https://bob.localhost:8443/profile/card')
const docContent = `
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
<#test> <#value> [ rdf:first 1; rdf:rest [ rdf:first 2; rdf:rest [ rdf:first 3; rdf:rest rdf:nil ]]] .
`
parse(docContent, store, doc.uri, 'text/turtle')
console.log(serialize(null, store, meta.uri))
store.removeDocument(store.sym('https://bob.localhost:8443/profile/card'))
expect(serialize(meta, store, null)).to.eql(voidDoc)
expect(serialize(doc, store, doc.uri)).to.eql(voidDoc)
})
})
})
20 changes: 11 additions & 9 deletions tests/unit/update-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ describe('UpdateManager', () => {
expect(updater.editable(doc1)).to.equal(undefined)
})

it('Should not detect a document is editable from metadata after removeMetadata', () => {
loadMeta(updater.store)
updater.store.removeMetadata(doc1)
expect(updater.editable(doc1)).to.equal(undefined)
})

it('Should not detect a document is editable from metadata after removeDocument', () => {
loadMeta(updater.store)
updater.store.removeDocument(doc1)
expect(updater.editable(doc1)).to.equal(undefined)
})

it('Async version should detect a document is editable from metadata', async () => {
loadMeta(updater.store)
Expand All @@ -233,19 +244,10 @@ describe('UpdateManager', () => {

it('Async version should not detect a document is editable from metadata after flush', async () => {
loadMeta(updater.store)

expect(updater.editable(doc1)).to.equal('SPARQL')

updater.flagAuthorizationMetadata()

const result = await updater.checkEditable(doc1)

expect(result).to.equal(undefined)
})


})



})

0 comments on commit e72fe6d

Please sign in to comment.