activitystreams-xl
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "activitystreams-xl", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "ActivityStreams 1.0 & 2.0 parsing and translation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
26
xml.js
@@ -5,2 +5,3 @@ const ltx = require('ltx'); | ||
const ACTIVITYNS = 'http://activitystrea.ms/spec/1.0/'; | ||
const AS2NS = 'https://www.w3.org/ns/activitystreams'; | ||
const POCONS = "http://portablecontacts.net/spec/1.0"; | ||
@@ -12,3 +13,24 @@ //const MASTODONNS = "http://mastodon.social/schema/1.0"; | ||
const jsonld = require('jsonld').promises; | ||
const as2context = require('./as2.context.json'); | ||
const nodeDocumentLoader = require('jsonld').documentLoaders.node(); | ||
const CONTEXTS = { | ||
[AS2NS]: as2context | ||
} | ||
const documentLoader = function(url, callback) { | ||
if(url in CONTEXTS) { | ||
return callback( | ||
null, { | ||
contextUrl: null, // this is for a context via a link header | ||
document: CONTEXTS[url], // this is the actual document that was loaded | ||
documentUrl: url // this is the actual context URL after redirects | ||
}); | ||
} | ||
nodeDocumentLoader(url, callback); | ||
}; | ||
module.exports = { | ||
@@ -35,3 +57,3 @@ parse | ||
const as1 = entry2as1(el); | ||
return jsonld.compact(addContext(as1ToAS2(as1)), 'https://www.w3.org/ns/activitystreams'); | ||
return jsonld.compact(addContext(as1ToAS2(as1)), 'https://www.w3.org/ns/activitystreams', { documentLoader }); | ||
} | ||
@@ -64,3 +86,3 @@ | ||
return Object.assign({ | ||
'@context': 'https://www.w3.org/ns/activitystreams' | ||
'@context': AS2NS | ||
}, obj); | ||
@@ -67,0 +89,0 @@ } |
117212
12
3569