npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@documentdb-js/shell-runtime

v0.8.1

Published

Sandboxed JavaScript evaluation engine for DocumentDB — shell command handling, result transformation, and help generation

Readme

@documentdb-js/shell-runtime

DocumentDB is an open-source document database built on PostgreSQL, with native BSON support, rich indexing, and vector search. It uses the MongoDB-compatible wire protocol, runs locally with Docker, and is MIT licensed.

This package is a sandboxed JavaScript evaluation engine for DocumentDB — provides shell command handling, result transformation, and help generation. Supports both single-shot evaluation (playground/scratchpad style) and persistent REPL sessions (interactive shell style).

Pre-1.0 notice — The API may change between minor versions until 1.0.0 is released. If you depend on this package and need stability guarantees sooner, please open an issue and let us know.

Features

  • JavaScript evaluation — executes user code in a sandboxed vm.Context against a target database
  • Command interception — routes shell commands (help, exit, cls) before evaluation
  • Result transformation — normalizes evaluation results into a protocol-agnostic ShellEvaluationResult
  • Help text — generates DocumentDB-specific help output
  • Service provider — bridges the evaluation engine to the MongoDB Node.js driver

Installation

npm install @documentdb-js/shell-runtime

Requires mongodb ≥ 6.0.0 as a peer dependency.

Eval Modes

The runtime supports two modes via the persistent option:

| Mode | persistent | Behavior | | ------------------ | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Fresh context | false (default) | New ShellInstanceState + vm.Context per evaluate() call. No variable leakage between runs. | | Persistent context | true | Reuses the same ShellInstanceState, ShellEvaluator, and vm.Context across calls. Variables, cursor state (it), and the db reference persist between evaluations. |

Usage

import { MongoClient } from 'mongodb';
import { DocumentDBShellRuntime } from '@documentdb-js/shell-runtime';

// The caller owns the MongoClient — create, connect, and close it yourself.
// The runtime never opens or closes the connection.
const mongoClient = new MongoClient(connectionString);
await mongoClient.connect();

// Constructor signature:
//   new DocumentDBShellRuntime(mongoClient, callbacks?, options?)
//
//   callbacks: { onConsoleOutput?, onLog? }
//   options:   { persistent?, productName?, displayBatchSize? }

// Fresh context (playground mode — default)
const playground = new DocumentDBShellRuntime(mongoClient, {
  onConsoleOutput: (output) => console.log(output),
});
const result = await playground.evaluate('db.users.find({})', 'myDatabase');

// Persistent context (interactive shell mode)
const shell = new DocumentDBShellRuntime(
  mongoClient,
  { onConsoleOutput: (output) => console.log(output) }, // callbacks
  { persistent: true }, // options
);
await shell.evaluate('const x = 1', 'myDatabase');
await shell.evaluate('x + 1', 'myDatabase'); // returns 2 — variable survived

// Dispose the runtime when done — this does NOT close the MongoClient.
shell.dispose();

// Close the MongoClient when the session is over.
// The runtime intentionally never closes it, so the same client
// can be reused across multiple evaluate() calls and runtime instances.
await mongoClient.close();

Components

| File | Role | | --------------------------- | ----------------------------------------------------------------------------- | | DocumentDBShellRuntime | Main entry point — evaluate(code, databaseName, options) | | CommandInterceptor | Pre-eval command routing (regex-based detection) | | ResultTransformer | Post-eval result normalization (cursor iteration, cursorHasMore extraction) | | DocumentDBServiceProvider | Evaluation engine ↔ MongoDB driver bridge (leverages @mongosh internals) | | HelpProvider | Help text generation | | types.ts | Public API types (ShellEvaluationResult, ShellRuntimeOptions, etc.) |

Origin

This package was developed while building features for the DocumentDB VS Code extension, which remains the primary consumer. The runtime is designed to work with any Node.js application that has a MongoClient and needs to evaluate shell-style JavaScript against a DocumentDB database.

License

MIT