You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add `.apply` REPL dot-command (Approach 1: Minimalist Function Injection).
6
+
7
+
The `.apply` command lets you run scenario scripts from the REPL prompt without leaving the terminal. A scenario is a plain TypeScript (or JavaScript) file that exports named functions. Each function receives an `ApplyContext` object with `{ context, loadContext, routes, route }` and can freely read or mutate state.
Copy file name to clipboardExpand all lines: docs/usage.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -542,6 +542,50 @@ await req.send()
542
542
543
543
See the [Route Builder guide](./route-builder.md) for full documentation.
544
544
545
+
### Scenario scripts with `.apply`
546
+
547
+
For more complex setups you can automate REPL interactions by writing _scenario scripts_ — plain TypeScript files that export named functions. Run them with `.apply`:
548
+
549
+
```
550
+
⬣> .apply soldPets
551
+
```
552
+
553
+
**Path resolution:** the argument to `.apply` is a slash-separated path. The last segment is the function name; everything before it is the file path, resolved relative to `<basePath>/scenarios/` (with `index.ts` as the default file).
// Store a pre-configured route builder for later use in the REPL
574
+
$.routes.findSold=$
575
+
.route("/pet/findByStatus")
576
+
.method("get")
577
+
.query({ status: "sold" });
578
+
}
579
+
```
580
+
581
+
After the command runs you can immediately use anything stored in `$.routes`:
582
+
583
+
```js
584
+
⬣>routes.findSold.send()
585
+
```
586
+
587
+
The `Scenario` type and `ApplyContext` interface are generated automatically into `types/scenario-context.ts` when you run Counterfact with type generation enabled.
0 commit comments