How to use the jsonld.promises function in jsonld

To help you get started, we’ve selected a few jsonld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / service / linkeddata-service-won.js View on Github external
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);
github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / service / linkeddata-service-won.js View on Github external
.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 => {
github mb21 / api-explorer / apiService.js View on Github external
//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;
                    }
                }
github bergos / hydra-middleware / examples / calendar / model.js View on Github external
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: {
github bergos / hydra-middleware / examples / api-demo / model.js View on Github external
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: {
github bergos / hydra-core / examples / api-demo.js View on Github external
* [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'
github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / won-message-utils.js View on Github external
const framingAttempts = acceptedSources.map(source =>
        jsonld.promises.frame(msgJson, {
            '@context': {
                'won': 'http://purl.org/webofneeds/model#',
                'msg': 'http://purl.org/webofneeds/message#'
            },
            '@type': source
        }));