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

@rmlio/rmlmapper-java-wrapper

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rmlio/rmlmapper-java-wrapper - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

7

CHANGELOG.md

@@ -10,2 +10,8 @@ # Changelog

## [1.1.1] - 2021-03-25
### Changed
- Use latest version of n3.js
- Use async/await where possible
## [1.1.0] - 2021-02-25

@@ -64,2 +70,3 @@

[1.1.1]: https://github.com/RMLio/rmlmapper-java-wrapper-js/compare/v1.1.0...v1.1.1
[1.1.0]: https://github.com/RMLio/rmlmapper-java-wrapper-js/compare/v1.0.1...v1.1.0

@@ -66,0 +73,0 @@ [1.0.1]: https://github.com/RMLio/rmlmapper-java-wrapper-js/compare/v1.0.0...v1.0.1

175

lib/wrapper.js

@@ -10,5 +10,6 @@ /**

const N3 = require('n3');
const { DataFactory, Parser, Writer } = N3;
const { literal } = DataFactory;
const { strToQuads } = require('./utils');
const {DataFactory, Parser, Writer} = N3;
const {literal, quad} = DataFactory;
const newQuad = quad;
const {strToQuads} = require('./utils');

@@ -60,102 +61,96 @@ const sourceFilePrefix = "data-";

return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
// current time
const ms = new Date().getTime();
// folder where the data used by the RMLMapper is stored
const processDir = path.resolve(this.tempFolder, '' + ms);
const processDir = path.resolve(this.tempFolder, '' + ms);
fs.mkdir(processDir, () => {
const logFile = path.resolve(processDir, 'rmlmapper.log');
const sourceDirPrefix = path.resolve(processDir, sourceFilePrefix);
const self = this;
await fs.mkdir(processDir);
const callback = async function (error) {
if (error) {
reject(error);
} else {
const mappingFile = path.resolve(processDir, 'mapping.rml.ttl');
const logFile = path.resolve(processDir, 'rmlmapper.log');
const sourceDirPrefix = path.resolve(processDir, sourceFilePrefix);
try {
const rmlStr = await self._setSourcesInRMLRules(rml, sourceDirPrefix);
if (options.sources) {
await this._saveSources(options.sources, sourceDirPrefix);
}
fs.writeFile(mappingFile, rmlStr, function (error) {
if (error) {
reject(error);
} else {
const outputFile = path.resolve(processDir, "output." + options.serialization);
const metadataFile = path.resolve(processDir, "metadata." + options.serialization);
try {
const result = await this._executeCLI({rml, sourceDirPrefix, processDir, logFile,
serialization: options.serialization,
asQuads: options.asQuads,
generateMetadata: options.generateMetadata});
resolve(result)
} catch (e) {
reject (e);
}
});
}
let execCommand = `java `;
async _executeCLI(options) {
const {rml, sourceDirPrefix, processDir, logFile, serialization, asQuads, generateMetadata} = options;
const mappingFile = path.resolve(processDir, 'mapping.rml.ttl');
Object.keys(self.javaVMOptions).forEach(key => {
const value = self.javaVMOptions[key];
execCommand += `-${key}=${value} `
});
const rmlStr = await this._setSourcesInRMLRules(rml, sourceDirPrefix);
execCommand += `-jar ${self.path} -m ${mappingFile} -o ${outputFile} -s ${options.serialization}`;
await fs.writeFile(mappingFile, rmlStr);
const outputFile = path.resolve(processDir, "output." + serialization);
const metadataFile = path.resolve(processDir, "metadata." + serialization);
if (options.generateMetadata) {
execCommand += ` -l triple -e ${metadataFile}`;
}
let execCommand = `java `;
exec(execCommand, function (error, stdout, stderr) {
Object.keys(this.javaVMOptions).forEach(key => {
const value = this.javaVMOptions[key];
execCommand += `-${key}=${value} `
});
if (stderr) {
fs.writeFileSync(logFile, stderr);
const err = new Error(`Error while executing the rules.`);
err.log = stderr;
reject(err);
} else {
fs.readFile(outputFile, 'utf8', async (outputErr, output) => {
if (outputErr) {
outputErr.message = `Error while reading output file '${outputFile}'`;
reject(outputErr);
} else {
if (options.asQuads) {
output = await strToQuads(output);
}
execCommand += `-jar ${this.path} -m ${mappingFile} -o ${outputFile} -s ${serialization}`;
if (options.generateMetadata) {
fs.readFile(metadataFile, 'utf8', async (metadataErr, metadata) => {
if (metadataErr) {
metadataErr.message = `Error while reading output file '${metadataFile}'`;
reject(metadataErr);
} else {
if (options.asQuads) {
metadata = await strToQuads(metadata);
}
if (generateMetadata) {
execCommand += ` -l triple -e ${metadataFile}`;
}
resolve({output, metadata});
}
});
} else {
resolve({output});
}
}
return new Promise((resolve, reject) => {
exec(execCommand, async (error, stdout, stderr) => {
if (stderr) {
await fs.writeFile(logFile, stderr);
const err = new Error(`Error while executing the rules.`);
err.log = stderr;
reject(err);
} else {
try {
let output = await fs.readFile(outputFile, 'utf8');
if (self.removeTempFolders) {
fs.remove(processDir, err => {
if (err) {
err.message = `Unable to remove temp folder "${processDir}.`;
reject(err)
}
});
}
});
}
});
if (asQuads) {
output = await strToQuads(output);
}
if (generateMetadata) {
try {
let metadata = await fs.readFile(metadataFile, 'utf8');
if (asQuads) {
metadata = await strToQuads(metadata);
}
});
} catch (error) {
reject(error);
resolve({output, metadata});
} catch (metadataErr) {
metadataErr.message = `Error while reading output file '${metadataFile}'`;
reject(metadataErr);
}
} else {
resolve({output});
}
} catch (outputError) {
outputError.message = `Error while reading output file '${outputFile}'`;
reject(outputError);
}
};
if (options.sources) {
this._saveSources(options.sources, sourceDirPrefix)
.then(callback)
.catch(reject);
} else {
callback();
if (this.removeTempFolders) {
try {
await fs.remove(processDir);
} catch (err) {
err.message = `Unable to remove temp folder "${processDir}.`;
reject(err);
}
}
}

@@ -232,6 +227,12 @@ });

return new Promise((resolve, reject) => {
rmlQuads.forEach(quad => {
if (quad.predicate.value === 'http://semweb.mmlab.be/ns/rml#source' && quad.object.termType === 'Literal') {
quad.object = literal(prefix + quad.object.value);
const adjustedRMLQuads = [];
rmlQuads.forEach(rmlQuad => {
let adjustedQuad = rmlQuad;
if (rmlQuad.predicate.value === 'http://semweb.mmlab.be/ns/rml#source' && rmlQuad.object.termType === 'Literal') {
adjustedQuad = newQuad(rmlQuad.subject, rmlQuad.predicate, literal(prefix + rmlQuad.object.value));
}
adjustedRMLQuads.push(adjustedQuad);
});

@@ -241,3 +242,3 @@

writer.addQuads(rmlQuads);
writer.addQuads(adjustedRMLQuads);
writer.end((error, result) => {

@@ -244,0 +245,0 @@ if (error) {

{
"name": "@rmlio/rmlmapper-java-wrapper",
"version": "1.1.0",
"version": "1.1.1",
"description": "A JavaScript wrapper around the Java RMLMapper.",

@@ -19,3 +19,3 @@ "main": "index.js",

"fs-extra": "^7.0.1",
"n3": "^1.0.5",
"n3": "^1.9.0",
"rdf-isomorphic": "^1.1.0"

@@ -22,0 +22,0 @@ },

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