@counterfact/repl
v0.1.1
Published
Inspect and manipulate a running Counterfact simulator from a Node.js REPL.
Downloads
385
Maintainers
Readme
@counterfact/repl
Counterfact's interactive Node.js REPL integration. It accepts narrow runtime registries and a client route catalog, so applications can embed the terminal experience without importing Counterfact's CLI or telemetry policy.
Starting a REPL
import { createOpenApiRouteCatalog } from "@counterfact/client";
import {
ContextRegistry,
Registry,
ScenarioRegistry,
} from "@counterfact/runtime";
import { startRepl } from "@counterfact/repl";
const contextRegistry = new ContextRegistry();
const registry = new Registry();
const scenarioRegistry = new ScenarioRegistry();
const config = { port: 3000, proxyPaths: new Map(), proxyUrl: "" };
const routeCatalog = createOpenApiRouteCatalog({ paths: {} });
const replServer = startRepl(
contextRegistry,
registry,
config,
undefined,
routeCatalog,
scenarioRegistry,
undefined,
undefined,
(event) => console.log(event),
);The optional event reporter receives command names but never command arguments. Reporter failures are ignored so observability cannot interrupt an interactive session.
REPL globals
The REPL starts with these live values:
contextandloadContext(path)expose runtime state.clientis an@counterfact/clientRawHttpClientconfigured for the simulator.route(path)creates an immutable request builder.routesis shared with scenario functions.storeis present when the simulator has a shared store.
For multiple APIs, context, loadContext, route, and routes are grouped
by API name. The .proxy command changes live proxy configuration and
.scenario applies named scenario functions.
See examples/complete-routes.mjs for a
complete public-import example.
