-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,53 @@ | ||
# add | ||
|
||
:::warning | ||
Work in progress | ||
::: | ||
Adds a new route to a router module. | ||
|
||
## Usage | ||
|
||
```ts twoslash | ||
/// <reference types="node" /> | ||
// ---cut--- | ||
import { createApp } from "@deroll/app"; | ||
import { createRouter } from "@deroll/router"; | ||
|
||
// create app | ||
const app = createApp({ url: "http://127.0.0.1:5004" }); | ||
|
||
// create router | ||
const router = createRouter({ app }); | ||
router.add<{ name: string }>( // [!code focus] | ||
"hello/:name", // [!code focus] | ||
({ params: { name } }) => `Hello ${name}`, // [!code focus] | ||
); // [!code focus] | ||
|
||
app.addInspectHandler(router.handler); | ||
|
||
// start app | ||
app.start().catch((e) => process.exit(1)); | ||
``` | ||
|
||
## Returns | ||
|
||
Type: `Route<P>` | ||
|
||
```ts | ||
type Route<P extends object> = { | ||
matcher: MatchFunction<P>; | ||
handler: Handler<P>; | ||
}; | ||
``` | ||
|
||
## Parameters | ||
|
||
Type: `string` | ||
|
||
URL of route. | ||
|
||
Type: `Handler` | ||
|
||
```ts | ||
type Handler<P extends object = object> = ( | ||
match: MatchResult<P>, | ||
matchedRoute: Route<P>, | ||
) => string; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
# createRouter | ||
|
||
:::warning | ||
Work in progress | ||
::: | ||
Create a new router module. | ||
|
||
## Usage | ||
|
||
```ts twoslash | ||
/// <reference types="node" /> | ||
// ---cut--- | ||
import { createApp } from "@deroll/app"; | ||
import { createRouter } from "@deroll/router"; | ||
|
||
// create app | ||
const app = createApp({ url: "http://127.0.0.1:5004" }); | ||
|
||
// create router | ||
const router = createRouter({ app }); // [!code focus] | ||
router.add<{ name: string }>( | ||
"hello/:name", | ||
({ params: { name } }) => `Hello ${name}`, | ||
); | ||
|
||
app.addInspectHandler(router.handler); | ||
|
||
// start app | ||
app.start().catch((e) => process.exit(1)); | ||
``` | ||
|
||
## Returns | ||
|
||
Type: `Router` | ||
|
||
## Parameters | ||
|
||
Type: `App` | ||
|
||
Application instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
# Router | ||
|
||
:::warning | ||
Work in progress | ||
::: | ||
The `@deroll/router` modules provides a simple routing mechanism that can be used by [inspect handlers](../inspect-handlers) to route requests to different handlers based on a URL mechanism. | ||
|
||
```ts twoslash | ||
/// <reference types="node" /> | ||
// ---cut--- | ||
import { createApp } from "@deroll/app"; | ||
import { createRouter } from "@deroll/router"; | ||
|
||
// create app | ||
const app = createApp({ url: "http://127.0.0.1:5004" }); | ||
|
||
// create router | ||
const router = createRouter({ app }); | ||
router.add<{ name: string }>( | ||
"hello/:name", | ||
({ params: { name } }) => `Hello ${name}`, | ||
); | ||
|
||
app.addInspectHandler(router.handler); | ||
|
||
// start app | ||
app.start().catch((e) => process.exit(1)); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# Wallet | ||
|
||
:::warning | ||
Work in progress | ||
::: | ||
The `@deroll/wallet` module provides an in-memory wallet management system, and some utility functions to deal with assets. |