Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fluree/fluree-context-utils

Package Overview
Dependencies
Maintainers
9
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluree/fluree-context-utils - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

40

lib/flureeContext.js

@@ -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

14

lib/tests.js
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": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc