Skip to content

Context decorator #567

@slinkydeveloper

Description

@slinkydeveloper

It is a common practice in Typescript to carry around a "context" object containing all the code dependencies. Because we have already our own context, people doing that will need to wrap our context in their context.

It would be nice to support this use case better, autowrapping somewhat like this:

const obj = object({ 
  name: "MyObj",
 
  makeContext: (restateCtx) => MyCtx { restateCtx },

  handlers: {
    myObjHandler: async (ctx: MyCtx<ObjectContext>): Promise<string> => {
      // handler code
    },
    myObjHandler: restate.handlers.shared(async (ctx: MyCtx<ObjectSharedContext>): Promise<string> => {
      // handler code
    })
  },
})

Some notes:

  • I guess the constraint will be anyway that the custom user context type needs to have a generic that supports restate context?
  • How to get the typing right -> if the user provides this makeContext, the handlers type need to infer the wrapped type?
  • How we deal with the different context types (shared/exclusive in object for example)
  • How we do this without breaking the client type magic stuff.

cc @nikrooz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions