Skip to content

v2.4.0

Choose a tag to compare

@pmcelhaney pmcelhaney released this 30 Mar 22:55
· 2151 commits to main since this release
7951e71

Minor Changes

  • cb931d6: When multiple wildcard route handlers exist at the same path level (e.g. /{x} and /{y} as siblings), Counterfact now:

    1. Logs an error to stderr at load time listing the conflicting wildcard names.
    2. 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 a Buffer or a base64-encoded string. OpenAPI schemas with format: "binary" (v3) or type: "file" (v2) now generate Buffer | string TypeScript types.

  • d53f4c3: Break REPL out of counterfact() and expose it as a callable startRepl() 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 calls startRepl() when --repl is passed, preserving existing behaviour.

  • 861c4db: Add route autocomplete to REPL for client.<method>("...") patterns.

    When typing client.get("/p in 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, and delete.

  • 1e4d5cf: Add chainable $.response.cookie() helper for setting response cookies.

    Route handlers can now set one or more cookies without manually building Set-Cookie header 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 context and client. The completer now delegates to the built-in completer when the input doesn't match the client.<method>("...") pattern.

  • 76d3103: Updated dependency json-schema-faker to 0.6.0.

  • 4229034: Updated dependency eslint to 10.0.3.

  • 635071c: Updated dependency eslint-plugin-jest to 29.15.1.

  • ff36c53: Updated dependency handlebars to 4.7.9.

  • 9e2b147: Updated dependency typescript to 6.0.2.

  • 7f9ce73: Updated dependency @swc/core to 1.15.21.

  • a7a56a2: Updated dependency eslint to 10.1.0.