Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
debug('before patch', store.toNT())
const originSym = rdflib.sym(origin)
// remove existing statements on same origin - if it exists
debug('finding statements about ', origin)
store.statementsMatching(null, rdflib.sym(ACL['origin'].toString()), originSym).forEach((st: any) => {
debug('found', st)
debug('removing trustedApp statements with object ', st.subject)
store.removeStatements([...store.statementsMatching(null, rdflib.sym(ACL['trustedApp'].toString()), st.subject)])
debug('removing statements with subject ', st.subject)
store.removeStatements([...store.statementsMatching(st.subject)])
})
debug('after removing', store.toNT())
// add new triples
const application = new rdflib.BlankNode()
store.add(rdflib.sym(webId.toString()), rdflib.sym(ACL['trustedApp'].toString()), application, rdflib.sym(webId.toString()))
store.add(application, rdflib.sym(ACL['origin'].toString()), originSym, rdflib.sym(webId.toString()))
modes.forEach(mode => {
debug('adding', application, ACL['mode'], mode)
store.add(application, rdflib.sym(ACL['mode'].toString()), rdflib.sym(mode.toString()))
})
debug('after patch', store.toNT())
const turtleDoc: string = rdflib.serialize(undefined, store, webId.toString(), 'text/turtle')
await blob.setData(await objectToStream(makeResourceData(resourceData.contentType, turtleDoc)))
}
async registerApp (ldp, appOrigin, accessModes, webId) {
debug(`Registering app (${appOrigin}) with accessModes ${accessModes} for webId ${webId}`)
const store = await this.getProfileGraph(ldp, webId)
const origin = $rdf.sym(appOrigin)
// remove existing statements on same origin - if it exists
store.statementsMatching(null, ACL('origin'), origin).forEach(st => {
store.removeStatements([...store.statementsMatching(null, ACL('trustedApp'), st.subject)])
store.removeStatements([...store.statementsMatching(st.subject)])
})
// add new triples
const application = new $rdf.BlankNode()
store.add($rdf.sym(webId), ACL('trustedApp'), application, webId)
store.add(application, ACL('origin'), origin, webId)
accessModes.forEach(mode => {
store.add(application, ACL('mode'), ACL(mode))
})
await this.saveProfileGraph(ldp, store, webId)
}
it("returns null without onError and registered resource", () => {
const opts = ctx.empty();
const resolved = errorComponent({
subject: new BlankNode(),
topology: defaultNS.ex("t"),
}, opts.lrs);
expect(resolved).toBeNull();
});
});
it("renders blank nodes", () => {
const bn = new BlankNode();
const opts = ctx.chargeLRS(
[
new Statement(bn, defaultNS.rdf("type"), defaultNS.schema("Thing")),
new Statement(bn, defaultNS.schema("name"), new Literal("title")),
],
bn,
);
const comp = createTestElement();
opts.lrs.registerAll(LinkedRenderStore.registerRenderer(comp, defaultNS.schema("Thing")));
const elem = mount(
opts.wrapComponent(createElement(LinkedResourceContainer, {
loadLinkedObject,
subject: bn,
})),
);
const comp = () => {
useDataFetching({ subject: new BlankNode() }, 0, setError);
return null;
};
export function newBlankNode (): RdfJsTerm {
return new rdflib.BlankNode()
}
export function getStatementsToAdd (
origin: NamedNode,
nodeName: string,
modes: Mode[],
person: NamedNode,
ns: Namespaces
) {
var application = new $rdf.BlankNode(`bn_${nodeName}`)
return [
$rdf.st(person, ns.acl('trustedApp'), application, person.doc()),
$rdf.st(application, ns.acl('origin'), origin, person.doc()),
...modes
.map(mode => {
return ns.acl(mode)
})
.map(mode => $rdf.st(application, ns.acl('mode'), mode, person.doc()))
]
}
export function getStatementsToAdd (
origin: NamedNode,
nodeName: string,
modes: string[],
person: NamedNode,
ns: Namespaces
) {
var application = new BlankNode(`bn_${nodeName}`)
return [
st(person, ns.acl('trustedApp'), application, person.doc()),
st(application, ns.acl('origin'), origin, person.doc()),
...modes
.map(mode => sym(mode))
.map(mode => st(application, ns.acl('mode'), mode, person.doc()))
]
}
function getStatementsToAdd(origin, nodeName, modes, person, ns) {
var application = new $rdf.BlankNode("bn_" + nodeName);
return [
$rdf.st(person, ns.acl('trustedApp'), application, person.doc()),
$rdf.st(application, ns.acl('origin'), origin, person.doc())
].concat(modes
.map(function (mode) { return $rdf.sym(mode); })
.map(function (mode) { return $rdf.st(application, ns.acl('mode'), mode, person.doc()); }));
}
exports.getStatementsToAdd = getStatementsToAdd;