Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# rdf-canonize ChangeLog

## Unreleased

### Removed
- **BREAKING**: Remove all support for `rdf-canonize-native`. The JavaScript
implementation is now the only supported method. Native bindings support
has been completely removed from the library, tests, and documentation due
to limited performance benefits and maintenance overhead.

## 4.0.1 - 2023-11-15

### Fixed
Expand Down
24 changes: 0 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,6 @@ npm install rdf-canonize
const canonize = require('rdf-canonize');
```

### Node.js + npm + native bindings

This package has support for [rdf-canonize-native][]. This package can be
useful if your application requires doing many canonizing operations
asynchronously in parallel or in the background. It is **highly recommended**
that you understand your requirements and benchmark using JavaScript vs native
bindings. The native bindings add overhead and the JavaScript implementation
may be faster with modern runtimes.

The native bindings are not installed by default and must be explicitly
installed.

```
npm install rdf-canonize
npm install rdf-canonize-native
```

Note that the native code is not automatically used. To use the native bindings
you must have them installed and set the `useNative` option to `true`.

```js
const canonize = require('rdf-canonize');
```

### Browser + npm

Expand Down Expand Up @@ -255,4 +232,3 @@ Commercial support for this library is available upon request from
[URDNA2015]: https://w3c.github.io/rdf-canon/spec/#urdna2015
[URGNA2012]: https://w3c.github.io/rdf-canon/spec/#urgna2012
[jsonld.js]: https://github.com/digitalbazaar/jsonld.js
[rdf-canonize-native]: https://github.com/digitalbazaar/rdf-canonize-native
2 changes: 1 addition & 1 deletion benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set:
ONLY=1 npm run benchmark
ONLY=1 TEST_DIR=./benchmark npm run benchmark

Tests are benchmarked with a matrix of {async/sync} {js/native} {x1/x10}.
Tests are benchmarked with a matrix of {async/sync} {js} {x1/x10}.

To run large "block" benchmarks, run the builder script first:

Expand Down
45 changes: 0 additions & 45 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
const RDFC10 = require('./RDFC10');
const RDFC10Sync = require('./RDFC10Sync');

// optional native support
let rdfCanonizeNative;
try {
rdfCanonizeNative = require('rdf-canonize-native');
} catch(e) {}

// return a dataset from input dataset or n-quads
function _inputToDataset(input, options) {
if(options.inputFormat) {
Expand Down Expand Up @@ -80,20 +74,6 @@ function _traceURDNA2015() {
exports.NQuads = require('./NQuads');
exports.IdentifierIssuer = require('./IdentifierIssuer');

/**
* Get or set native API.
*
* @param {object} [api] - The native API.
*
* @returns {object} - The currently set native API.
*/
exports._rdfCanonizeNative = function(api) {
if(api) {
rdfCanonizeNative = api;
}
return rdfCanonizeNative;
};

/**
* Asynchronously canonizes an RDF dataset.
*
Expand All @@ -118,7 +98,6 @@ exports._rdfCanonizeNative = function(api) {
* falsy for a JSON dataset.
* {string} [format] - The format of the output. Omit or use
* 'application/n-quads' for a N-Quads string.
* {boolean} [useNative=false] - Use native implementation.
* {number} [maxWorkFactor=1] - Control of the maximum number of times to run
* deep comparison algorithms (such as the N-Degree Hash Quads algorithm
* used in RDFC-1.0) before bailing out and throwing an error; this is a
Expand Down Expand Up @@ -148,19 +127,6 @@ exports.canonize = async function(input, options = {}) {
const dataset = _inputToDataset(input, options);
_checkOutputFormat(options);

if(options.useNative) {
if(!rdfCanonizeNative) {
throw new Error('rdf-canonize-native not available');
}
if(options.createMessageDigest) {
throw new Error(
'"createMessageDigest" cannot be used with "useNative".');
}
return new Promise((resolve, reject) =>
rdfCanonizeNative.canonize(dataset, options, (err, canonical) =>
err ? reject(err) : resolve(canonical)));
}

if(!('algorithm' in options)) {
throw new Error('No RDF Dataset Canonicalization algorithm specified.');
}
Expand Down Expand Up @@ -202,7 +168,6 @@ exports.canonize = async function(input, options = {}) {
* falsy for a JSON dataset.
* {string} [format] - The format of the output. Omit or use
* 'application/n-quads' for a N-Quads string.
* {boolean} [useNative=false] - Use native implementation.
* {number} [maxWorkFactor=1] - Control of the maximum number of times to run
* deep comparison algorithms (such as the N-Degree Hash Quads algorithm
* used in RDFC-1.0) before bailing out and throwing an error; this is a
Expand Down Expand Up @@ -236,16 +201,6 @@ exports._canonizeSync = function(input, options = {}) {
const dataset = _inputToDataset(input, options);
_checkOutputFormat(options);

if(options.useNative) {
if(!rdfCanonizeNative) {
throw new Error('rdf-canonize-native not available');
}
if(options.createMessageDigest) {
throw new Error(
'"createMessageDigest" cannot be used with "useNative".');
}
return rdfCanonizeNative.canonizeSync(dataset, options);
}
if(!('algorithm' in options)) {
throw new Error('No RDF Dataset Canonicalization algorithm specified.');
}
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@
},
"browser": {
"./lib/MessageDigest.js": "./lib/MessageDigest-webcrypto.js",
"./lib/platform.js": "./lib/platform-browser.js",
"rdf-canonize-native": false
"./lib/platform.js": "./lib/platform-browser.js"
},
"react-native": {
"./lib/MessageDigest.js": "./lib/MessageDigest-webcrypto.js",
"./lib/platform.js": "./lib/platform-browser.js",
"rdf-canonize-native": false
"./lib/platform.js": "./lib/platform-browser.js"
},
"nyc": {
"reporter": [
Expand Down
19 changes: 0 additions & 19 deletions test/test-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@ const fs = require('fs-extra');
const os = require('os');
const path = require('path');

// try to load native bindings
let rdfCanonizeNative;
// try regular load
try {
rdfCanonizeNative = require('rdf-canonize-native');
} catch(e) {
// try peer package
try {
rdfCanonizeNative = require('../../rdf-canonize-native');
} catch(e) {
}
}
// use native bindings
if(!rdfCanonizeNative) {
// skip native tests
console.warn('rdf-canonize-native not found');
}

const entries = [];

if(process.env.TESTS) {
Expand Down Expand Up @@ -85,7 +67,6 @@ const options = {
},
assert,
benchmark,
rdfCanonizeNative,
exit: code => process.exit(code),
earl: {
filename: process.env.EARL
Expand Down
81 changes: 0 additions & 81 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ module.exports = async function(options) {
const assert = options.assert;
const benchmark = options.benchmark;

// use native bindings if available
if(options.rdfCanonizeNative) {
rdfCanonize._rdfCanonizeNative(options.rdfCanonizeNative);
}

const bailOnError = isTrue(options.env.BAIL || 'false');
const verboseSkip = isTrue(options.env.VERBOSE_SKIP || 'false');

Expand Down Expand Up @@ -409,9 +404,6 @@ async function addTest(manifest, test, tests) {
const types = getJsonLdType(test);
throw new Error(`Unknown test type: "${JSON.stringify(types)}"`);
}
const params = testInfo.params.map(param => param(test));
const testOptions = params[1];

// number of parallel jobs for benchmarks
const jobTests = benchmarkOptions.enabled ? benchmarkOptions.jobs : [1];
const fast1 = benchmarkOptions.enabled ? benchmarkOptions.fast1 : true;
Expand Down Expand Up @@ -488,43 +480,6 @@ async function addTest(manifest, test, tests) {
});
}

// async native
if(doAsync && options.rdfCanonizeNative &&
testOptions.algorithm === 'RDFC-1.0') {
jobTests.forEach(jobs => {
const _an_test = {
title: description + ` (asynchronous, native, jobs=${jobs})`,
f: makeFn({
test,
adjustParams: params => {
_commonAdjustParams(params[1], test);
params[1].useNative = true;
return params;
},
run: ({/*test, testInfo,*/ params}) => {
// skip Promise.all
if(jobs === 1 && fast1) {
return options.rdfCanonizeNative.canonize(...params);
}
const all = [];
for(let j = 0; j < jobs; j++) {
all.push(options.rdfCanonizeNative.canonize(...params));
}
return Promise.all(all);
},
jobs,
isBenchmark: benchmarkOptions.enabled
})
};
// 'only' based on test manifest
// 'skip' handled via skip()
if('only' in test) {
_an_test.only = test.only;
}
tests.push(_an_test);
});
}

// sync js
if(doSync) {
jobTests.forEach(jobs => {
Expand Down Expand Up @@ -561,42 +516,6 @@ async function addTest(manifest, test, tests) {
});
}

// sync native
if(doSync && options.rdfCanonizeNative &&
testOptions.algorithm === 'RDFC-1.0') {
jobTests.forEach(jobs => {
const _sn_test = {
title: description + ` (synchronous, native, jobs=${jobs})`,
f: makeFn({
test,
adjustParams: params => {
_commonAdjustParams(params[1], test);
params[1].useNative = true;
return params;
},
run: async ({/*test, testInfo,*/ params}) => {
// skip Promise.all
if(jobs === 1 && fast1) {
return options.rdfCanonizeNative.canonizeSync(...params);
}
const all = [];
for(let j = 0; j < jobs; j++) {
all.push(options.rdfCanonizeNative.canonizeSync(...params));
}
return Promise.all(all);
},
jobs,
isBenchmark: benchmarkOptions.enabled
})
};
// 'only' based on test manifest
// 'skip' handled via skip()
if('only' in test) {
_sn_test.only = test.only;
}
tests.push(_sn_test);
});
}
}

function makeFn({
Expand Down