Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
};
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));
}> {
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
};
}
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};
}
export const expand = async (doc: any, options: any = {}): Promise => {
// @ts-ignore
return jsonld.expand(doc, options);
};
.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);
});
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
*/
const transformer = useCallback(async ({ value }) => {
const jsonLd = await expand(JSON.parse(value));
return JSON.stringify(jsonLd, null, 2);
}, []);
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 };
}
}