@fluree/fluree-context-utils
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -229,4 +229,42 @@ const jsonld = require('jsonld'); | ||
// Check if the property also exists in obj2 | ||
if (['@context', '@graph', '@id', '@type'].includes(key)) { | ||
if (['@context', '@graph', '@id'].includes(key)) { | ||
intersection[key] = obj1[key]; | ||
} else if (key === '@type') { | ||
if (Array.isArray(obj1[key])) { | ||
let newTypeArray = []; | ||
for (const ldType of obj1[key]) { | ||
if (obj2.hasOwnProperty(ldType)) { | ||
if (expandContext) { | ||
newContext[ldType] = obj2[ldType]; | ||
const id = obj2[ldType]?.['@id']; | ||
if (!id) { | ||
throw new TypeError( | ||
`The following @type value is invalid: ${ldType} of IRI ${obj2[ldType]} appears not to be a Class` | ||
); | ||
} | ||
const namespace = getInitialString(id); | ||
if (namespace) { | ||
newContext[namespace] = obj2[namespace]; | ||
} | ||
} | ||
newTypeArray.push(ldType); | ||
} else if (obj2.hasOwnProperty(getInitialString(ldType))) { | ||
newTypeArray.push(ldType); | ||
} | ||
} | ||
if (newTypeArray.length > 0) { | ||
intersection[key] = newTypeArray; | ||
} | ||
} else { | ||
if (obj2.hasOwnProperty(obj1[key])) { | ||
if (expandContext) { | ||
newContext[obj1[key]] = obj2[obj1[key]]; | ||
const namespace = getInitialString(obj2[obj1[key]]?.['@id']); | ||
if (namespace) { | ||
newContext[namespace] = obj2[namespace]; | ||
} | ||
} | ||
intersection[key] = obj1[key]; | ||
} | ||
} | ||
} else if (obj2.hasOwnProperty(key)) { | ||
@@ -233,0 +271,0 @@ // If it exists, add it to the intersection object |
const flureeContext = require('./index'); | ||
const jsonldDoc = { | ||
//note this invalid URL that will cause an | ||
//invalid URL error if errorOnInvalidUrl is TRUE: | ||
'@context': 'https://woop-woop-not-a-site.org', | ||
'@context': ['https://schema.org', { wiki: 'http://wikidata.org/' }], | ||
'@id': 'https://www.wikidata.org/wiki/Q836821', | ||
'@type': ['Movie'], | ||
//Bad Type!! | ||
'@type': 'GLURPY', | ||
name: "The Hitchhiker's Guide to the Galaxy", | ||
@@ -18,6 +17,9 @@ isBasedOn: { | ||
const validatedJsonldDoc = flureeContext | ||
.includeVocabulary(jsonldDoc, { | ||
errorOnInvalidUrl: true, | ||
.validate(jsonldDoc, { expandContext: false }) | ||
.then((x) => { | ||
// debugger; | ||
console.log(JSON.stringify(x, null, 2)); | ||
}) | ||
.catch((err) => { | ||
// debugger; | ||
console.log(err); | ||
@@ -24,0 +26,0 @@ /* |
{ | ||
"name": "@fluree/fluree-context-utils", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "NodeJS Library helping to dereference context and vocabulary documents from URLs, particularly for use with JSON-LD FlureeDB.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34509
643