morpheus4j
Version:
Morpheus is a migration tool for Neo4j. It aims to be a simple and intuitive way to migrate your database.
47 lines • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertAtToDate = exports.convertInToTime = exports.generateChecksum = void 0;
const crc_1 = require("crc");
/**
* Generates a CRC32 checksum from an array of string statements.
*
* The behavior of this function is controlled by the environment variable
* 'MORPHEUS_USE_ORIGINAL_CHECKSUM_IMPLEMENTATION'. When set to 'true', it uses
* the original implementation with undefined as the initial value.
*
* @param {string[]} statements - An array of strings to calculate the checksum from
* @returns {string} The calculated CRC32 checksum as a string
*
* @example
* // Set environment variable for original implementation (recommended)
* // process.env.MORPHEUS_USE_ORIGINAL_CHECKSUM_IMPLEMENTATION = 'true'
* const checksum = generateChecksum(statements);
*
* @deprecated The default behavior (with initial value of 0) is deprecated and will be removed
* in a future version. Please set MORPHEUS_USE_ORIGINAL_CHECKSUM_IMPLEMENTATION='true' in your
* environment for consistent behavior with previous versions.
*/
const generateChecksum = (statements) => {
// Check environment variable for original implementation flag
const useOriginalImplementation = process.env.MORPHEUS_USE_ORIGINAL_CHECKSUM_IMPLEMENTATION === 'true';
// Use undefined as initial value if original implementation is requested
let crcValue = useOriginalImplementation ? undefined : 0;
for (const statement of statements) {
crcValue = (0, crc_1.crc32)(statement, crcValue);
}
return crcValue.toString();
};
exports.generateChecksum = generateChecksum;
const convertInToTime = (inDate) => {
const seconds = inDate.seconds.low + inDate.seconds.high * 2 ** 32;
const nanoseconds = inDate.nanoseconds.low + inDate.nanoseconds.high * 2 ** 32;
const totalSeconds = seconds + nanoseconds / 1_000_000_000;
return `${totalSeconds}s`;
};
exports.convertInToTime = convertInToTime;
const convertAtToDate = (at) => {
const date = at.toStandardDate();
return date;
};
exports.convertAtToDate = convertAtToDate;
//# sourceMappingURL=utils.js.map