How to use the jsonld.expand 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 api-platform / api-doc-parser / src / hydra / parseHydraDocumentation.ts View on Github external
docsUrl: string;
  response: Response;
  entrypoint: any;
  docs: any;
}> {
  const d = await fetchJsonLd(entrypointUrl, options);
  const docsUrl = getDocumentationUrlFromHeaders(d.response.headers);

  // @TODO this is suspect according to the jsonld type defs
  const documentLoader = (input: string): Promise =>
    fetchJsonLd(input, options);

  const docsJsonLd = (await fetchJsonLd(docsUrl, options)).body;

  const [docs, entrypoint] = await Promise.all([
    jsonld.expand(docsJsonLd, {
      base: docsUrl,
      documentLoader
    }),
    jsonld.expand(d.body, {
      base: entrypointUrl,
      documentLoader
    })
  ]);

  return {
    entrypointUrl,
    docsUrl,
    entrypoint,
    response: d.response,
    docs
  };
github blake-regalia / graphy.js / lib / main-old / index.js View on Github external
for(let s_key in h_context) {

			// ref value
			let z_value = h_context[s_key];

			// type of value is string; indeed a prefix
			if('string' === typeof z_value) {

				// copy to map
				h_prefixes[s_key] = z_value;
			}
		}
	}

	// transform json-ld to expanded form
	jsonld.expand(h_jsonld, (d_jld_err, a_expanded) => {

		// prepare array for all covered nodes
		let a_entities_unnamespaced = [];

		// prepare set for all top-level nodes
		let as_top_level_nodes = new Set();

		// each subject node in json-ld object
		a_expanded.forEach((h_node) => {

			// ref node id (blanknode or iri)
			let s_id = h_node['@id'];

			// blanknode; track highest blanknode index
			if(s_id.startsWith('_:')) {
				i_highest_blanknode_id = Math.max(i_highest_blanknode_id, ~~s_id.substr(3));
github api-platform / api-doc-parser / src / hydra / parseHydraDocumentation.ts View on Github external
}> {
  const d = await fetchJsonLd(entrypointUrl, options);
  const docsUrl = getDocumentationUrlFromHeaders(d.response.headers);

  // @TODO this is suspect according to the jsonld type defs
  const documentLoader = (input: string): Promise =>
    fetchJsonLd(input, options);

  const docsJsonLd = (await fetchJsonLd(docsUrl, options)).body;

  const [docs, entrypoint] = await Promise.all([
    jsonld.expand(docsJsonLd, {
      base: docsUrl,
      documentLoader
    }),
    jsonld.expand(d.body, {
      base: entrypointUrl,
      documentLoader
    })
  ]);

  return {
    entrypointUrl,
    docsUrl,
    entrypoint,
    response: d.response,
    docs
  };
}
github digitalbazaar / jsonld-signatures / lib / ProofSet.js View on Github external
async function _getTypeInfo({document, documentLoader, expansionMap}) {
  // determine `@type` alias, if any
  const ctx = jsonld.getValues(document, '@context');
  const compacted = await jsonld.compact(
    {'@type': '_:b0'}, ctx, {documentLoader, expansionMap});
  delete compacted['@context'];
  const alias = Object.keys(compacted)[0];

  // optimize: expand only `@type` and `type` values
  const toExpand = {'@context': ctx};
  toExpand['@type'] = jsonld.getValues(document, '@type')
    .concat(jsonld.getValues(document, alias));
  const expanded = (await jsonld.expand(
    toExpand, {documentLoader, expansionMap}))[0] || {};
  return {types: jsonld.getValues(expanded, '@type'), alias};
}
github TangleID / TangleID / packages / jsonld / src / jsonld.ts View on Github external
export const expand = async (doc: any, options: any = {}): Promise => {
  // @ts-ignore
  return jsonld.expand(doc, options);
};
github DefinitelyTyped / DefinitelyTyped / types / jsonld / jsonld-tests.ts View on Github external
.then((compDoc) => {
    log(compDoc);
});

/**
 * expand() test
 */
jsonld.expand(doc, (err, res) => {
    log(res);
});

jsonld.expand(doc, {keepFreeFloatingNodes: false}, (err, res) => {
    log(res);
});

jsonld.expand(doc)
.then((res) => {
    log(res);
});

jsonld.expand(doc, {keepFreeFloatingNodes: false})
.then((res) => {
    log(res);
});

/**
 * flatten() test
 */
jsonld.flatten(doc, context, (err, res) => {
    log(res);
});
github DefinitelyTyped / DefinitelyTyped / types / jsonld / jsonld-tests.ts View on Github external
log(compDoc);
});

jsonld.compact(doc, context, {graph: false})
.then((compDoc) => {
    log(compDoc);
});

/**
 * expand() test
 */
jsonld.expand(doc, (err, res) => {
    log(res);
});

jsonld.expand(doc, {keepFreeFloatingNodes: false}, (err, res) => {
    log(res);
});

jsonld.expand(doc)
.then((res) => {
    log(res);
});

jsonld.expand(doc, {keepFreeFloatingNodes: false})
.then((res) => {
    log(res);
});

/**
 * flatten() test
 */
github ritz078 / transform / pages / jsonld-to-expanded.tsx View on Github external
const transformer = useCallback(async ({ value }) => {
    const jsonLd = await expand(JSON.parse(value));

    return JSON.stringify(jsonLd, null, 2);
  }, []);
github levelgraph / levelgraph-jsonld / index.js View on Github external
function doDel(obj, options, callback) {
    var blanks = {};
    jsonld.expand(obj, options, function(err, expanded) {
      if (err) {
        return callback && callback(err);
      }

      var stream  = graphdb.delStream();
      stream.on('close', callback);
      stream.on('error', callback);

      if (options.base) {
        if (expanded['@context']) {
          expanded['@context']['@base'] = options.base;
        } else {
          expanded['@context'] = { '@base' : options.base };
        }
      }