Skip to content

Instantly share code, notes, and snippets.

@alpox
Last active March 23, 2018 20:30
Show Gist options
  • Save alpox/88fa8ba7ac298c9080ca40828791b4b0 to your computer and use it in GitHub Desktop.
Save alpox/88fa8ba7ac298c9080ca40828791b4b0 to your computer and use it in GitHub Desktop.
enricher
const { transformFactory } = require('../utils/stream');
const { GENERATED_AT_TIME } = require('../utils/constants');
module.exports = transformFactory((stream, config, transform) => data => {
const transformed = transform(data);
const id = transformed[0].subject;
const graph = transformed.reduce(
(acc, triple) => {
acc[triple.predicate] = { '@id': triple.object };
return acc;
},
{ '@id': id }
);
stream.push({
'@id': id,
'@graph': graph,
[GENERATED_AT_TIME]: new Date()
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment