Skip to content

Commit

Permalink
Merge pull request #641 from linkeddata/revert-633-issue#631
Browse files Browse the repository at this point in the history
Revert "removeMetadata"
  • Loading branch information
bourgeoa authored Mar 22, 2024
2 parents 7a40abf + cc97e88 commit ee0ceb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
44 changes: 11 additions & 33 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,47 +871,25 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
}

/**
* Removes all metadata
* Removes all statements in a doc, along with the related metadata including request/response
* @param doc - The document / graph
*/
removeMetadata(doc: Quad_Graph): IndexedFormula {
// temporary until the issue on COLLECTION is resolved see https://github.com/linkeddata/rdflib.js/issues/631
const meta = this.fetcher?.appNode // this.sym('chrome://TheCurrentSession')
const linkNamespaceURI = 'http://www.w3.org/2007/ont/link#'
const kb = this
// removeMatches() --> removeMany() --> remove() fails on Collection
function removeBySubject (subject) {
const sts = kb.statementsMatching(subject, null, null, meta)
// console.log(sts)
for (var i = 0; i < sts.length; i++) {
kb.removeStatement(sts[i])
}
}
const requests = this.statementsMatching(null, this.sym(`${linkNamespaceURI}requestedURI`), this.rdfFactory.literal(doc.value), meta).map(st => st.subject)
removeDocument(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 != null) { // null or undefined
if (request !== undefined) {
this.removeMatches(request, null, null, meta)
const response = this.any(request, this.sym(`${linkNamespaceURI}response`), null, meta) as Quad_Subject
// console.log('REQUEST ' + request.value)
removeBySubject(request)
if (response != null) { // null or undefined
// console.log('RESPONSE ' + response.value)
removeBySubject(response)
if (response !== undefined) { // ts
this.removeMatches(response, null, null, meta)
}
}
}
// console.log('DOCTYPE ' + doc.value)
removeBySubject(doc)
return this
}

/**
* Removes all statements in a doc, along with the related metadata including request/response
* @param doc - The document / graph
*/
removeDocument(doc: Quad_Graph): IndexedFormula {
// remove request/response and metadata
this.removeMetadata(doc)
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
Expand Down
15 changes: 4 additions & 11 deletions tests/unit/update-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,6 @@ 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 @@ -244,9 +233,13 @@ 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)
})

Expand Down

0 comments on commit ee0ceb0

Please sign in to comment.