v2.4.0
Minor Changes
-
cb931d6: When multiple wildcard route handlers exist at the same path level (e.g.
/{x}and/{y}as siblings), Counterfact now:- Logs an error to stderr at load time listing the conflicting wildcard names.
- Returns an HTTP 500 response when a request could be routed to two or more handlers due to the ambiguity.
-
0a3039b: Add support for binary data in responses. Route handlers can now return binary content using the new
binary()method on the response builder, which accepts aBufferor a base64-encoded string. OpenAPI schemas withformat: "binary"(v3) ortype: "file"(v2) now generateBuffer | stringTypeScript types. -
d53f4c3: Break REPL out of
counterfact()and expose it as a callablestartRepl()on the returned object. This enables programmatic usage (e.g. from Playwright tests) without automatically starting an interactive terminal session.import { counterfact } from "counterfact"; const { contextRegistry, start, startRepl } = await counterfact(config); await start(config); // Manipulate server state directly from test code: const rootContext = contextRegistry.find("/"); rootContext.passwordResponse = "expired";
The CLI (
bin/counterfact.js) now explicitly callsstartRepl()when--replis passed, preserving existing behaviour. -
861c4db: Add route autocomplete to REPL for
client.<method>("...")patterns.When typing
client.get("/pin the REPL and pressing Tab, the REPL now suggests available routes (e.g./pets,/pets/{petId}) derived from the route registry.This works for all HTTP methods:
get,post,put,patch, anddelete. -
1e4d5cf: Add chainable
$.response.cookie()helper for setting response cookies.Route handlers can now set one or more cookies without manually building
Set-Cookieheader strings:return $.response[200] .cookie("sessionId", "abc123", { httpOnly: true, secure: true, sameSite: "lax", path: "/", maxAge: 3600, }) .cookie("theme", "dark") .json({ ok: true });
Supported options:
path,domain,maxAge,expires,httpOnly,secure,sameSite.
Patch Changes
-
578faab: Fix REPL tab completion for built-in Node.js completions (e.g.
context.<Tab>).The custom route completer previously replaced Node's built-in REPL completer entirely, breaking property completion for objects like
contextandclient. The completer now delegates to the built-in completer when the input doesn't match theclient.<method>("...")pattern. -
76d3103: Updated dependency
json-schema-fakerto0.6.0. -
4229034: Updated dependency
eslintto10.0.3. -
635071c: Updated dependency
eslint-plugin-jestto29.15.1. -
ff36c53: Updated dependency
handlebarsto4.7.9. -
9e2b147: Updated dependency
typescriptto6.0.2. -
7f9ce73: Updated dependency
@swc/coreto1.15.21. -
a7a56a2: Updated dependency
eslintto10.1.0.