-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
manipulating existing codecs / versioning #134
Comments
I don't think "migrations" are a problem we should solve in scale. Scale should be a minimal language for defining codecs, and these kinds of migrations add a lot of conceptual complexity and do not scale very well. Changes like the " If one really wants to have multiple versioned codecs, most of the time, the changes will be additive. In this case, you can simply write const $superheroV1 = $.object(
$.field("pseudonym", $.str),
$.optionalField("secretIdentity", $.str),
$.field("superpowers", $.array($.str)),
)
const $superheroV2 = $.object(
$superheroV1,
$.field("defeated", $.array($supervillain)),
)
The only way this would work is if the storage was a versioned union in the first place, i.e. // v1
const $superhero = $.taggedUnion("version", [
$.variant("1", $superheroV1),
])
// v2
const $superhero = $.taggedUnion("version", [
$.variant("1", $superheroV1),
$.variant("2", $superheroV2),
]) At this point, though, there are other, likely simpler, solutions. For example, if we went back to allowing const $extensible = $.option($.never);
// v1
const $superhero = $.object(
$.field("pseudonym", $.str),
$.optionalField("secretIdentity", $.str),
$.field("superpowers", $.array($.str)),
$extensible,
)
// v2
const $superhero = $.object(
$.field("pseudonym", $.str),
$.optionalField("secretIdentity", $.str),
$.field("superpowers", $.array($.str)),
$.option($.object(
$.field("defeated", $.array($supervillain)),
$extensible,
)),
) |
This is a very good point.
How would you feel about a utility that does this compatibility check for the sake of versionless API development?
Is this something you've been considering? |
Feature idea: utils for manipulating existing codecs for the sake of versioning.
Let's say we're using the following codec to model an event.
v1.ts
In v2, perhaps we'd like to remove the
superpowers
field. However, our users may still want to interact with previous events, hence we must keep the original codec around. Yes, we could define the new version as an entirely new codec.v2.ts
export const $superhero = $.object( $.field("pseudonym", $.str), $.optionalField("secretIdentity", $.str), - $.field("superpowers", $.array($.str)), )
However, we'll encounter quite a bit of duplication, especially if bumping is frequent. Perhaps there's a simpler path?
v2.ts
This would be especially useful in cases where the means and validity of change is dubious.
In most cases, we'd be unable to determine whether the rename was actually a field deletion followed by a field addition. If modeled with a migration codec factory + instructions, we could know how to transform previous versions.
Some potential use cases:
The text was updated successfully, but these errors were encountered: