Skip to content

Commit 41261bf

Browse files
dahliaclaude
authored andcommitted
Remove rdf-canonize-native support
Remove all support for rdf-canonize-native bindings to simplify the codebase and reduce maintenance overhead. The JavaScript implementation provides sufficient performance for most use cases and eliminates the complexity of native dependencies. - Remove native package loading and initialization - Remove useNative option and _rdfCanonizeNative API - Remove native test cases from test suite - Update documentation to remove native references - Clean up package.json browser/react-native configurations Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3f69b8f commit 41261bf

7 files changed

Lines changed: 11 additions & 174 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# rdf-canonize ChangeLog
22

3+
## Unreleased
4+
5+
### Removed
6+
- **BREAKING**: Remove all support for `rdf-canonize-native`. The JavaScript
7+
implementation is now the only supported method. Native bindings support
8+
has been completely removed from the library, tests, and documentation due
9+
to limited performance benefits and maintenance overhead.
10+
311
## 4.0.1 - 2023-11-15
412

513
### Fixed

README.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,6 @@ npm install rdf-canonize
2525
const canonize = require('rdf-canonize');
2626
```
2727

28-
### Node.js + npm + native bindings
29-
30-
This package has support for [rdf-canonize-native][]. This package can be
31-
useful if your application requires doing many canonizing operations
32-
asynchronously in parallel or in the background. It is **highly recommended**
33-
that you understand your requirements and benchmark using JavaScript vs native
34-
bindings. The native bindings add overhead and the JavaScript implementation
35-
may be faster with modern runtimes.
36-
37-
The native bindings are not installed by default and must be explicitly
38-
installed.
39-
40-
```
41-
npm install rdf-canonize
42-
npm install rdf-canonize-native
43-
```
44-
45-
Note that the native code is not automatically used. To use the native bindings
46-
you must have them installed and set the `useNative` option to `true`.
47-
48-
```js
49-
const canonize = require('rdf-canonize');
50-
```
5128

5229
### Browser + npm
5330

@@ -255,4 +232,3 @@ Commercial support for this library is available upon request from
255232
[URDNA2015]: https://w3c.github.io/rdf-canon/spec/#urdna2015
256233
[URGNA2012]: https://w3c.github.io/rdf-canon/spec/#urgna2012
257234
[jsonld.js]: https://github.com/digitalbazaar/jsonld.js
258-
[rdf-canonize-native]: https://github.com/digitalbazaar/rdf-canonize-native

benchmark/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set:
2525
ONLY=1 npm run benchmark
2626
ONLY=1 TEST_DIR=./benchmark npm run benchmark
2727

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

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

lib/index.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
const RDFC10 = require('./RDFC10');
3838
const RDFC10Sync = require('./RDFC10Sync');
3939

40-
// optional native support
41-
let rdfCanonizeNative;
42-
try {
43-
rdfCanonizeNative = require('rdf-canonize-native');
44-
} catch(e) {}
45-
4640
// return a dataset from input dataset or n-quads
4741
function _inputToDataset(input, options) {
4842
if(options.inputFormat) {
@@ -80,20 +74,6 @@ function _traceURDNA2015() {
8074
exports.NQuads = require('./NQuads');
8175
exports.IdentifierIssuer = require('./IdentifierIssuer');
8276

83-
/**
84-
* Get or set native API.
85-
*
86-
* @param {object} [api] - The native API.
87-
*
88-
* @returns {object} - The currently set native API.
89-
*/
90-
exports._rdfCanonizeNative = function(api) {
91-
if(api) {
92-
rdfCanonizeNative = api;
93-
}
94-
return rdfCanonizeNative;
95-
};
96-
9777
/**
9878
* Asynchronously canonizes an RDF dataset.
9979
*
@@ -118,7 +98,6 @@ exports._rdfCanonizeNative = function(api) {
11898
* falsy for a JSON dataset.
11999
* {string} [format] - The format of the output. Omit or use
120100
* 'application/n-quads' for a N-Quads string.
121-
* {boolean} [useNative=false] - Use native implementation.
122101
* {number} [maxWorkFactor=1] - Control of the maximum number of times to run
123102
* deep comparison algorithms (such as the N-Degree Hash Quads algorithm
124103
* used in RDFC-1.0) before bailing out and throwing an error; this is a
@@ -148,19 +127,6 @@ exports.canonize = async function(input, options = {}) {
148127
const dataset = _inputToDataset(input, options);
149128
_checkOutputFormat(options);
150129

151-
if(options.useNative) {
152-
if(!rdfCanonizeNative) {
153-
throw new Error('rdf-canonize-native not available');
154-
}
155-
if(options.createMessageDigest) {
156-
throw new Error(
157-
'"createMessageDigest" cannot be used with "useNative".');
158-
}
159-
return new Promise((resolve, reject) =>
160-
rdfCanonizeNative.canonize(dataset, options, (err, canonical) =>
161-
err ? reject(err) : resolve(canonical)));
162-
}
163-
164130
if(!('algorithm' in options)) {
165131
throw new Error('No RDF Dataset Canonicalization algorithm specified.');
166132
}
@@ -202,7 +168,6 @@ exports.canonize = async function(input, options = {}) {
202168
* falsy for a JSON dataset.
203169
* {string} [format] - The format of the output. Omit or use
204170
* 'application/n-quads' for a N-Quads string.
205-
* {boolean} [useNative=false] - Use native implementation.
206171
* {number} [maxWorkFactor=1] - Control of the maximum number of times to run
207172
* deep comparison algorithms (such as the N-Degree Hash Quads algorithm
208173
* used in RDFC-1.0) before bailing out and throwing an error; this is a
@@ -236,16 +201,6 @@ exports._canonizeSync = function(input, options = {}) {
236201
const dataset = _inputToDataset(input, options);
237202
_checkOutputFormat(options);
238203

239-
if(options.useNative) {
240-
if(!rdfCanonizeNative) {
241-
throw new Error('rdf-canonize-native not available');
242-
}
243-
if(options.createMessageDigest) {
244-
throw new Error(
245-
'"createMessageDigest" cannot be used with "useNative".');
246-
}
247-
return rdfCanonizeNative.canonizeSync(dataset, options);
248-
}
249204
if(!('algorithm' in options)) {
250205
throw new Error('No RDF Dataset Canonicalization algorithm specified.');
251206
}

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@
8181
},
8282
"browser": {
8383
"./lib/MessageDigest.js": "./lib/MessageDigest-webcrypto.js",
84-
"./lib/platform.js": "./lib/platform-browser.js",
85-
"rdf-canonize-native": false
84+
"./lib/platform.js": "./lib/platform-browser.js"
8685
},
8786
"react-native": {
8887
"./lib/MessageDigest.js": "./lib/MessageDigest-webcrypto.js",
89-
"./lib/platform.js": "./lib/platform-browser.js",
90-
"rdf-canonize-native": false
88+
"./lib/platform.js": "./lib/platform-browser.js"
9189
},
9290
"nyc": {
9391
"reporter": [

test/test-node.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,6 @@ const fs = require('fs-extra');
1515
const os = require('os');
1616
const path = require('path');
1717

18-
// try to load native bindings
19-
let rdfCanonizeNative;
20-
// try regular load
21-
try {
22-
rdfCanonizeNative = require('rdf-canonize-native');
23-
} catch(e) {
24-
// try peer package
25-
try {
26-
rdfCanonizeNative = require('../../rdf-canonize-native');
27-
} catch(e) {
28-
}
29-
}
30-
// use native bindings
31-
if(!rdfCanonizeNative) {
32-
// skip native tests
33-
console.warn('rdf-canonize-native not found');
34-
}
35-
3618
const entries = [];
3719

3820
if(process.env.TESTS) {
@@ -85,7 +67,6 @@ const options = {
8567
},
8668
assert,
8769
benchmark,
88-
rdfCanonizeNative,
8970
exit: code => process.exit(code),
9071
earl: {
9172
filename: process.env.EARL

test/test.js

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ module.exports = async function(options) {
8787
const assert = options.assert;
8888
const benchmark = options.benchmark;
8989

90-
// use native bindings if available
91-
if(options.rdfCanonizeNative) {
92-
rdfCanonize._rdfCanonizeNative(options.rdfCanonizeNative);
93-
}
94-
9590
const bailOnError = isTrue(options.env.BAIL || 'false');
9691
const verboseSkip = isTrue(options.env.VERBOSE_SKIP || 'false');
9792

@@ -409,9 +404,6 @@ async function addTest(manifest, test, tests) {
409404
const types = getJsonLdType(test);
410405
throw new Error(`Unknown test type: "${JSON.stringify(types)}"`);
411406
}
412-
const params = testInfo.params.map(param => param(test));
413-
const testOptions = params[1];
414-
415407
// number of parallel jobs for benchmarks
416408
const jobTests = benchmarkOptions.enabled ? benchmarkOptions.jobs : [1];
417409
const fast1 = benchmarkOptions.enabled ? benchmarkOptions.fast1 : true;
@@ -488,43 +480,6 @@ async function addTest(manifest, test, tests) {
488480
});
489481
}
490482

491-
// async native
492-
if(doAsync && options.rdfCanonizeNative &&
493-
testOptions.algorithm === 'RDFC-1.0') {
494-
jobTests.forEach(jobs => {
495-
const _an_test = {
496-
title: description + ` (asynchronous, native, jobs=${jobs})`,
497-
f: makeFn({
498-
test,
499-
adjustParams: params => {
500-
_commonAdjustParams(params[1], test);
501-
params[1].useNative = true;
502-
return params;
503-
},
504-
run: ({/*test, testInfo,*/ params}) => {
505-
// skip Promise.all
506-
if(jobs === 1 && fast1) {
507-
return options.rdfCanonizeNative.canonize(...params);
508-
}
509-
const all = [];
510-
for(let j = 0; j < jobs; j++) {
511-
all.push(options.rdfCanonizeNative.canonize(...params));
512-
}
513-
return Promise.all(all);
514-
},
515-
jobs,
516-
isBenchmark: benchmarkOptions.enabled
517-
})
518-
};
519-
// 'only' based on test manifest
520-
// 'skip' handled via skip()
521-
if('only' in test) {
522-
_an_test.only = test.only;
523-
}
524-
tests.push(_an_test);
525-
});
526-
}
527-
528483
// sync js
529484
if(doSync) {
530485
jobTests.forEach(jobs => {
@@ -561,42 +516,6 @@ async function addTest(manifest, test, tests) {
561516
});
562517
}
563518

564-
// sync native
565-
if(doSync && options.rdfCanonizeNative &&
566-
testOptions.algorithm === 'RDFC-1.0') {
567-
jobTests.forEach(jobs => {
568-
const _sn_test = {
569-
title: description + ` (synchronous, native, jobs=${jobs})`,
570-
f: makeFn({
571-
test,
572-
adjustParams: params => {
573-
_commonAdjustParams(params[1], test);
574-
params[1].useNative = true;
575-
return params;
576-
},
577-
run: async ({/*test, testInfo,*/ params}) => {
578-
// skip Promise.all
579-
if(jobs === 1 && fast1) {
580-
return options.rdfCanonizeNative.canonizeSync(...params);
581-
}
582-
const all = [];
583-
for(let j = 0; j < jobs; j++) {
584-
all.push(options.rdfCanonizeNative.canonizeSync(...params));
585-
}
586-
return Promise.all(all);
587-
},
588-
jobs,
589-
isBenchmark: benchmarkOptions.enabled
590-
})
591-
};
592-
// 'only' based on test manifest
593-
// 'skip' handled via skip()
594-
if('only' in test) {
595-
_sn_test.only = test.only;
596-
}
597-
tests.push(_sn_test);
598-
});
599-
}
600519
}
601520

602521
function makeFn({

0 commit comments

Comments
 (0)