Open Kmaschta opened 7 years ago
For now, we use object-hash to get a hash of configuration version. We want to remove this dependency and write our own hashing function.
object-hash
Here is an example of the new API:
const currentVersion = { hash: '000000000000000000000000', // Already computed unique hash entries: { A: 'value A', }, }; const newVersion = { // ... entries: { A: 'value A', B: 'value B', }, }; const hash = getHash(newVersion.entries, currentVersion.hash); // Should be a unique hash // or, if there is no precedent version (for example for the first version) const hash = getHash(newVersion.entries);
The idea is to concatenate the following values:
[PRECEDENT VERSION HASH] + [ENTRY KEY 0] + [ENTRY VALUE 0] + [ENTRY KEY 1] ... eg: 000000000000000000000000 A value A B value B
or, for no precedent version
[ENTRY KEY 0] + [ENTRY VALUE 0] + [ENTRY KEY 1] + [ENTRY VALUE 1] ...
Then, get a unique hash of this character chain. You can use the native Node.JS crypto module to find the better way to do this.
getHash({ a: 1 }) !== getHash({ b: 2 })
getHash({ a: 1 }) !== getHash({ a: 1 })
It is highly recommended to write the tests first and then code the function. Feel free to ask your questions here!
Changing the way we compute hashes would be a breaking change now
Rationale
For now, we use
object-hash
to get a hash of configuration version. We want to remove this dependency and write our own hashing function.Details
Here is an example of the new API:
The idea is to concatenate the following values:
or, for no precedent version
Then, get a unique hash of this character chain. You can use the native Node.JS crypto module to find the better way to do this.
Requirements
getHash({ a: 1 }) !== getHash({ b: 2 })
getHash({ a: 1 }) !== getHash({ a: 1 })
It is highly recommended to write the tests first and then code the function. Feel free to ask your questions here!