Skip to content

Commit

Permalink
Filter deltas: Add rdflib.js and class Delta
Browse files Browse the repository at this point in the history
  • Loading branch information
peternowee committed Oct 9, 2023
1 parent f7e03f8 commit 15ac139
Show file tree
Hide file tree
Showing 5 changed files with 2,416 additions and 179 deletions.
6 changes: 5 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// eslint-disable-next-line no-unused-vars
import { NamedNode, triple } from 'rdflib';
import bodyParser from 'body-parser';
import { LOG_INCOMING_DELTA } from './config';
import { app, query, errorHandler } from 'mu';
// eslint-disable-next-line no-unused-vars
import { Delta } from './lib/delta';

app.get('/', function (req, res) {
res.send('Hello from virus-scanner-service');
Expand Down Expand Up @@ -31,7 +35,7 @@ app.post(
console.log(`Receiving delta : ${JSON.stringify(body)}`);
}

//await processDelta(body);
// ...

res.status(202).send();
} catch (error) {
Expand Down
Empty file added lib/.gitkeep
Empty file.
32 changes: 32 additions & 0 deletions lib/delta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { NamedNode, triple } from 'rdflib';

export class Delta {
constructor(delta) {
this.delta = delta;
}

get inserts() {
return this.delta.map((changeSet) => changeSet.inserts).flat();
}

getInsertsFor(trigger) {
return this.inserts
.filter((triple) => this.isTriggerTriple(triple, trigger))
.map(this.mapToRdfTriple);
}

isTriggerTriple(triple, trigger) {
return (
triple.predicate.value === trigger.predicate.value &&
triple.object.value === trigger.object.value
);
}

mapToRdfTriple(t) {
return triple(
new NamedNode(t.subject.value),
new NamedNode(t.predicate.value),
new NamedNode(t.object.value),
);
}
}
Loading

0 comments on commit 15ac139

Please sign in to comment.