Skip to content

Support for extending or customising the runtime? #40

Closed

Description

@tom-sherman

Is this planned/possible to support?

Some use cases I'm thinking of:

  • Changing the exports/event handler semantics
  • Adding new global JS APIs
  • Adding JS APIs that can use new types of bindings/services

Activity

  1. jasnell commented on Sep 28, 2022

    @jasnell
    Collaborator

    Much of that will fall under the category of new feature development and we will be handling that very carefully. The best approach is to open a discussion or issue early to propose and discuss possible features before writing any code.

  2. tom-sherman commented on Sep 28, 2022

    @tom-sherman
    Author

    @jasnell Ah, I was more thinking like workerd having some sort of plugin interface to allow for adding stuff to the runtime. Does this align with the goals of the project? If not I'm happy to extend/customise via a fork before suggesting changes up stream, but I can imagine much of the extensions wouldn't really be relevant to include in workerd mainline as they'd be things like "a KV-like API backed by DynamoDB" (for example).

  3. penalosa commented on Sep 28, 2022

    @penalosa
    Contributor

    For things like a KV API with a different backing, that's supported out of the box! workerd supports pluggable KV, R2 etc... interfaces, and you should be able to implement the KV API backed by DynamoDB (see miniflare for an example of how this is done with KV persisted to disk)

  4. kentonv commented on Sep 28, 2022

    @kentonv
    Member

    Hi Tom,

    The code today is structured internally so that it's possible to add custom APIs and event handlers. Specifically, the full set of available APIs is controlled by the class WorkerdApiIsolate in src/workerd/server/workerd-api.{h,c++}. Essentially, if you fork the server directory, you can add new APIs here without having to fork the rest of the codebase.

    HOWEVER, we do not currently make any promises about stability of internal APIs. E.g. WorkerdApiIsolate implements the Worker::ApiIsolate interface. This interface could change at any time. You will have to be ready to update your code as needed, or be willing to pin to a particular version of workerd.

    We might add a more flexible mechanism for custom APIs in the future, perhaps especially to support Workers for Platforms use cases, but this is something we need to design carefully in coordination with our product management team.

    (I'm converting this issue to a discussion since I don't think there's an action item for us, but happy to answer questions about this.)

  5. locked and limited conversation to collaborators on Sep 28, 2022
  6. converted this issue into a discussion #50 on Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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