Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const jsonldjsQuads = {
// everything in our rdfstore is in the default-graph atm
'@default': triples.map(triple => ({
subject: rdfstorejsToJsonldjs(triple.subject),
predicate: rdfstorejsToJsonldjs(triple.predicate),
object: rdfstorejsToJsonldjs(triple.object),
//object.datatype: ? //TODO
}))
};
//console.log('jsonldjsQuads: ', jsonldjsQuads);
const context = frame['@context']? clone(frame['@context']) : {}; //TODO
context.useNativeTypes = true; //do some of the parsing from strings to numbers
const jsonLdP = jld.promises
.fromRDF(jsonldjsQuads, context)
.then(complexJsonLd => {
//the framing algorithm expects an js-object with an `@graph`-property
const complexJsonLd_ = complexJsonLd['@graph'] ?
complexJsonLd :
{'@graph': complexJsonLd};
//console.log('complexJsonLd_: ', complexJsonLd_);
return jld.promises.frame(complexJsonLd_, frame);
})
.then(framed => {
console.log('framed: ', framed);
return framed;
})
.catch(err => {
console.error('Failed to frame need-data.', needUri, err);
.then(complexJsonLd => {
//the framing algorithm expects an js-object with an `@graph`-property
const complexJsonLd_ = complexJsonLd['@graph'] ?
complexJsonLd :
{'@graph': complexJsonLd};
//console.log('complexJsonLd_: ', complexJsonLd_);
return jld.promises.frame(complexJsonLd_, frame);
})
.then(framed => {
//try to set baseUrl right
var contextType = typeof obj["@context"];
if (contextType === "string") {
//external context
var absoluteContext = URI(obj["@context"]).absoluteTo(url).toString();
obj["@context"] = [
absoluteContext, {
"@base": url
}
];
} else if (contextType === "object") {
//in-document context
obj["@context"]["@base"] = url;
}
return jsonld.promises().expand(obj) //if this breaks, just redownload from url to get baseUrl etc. right
.then( function(expanded) {
var isId = function(val, key) { return key == "@id"; };
var rawlinks = deepCollect(expanded, function(obj) {
return _u.filter(obj, isId);
});
var links = [];
rawlinks.forEach( function(link) {
//try to find originial key of link to use as rel, bit hacky, doesn't always work
var rel = link;
for( var key in obj) {
if ( endsWith(link, obj[key]) ) {
rel = key;
break;
}
}
var
hydra = require('hydra-core'),
jsonldp = require('jsonld').promises(),
path = require('path');
var Model = function() {
this.init = function (api) {
this.api = api;
};
this.createEntryPoint = function (iri, controller) {
var entryPointClass = this.api.findClass(Model.ns.EntryPoint);
return hydra.model.create(entryPointClass, {
'@context': Model.ns.context,
'@id': iri,
event: {
var
hydra = require('hydra-core'),
jsonldp = require('jsonld').promises(),
path = require('path');
var Model = function () {
this.init = function (api) {
this.api = api;
};
this.createEntryPoint = function (iri, controller) {
var entryPointClass = this.api.findClass(Model.ns.EntryPoint);
return hydra.model.create(entryPointClass, {
'@context': Model.ns.EntryPointContext,
'@id': iri,
issues: {
* [1] http://www.markus-lanthaler.com/hydra/api-demo/
* [2] http://www.markus-lanthaler.com/hydra/console/
*/
global.Promise = require('es6-promise').Promise;
/**
* !!! change this to true if you want to keep the created objects !!!
*/
var dontDelete = false;
var
hydra = require('../'),
jsonldp = require('jsonld').promises();
var ns = {
Issue: 'http://www.markus-lanthaler.com/hydra/api-demo/vocab#Issue',
User: 'http://www.markus-lanthaler.com/hydra/api-demo/vocab#User',
issues: 'http://www.markus-lanthaler.com/hydra/api-demo/vocab#EntryPoint/issues',
registerUser: 'http://www.markus-lanthaler.com/hydra/api-demo/vocab#EntryPoint/registerUser'
};
var config = {
//base: 'http://www.markus-lanthaler.com',
base: 'http://localhost:8080',
user: 'hydracore',
email: 'hydracore@test.com',
password: '123456'
const framingAttempts = acceptedSources.map(source =>
jsonld.promises.frame(msgJson, {
'@context': {
'won': 'http://purl.org/webofneeds/model#',
'msg': 'http://purl.org/webofneeds/message#'
},
'@type': source
}));