Open PfisterFactor opened 3 months ago
Could you not achieve the same thing with the following:
interface State {
Lead: {
Status: "NONEXISTANT"
} |
{
Status: "ACTIVE"
Details: {
SomeField: number
SomeOtherField: string
}
}
}
const handler = async (ctx: restate.ObjectContext<State>) => {
const oldState = await ctx.get("Lead") // typed: Lead | null
ctx.set("Lead", {
Status: "ACTIVE",
Details: {
SomeField: 1,
SomeOtherField: "hello",
},
})
}
Sure - but now we have to nest it arbitrarily. Plus the issue remains that you can't atomically update one or more fields within the context store at the first level
There is an issue I run into with having a typed context.
Say I have a type like:
And my context looks like:
Currently there is no typesafe way for me to update the key value store. This is annoying when trying to implement a state-machine pattern for the key value store.
Example:
If we were to introduce some method to update the entire key/value state at once, we can resolve this. It would be akin to a
map
operation.