Template
1
0

feat: update docs

This commit is contained in:
2025-04-25 18:58:22 +00:00
parent c42a090666
commit 9ff4d2c5fc
4 changed files with 78 additions and 31 deletions

View File

@@ -192,7 +192,39 @@ export class Route<const TState extends State = State> {
/**
* Server handler callback method.
*
* Handler receives the params, query, body, actions in order of definition.
* So if your route has params, and body the route handle method will
* receive (params, body) as arguments.
*
* @param handle - Handle function to trigger when the route is executed.
*
* @examples
*
* ```ts
* relay
* .post("/foo/:bar")
* .params({ bar: z.string() })
* .body(z.tuple([z.string(), z.number()]))
* .handle(async ({ bar }, [ "string", number ]) => {});
* ```
*
* ```ts
* const prefix = actions
* .make("prefix")
* .input(z.string())
* .output({ prefixed: z.string() })
* .handle(async (value) => ({
* prefixed: `prefix_${value}`;
* }))
*
* relay
* .post("/foo")
* .body(z.object({ bar: z.string() }))
* .actions([prefix, (body) => body.bar])
* .handle(async ({ bar }, { prefixed }) => {
* console.log(prefixed); => prefixed_${bar}
* });
* ```
*/
handle<THandleFn extends HandleFn<this["args"], this["state"]["output"]>>(handle: THandleFn): Route<Omit<TState, "handle"> & { handle: THandleFn }> {
return new Route({ ...this.state, handle });