A schema version field should be stored for every encrypted entity.
This helps in two ways
Prevents needing to double read the json blob
Allows us to deprecate old versions gradually, we don't want to support all permutations in the FE code forever
Currently if we want to read the schema version of an entity we'll need to parse the json dump and read the version field. After which we'll need to parse it convert the json data into an actual object on the FE. You can imagine something like this
function getReader(str: string): V1Reader | V2Reader {
const data = JSON.parse(str);
switch (data.version) {
case 1: return new V1Reader();
case 2: return new V2Reader();
default: throw new Error();
}
}
const reader = getReader(dump);
// reader will need to parse the json dump again!
const etch = reader.read(dump);
We can add a method that returns the parsed data and the version specific reader to save parsing twice but that's not nice. We should store the schema version outside the payload so that we know how to read it without first having to decrypt it.
I was initially thinking that it may be some kind of security concern if the backend about "old" messages. But schemas are not related to encryption. Additionally the BE has timestamps when etches are created so we're not really hiding anything.
Storing schema on the backend allows us to gradually deprecate older unused versions. We won't have to keep code to use older unused versions.
A schema version field should be stored for every encrypted entity.
This helps in two ways
Currently if we want to read the schema version of an entity we'll need to parse the json dump and read the version field. After which we'll need to parse it convert the json data into an actual object on the FE. You can imagine something like this
We can add a method that returns the parsed data and the version specific reader to save parsing twice but that's not nice. We should store the schema version outside the payload so that we know how to read it without first having to decrypt it.
I was initially thinking that it may be some kind of security concern if the backend about "old" messages. But schemas are not related to encryption. Additionally the BE has timestamps when etches are created so we're not really hiding anything.
Storing schema on the backend allows us to gradually deprecate older unused versions. We won't have to keep code to use older unused versions.