restatedev / restatedev/sdk-typescript
Allow updating the entire key value store at once
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 122
- Forks
- 27
- Avg merge
- 9h 17m
- Merged PRs (30d)
- 8
Description
There is an issue I run into with having a typed context.
Say I have a type like:
interface Lead {
Status: "NONEXISTANT";
} |
{
Status: "ACTIVE",
Details: {
SomeField: number,
SomeOtherField: string
};
}
And my context looks like:
ctx: restate.ObjectContext<Lead>
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:
ctx.set("Status", "ACTIVE"); // Context is now in non-typesafe state because Details doesn't exist
ctx.set("Details", ...) // Get a type error because Details field isn't present when Status is "NONEXISTANT"
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.
await ctx.update((oldState) => {
return {
Status: "ACTIVE",
Details: {
SomeField: 1,
SomeOtherField: "hello"
}
}
} // All fields are updated atomically and type safety is preserved
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript ObjectContext API and the existing ctx.set operation; no file or test is named in the issue. Define the requested whole-state update behavior, including the callback's typed oldState and atomic replacement, then add coverage showing that discriminated-union state transitions remain type-safe.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100