Skip to content

feat(NODE-7385): add experimental os runtime adapter #4851

Merged
PavelSafronov merged 7 commits intomainfrom
NODE-7385
Feb 4, 2026
Merged

feat(NODE-7385): add experimental os runtime adapter #4851
PavelSafronov merged 7 commits intomainfrom
NODE-7385

Conversation

@baileympearson
Copy link
Contributor

@baileympearson baileympearson commented Jan 28, 2026

Description

Summary of Changes

This PR adds support for an experimental runtimeAdapters.

Notes for Reviewers

What is the motivation for this change?

Release Highlight

Experimental Support for Dependency Injection of Nodejs Runtime Dependencies

This release introduces a new MongoClient option, runtimeAdapters. runtimeAdapters allows injection of core Nodejs APIs, to allow users of the driver to use alternative runtimes that don't support Nodejs compatibility or work in restricted environments.

runtimeAdapters is experimental and the actual interface of each dependency might change at any time.

Notes about usage of runtimeAdapters:

  1. If no runtimeAdapter is provided for a core Nodejs module that the driver uses, the driver will import the corresponding module from Nodejs.
  2. Adapters are per-client.
  3. Each adapter specifies the required APIs as a part of its Typescript API definition. There are no runtime checks to ensure all required functions are provided; the onus is on users to ensure that all required module dependencies are provided.
  4. The runtimeAdapters Typescript types currently rely Nodejs' type definitions (@types/node). To use runtimeAdapters in a Typescript project, @types/node must be installed as well.
  5. When providing a module in runtimeAdapters, all required functions inside that mo
    dule must be provided. For example, when injecting the os module, the platform() function cannot be omitted.

runtimeAdapters supports injecting Nodejs' os module

The os module is pluggable using runtimeAdapters:

const os: OsAdapter = {
  // implement the required OSAdapter interface
}

// `client` will never import or make use of the `os` module and instead only rely on the `os` adapter specified above.
const client = new MongoClient(<uri>, {
  runtimeAdapters: { os }
});

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@baileympearson baileympearson marked this pull request as ready for review February 2, 2026 20:30
@baileympearson baileympearson requested a review from a team as a code owner February 2, 2026 20:30
@PavelSafronov PavelSafronov self-assigned this Feb 3, 2026
@PavelSafronov PavelSafronov added the Team Review Needs review from team label Feb 3, 2026
Copy link
Member

@tadjik1 tadjik1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thank you for laying the foundation @baileympearson!

@PavelSafronov PavelSafronov merged commit d2ad07f into main Feb 4, 2026
29 of 31 checks passed
@PavelSafronov PavelSafronov deleted the NODE-7385 branch February 4, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team Review Needs review from team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants