You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ji...@apache.org on 2026/05/25 00:15:37 UTC
(thrift) 01/01: No ticket: Drop uuid dependency in favor of native parse/stringify Client: nodejs
This is an automated email from the ASF dual-hosted git repository.
jimexist pushed a commit to branch claude/intelligent-varahamihira-7964e6
in repository https://gitbox.apache.org/repos/asf/thrift.git
commit 5acb41d4a8b049b881d7711cf1396ba98e3bce6f
Author: Jiayu Liu <ji...@gmail.com>
AuthorDate: Mon May 25 08:15:23 2026 +0800
No ticket: Drop uuid dependency in favor of native parse/stringify
Client: nodejs
The uuid npm package was used only for parse() and stringify() in the
binary and compact protocols. Replaced with a small in-tree helper so
the runtime no longer pulls in an external dependency for two trivial
hex conversions.
Co-Authored-By: Claude Opus 4.7 (1M context) <no...@anthropic.com>
---
lib/nodejs/lib/thrift/binary_protocol.js | 2 +-
lib/nodejs/lib/thrift/compact_protocol.js | 2 +-
lib/nodejs/lib/thrift/uuid.js | 69 +++++++++++++++++++++++++++++++
package-lock.json | 14 -------
package.json | 1 -
5 files changed, 71 insertions(+), 17 deletions(-)
diff --git a/lib/nodejs/lib/thrift/binary_protocol.js b/lib/nodejs/lib/thrift/binary_protocol.js
index b2c3720a6..e26b52b4d 100644
--- a/lib/nodejs/lib/thrift/binary_protocol.js
+++ b/lib/nodejs/lib/thrift/binary_protocol.js
@@ -23,7 +23,7 @@ var Int64 = require("node-int64");
var Thrift = require("./thrift");
var Type = Thrift.Type;
-const { parse: uuidParse, stringify: uuidStringify } = require("uuid");
+const { parse: uuidParse, stringify: uuidStringify } = require("./uuid");
module.exports = TBinaryProtocol;
diff --git a/lib/nodejs/lib/thrift/compact_protocol.js b/lib/nodejs/lib/thrift/compact_protocol.js
index 2f6fc71b4..c70b20839 100644
--- a/lib/nodejs/lib/thrift/compact_protocol.js
+++ b/lib/nodejs/lib/thrift/compact_protocol.js
@@ -22,7 +22,7 @@ var Int64 = require("node-int64");
var Thrift = require("./thrift");
var Type = Thrift.Type;
-const { parse: uuidParse, stringify: uuidStringify } = require("uuid");
+const { parse: uuidParse, stringify: uuidStringify } = require("./uuid");
module.exports = TCompactProtocol;
diff --git a/lib/nodejs/lib/thrift/uuid.js b/lib/nodejs/lib/thrift/uuid.js
new file mode 100644
index 000000000..83a77ee95
--- /dev/null
+++ b/lib/nodejs/lib/thrift/uuid.js
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+const UUID_RE =
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+
+exports.parse = function (uuid) {
+ if (typeof uuid !== "string") {
+ throw new TypeError("Invalid UUID");
+ }
+ if (!UUID_RE.test(uuid)) {
+ throw new TypeError("Invalid UUID");
+ }
+ const hex = uuid.replace(/-/g, "");
+ const bytes = new Uint8Array(16);
+ for (let i = 0; i < 16; i++) {
+ bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
+ }
+ return bytes;
+};
+
+const HEX = [];
+for (let i = 0; i < 256; i++) {
+ HEX.push((i + 0x100).toString(16).slice(1));
+}
+
+exports.stringify = function (bytes) {
+ if (!bytes || bytes.length < 16) {
+ throw new TypeError("Invalid UUID byte array");
+ }
+ return (
+ HEX[bytes[0]] +
+ HEX[bytes[1]] +
+ HEX[bytes[2]] +
+ HEX[bytes[3]] +
+ "-" +
+ HEX[bytes[4]] +
+ HEX[bytes[5]] +
+ "-" +
+ HEX[bytes[6]] +
+ HEX[bytes[7]] +
+ "-" +
+ HEX[bytes[8]] +
+ HEX[bytes[9]] +
+ "-" +
+ HEX[bytes[10]] +
+ HEX[bytes[11]] +
+ HEX[bytes[12]] +
+ HEX[bytes[13]] +
+ HEX[bytes[14]] +
+ HEX[bytes[15]]
+ );
+};
diff --git a/package-lock.json b/package-lock.json
index e8ce4f151..b8530cb39 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,7 +13,6 @@
"isomorphic-ws": "^4.0.1",
"node-int64": "^0.4.0",
"q": "^1.5.0",
- "uuid": "^14.0.0",
"ws": "^5.2.3"
},
"devDependencies": {
@@ -3070,19 +3069,6 @@
"node": ">= 0.4.0"
}
},
- "node_modules/uuid": {
- "version": "14.0.0",
- "resolved": "https://registry.npmjs.org/uuid/-/uuid-14.0.0.tgz",
- "integrity": "sha512-Qo+uWgilfSmAhXCMav1uYFynlQO7fMFiMVZsQqZRMIXp0O7rR7qjkj+cPvBHLgBqi960QCoo/PH2/6ZtVqKvrg==",
- "funding": [
- "https://github.com/sponsors/broofa",
- "https://github.com/sponsors/ctavan"
- ],
- "license": "MIT",
- "bin": {
- "uuid": "dist-node/bin/uuid"
- }
- },
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
diff --git a/package.json b/package.json
index febc130fe..d415ab14e 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,6 @@
"isomorphic-ws": "^4.0.1",
"node-int64": "^0.4.0",
"q": "^1.5.0",
- "uuid": "^14.0.0",
"ws": "^5.2.3"
},
"devDependencies": {