# HG changeset patch # User drewp@bigasterisk.com # Date 1576309963 28800 # Node ID 7fe46400f04b2f598822783c566e3261053a2ea6 # Parent 86270a59ae7bc586d0d1854b4525bfaf0bf101a6 jsonld module now does async diff -r 86270a59ae7b -r 7fe46400f04b src/json_ld_quads.ts --- 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(); }); }); } -;