Mercurial > code > home > repos > streamed-graph
changeset 26:7fe46400f04b
jsonld module now does async
author | drewp@bigasterisk.com |
---|---|
date | Fri, 13 Dec 2019 23:52:43 -0800 |
parents | 86270a59ae7b |
children | e0f5da648199 |
files | src/json_ld_quads.ts |
diffstat | 1 files changed, 11 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/json_ld_quads.ts Fri Dec 13 23:52:23 2019 -0800 +++ b/src/json_ld_quads.ts Fri Dec 13 23:52:43 2019 -0800 @@ -30,29 +30,19 @@ export async function eachJsonLdQuad(jsonLdObj: object, onQuad: (q: Quad) => void) { - return new Promise(function (resolve, reject) { + const expanded = await jsonld.expand(jsonLdObj); - jsonld.expand(jsonLdObj, function onExpand(err, expanded: JsonLd) { - if (err) { - reject(err); + (expanded as JsonLdArray).forEach(function (g: JsonLd) { + var graph = (g as { '@id': string })['@id']; + var graphNode = namedNode(graph); + (g as { '@graph': JsonLdArray })['@graph'].forEach(function (subj: { [predOrId: string]: any; }) { + const subjNode = namedNode(subj['@id']); + for (let pred in subj) { + if (pred === '@id') { + continue; + } + _emitQuad(onQuad, subjNode, pred, subj, graphNode); } - (expanded as JsonLdArray).forEach(function (g: JsonLd) { - var graph = (g as { '@id': string })['@id']; - var graphNode = namedNode(graph); - (g as { '@graph': JsonLdArray })['@graph'].forEach(function (subj: { [predOrId: string]: any; }) { - console.log('process subj', subj) - const subjNode = namedNode(subj['@id']); - for (let pred in subj) { - if (pred === '@id') { - continue; - } - console.log('emit with', pred); - _emitQuad(onQuad, subjNode, pred, subj, graphNode); - } - }); - }); - resolve(); }); }); } -;