UNPKG

ravendb

Version:
60 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HashCalculator = void 0; const TypeUtil_js_1 = require("../../Utility/TypeUtil.js"); const node_crypto_1 = require("node:crypto"); const node_buffer_1 = require("node:buffer"); const typeSignatures = { bigint: node_buffer_1.Buffer.from([1]), boolean: node_buffer_1.Buffer.from([2]), function: node_buffer_1.Buffer.from([3]), number: node_buffer_1.Buffer.from([4]), object: node_buffer_1.Buffer.from([5]), string: node_buffer_1.Buffer.from([6]), symbol: node_buffer_1.Buffer.from([7]), undefined: node_buffer_1.Buffer.from([8]), }; class HashCalculator { _buffers = []; getHash() { const buffer = node_buffer_1.Buffer.concat(this._buffers); return (0, node_crypto_1.createHash)("md5").update(buffer).digest("hex"); } //TBD 4.1 public void Write(HighlightedField[] highlightedFields) write(o, mapper) { if (TypeUtil_js_1.TypeUtil.isNullOrUndefined(o)) { this._buffers.push(node_buffer_1.Buffer.from("null")); return; } // Push a byte that identifies the type, to differentiate strings, numbers, and bools this._buffers.push(typeSignatures[typeof o] || typeSignatures.undefined); if (typeof o === "number") { this._buffers.push(node_buffer_1.Buffer.from(String(o))); } else if (typeof o === "string") { this._buffers.push(node_buffer_1.Buffer.from(o)); } else if (typeof o === "boolean") { this._buffers.push(node_buffer_1.Buffer.from(o ? [1] : [2])); } else if (Array.isArray(o)) { for (const item of o) { this.write(item, mapper); } this.write(o.length); } else if (typeof o === "object") { for (const key of Object.keys(o)) { this.write("key"); this.write(key, mapper); this.write("value"); this.write(o[key], mapper); } } else { this.write(mapper.toObjectLiteral(o), mapper); } } } exports.HashCalculator = HashCalculator; //# sourceMappingURL=HashCalculator.js.map