add admin tool to purge all records for a provided node id

This commit is contained in:
liamcottle
2025-01-12 23:32:53 +13:00
parent 3bcdb2628a
commit 43cf12015d
3 changed files with 159 additions and 0 deletions

23
src/utils/node_id_util.js Normal file
View File

@ -0,0 +1,23 @@
class NodeIdUtil {
/**
* Converts the provided hex id to a numeric id, for example: !FFFFFFFF to 4294967295
* Anything else will be converted as is to a BigInt, for example "4294967295" to 4294967295
* @param hexIdOrNumber a node id in hex format with a prepended "!", or a numeric node id as a string or number
* @returns {bigint} the node id in numeric form
*/
static convertToNumeric(hexIdOrNumber) {
// check if this is a hex id, and convert to numeric
if(hexIdOrNumber.toString().startsWith("!")){
return BigInt('0x' + hexIdOrNumber.replaceAll("!", ""));
}
// convert string or number to numeric
return BigInt(hexIdOrNumber);
}
}
module.exports = NodeIdUtil;

View File

@ -0,0 +1,9 @@
const NodeIdUtil = require("./node_id_util");
test('can convert hex id to numeric id', () => {
expect(NodeIdUtil.convertToNumeric("!FFFFFFFF")).toBe(BigInt(4294967295));
});
test('can convert numeric id to numeric id', () => {
expect(NodeIdUtil.convertToNumeric(4294967295)).toBe(BigInt(4294967295));
});