From 659debc22a533afad7270694f46aada80352d33f Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Sat, 14 Jun 2025 00:36:21 +0900 Subject: [PATCH] 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 --- CHANGELOG.md | 8 +++++ README.md | 24 -------------- benchmark/README.md | 2 +- lib/index.js | 45 ------------------------- package.json | 6 ++-- test/test-node.js | 19 ----------- test/test.js | 81 --------------------------------------------- 7 files changed, 11 insertions(+), 174 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6806fb..87e2e95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 0ddaf4e..225556a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/benchmark/README.md b/benchmark/README.md index 3d3c2d9..9260b14 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -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: diff --git a/lib/index.js b/lib/index.js index e434877..7a74d37 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) { @@ -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. * @@ -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 @@ -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.'); } @@ -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 @@ -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.'); } diff --git a/package.json b/package.json index 2cd7c58..9044842 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/test/test-node.js b/test/test-node.js index 8e9d449..b86ee03 100644 --- a/test/test-node.js +++ b/test/test-node.js @@ -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) { @@ -85,7 +67,6 @@ const options = { }, assert, benchmark, - rdfCanonizeNative, exit: code => process.exit(code), earl: { filename: process.env.EARL diff --git a/test/test.js b/test/test.js index dbbcf58..10b64fc 100644 --- a/test/test.js +++ b/test/test.js @@ -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'); @@ -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; @@ -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 => { @@ -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({