Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/api/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ new Elysia({
```

## Listen
`.listen` will config any value for starting server.
`.listen` will configure any value for starting the server.

By default `listen` will either accept `number` or `Object`.

For Object, `listen` accept the same value as `Bun.serve`, you can provide any custom one except `serve`.
For Object, `listen` accepts the same value as `Bun.serve`, you can provide any custom one except `serve`.

```typescript
// ✅ This is fine
Expand Down
4 changes: 2 additions & 2 deletions docs/at-glance.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ new Elysia()
.listen(3000)
```

Navigate to [localhost:3000](http://localhost:3000/) should show 'Hello Elysia' as a result.
Navigate to [localhost:3000](http://localhost:3000/) and it should show 'Hello Elysia' as a result.

## Performance
Building on Bun and extensive optimization like Static Code Analysis allows Elysia to generate optimized code on the fly.
Expand Down Expand Up @@ -62,7 +62,7 @@ new Elysia()

The above code allows you to create a path parameter with the name of id, the value that passes after `/id/` will be reflected in `params.id`.

In most framework, you need to provide a generic type to the **id** parameter while Elysia understand that `params.id` will always be available and type as **string**. Elysia then infers this type without any manual type reference need.
In most framework, you need to provide a generic type to the **id** parameter while Elysia understand that `params.id` will always be available and type as **string**. Elysia then infers this type without any manual type reference needed.

Elysia's goal is to help you write less TypeScript and focus more on Business logic. Let the complex type be handled by the framework.

Expand Down
4 changes: 2 additions & 2 deletions docs/concept/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ head:

- - meta
- name: 'description'
content: Schema is a strictly typed definitions, use to infer TypeScript's type and data validation of an incoming request and outgoing response. Elysia's schema validation are based on Sinclair's TypeBox, a TypeScript library for data validation.
content: Schema are strictly typed definitions, used to infer TypeScript's type and data validation of an incoming request and outgoing response. Elysia's schema validation are based on Sinclair's TypeBox, a TypeScript library for data validation.

- - meta
- property: 'og:description'
content: Schema is a strictly typed definitions, use to infer TypeScript's type and data validation of an incoming request and outgoing response. Elysia's schema validation are based on Sinclair's TypeBox, a TypeScript library for data validation.
content: Schema are strictly typed definitions, used to infer TypeScript's type and data validation of an incoming request and outgoing response. Elysia's schema validation are based on Sinclair's TypeBox, a TypeScript library for data validation.
---

# Schema
Expand Down
10 changes: 5 additions & 5 deletions docs/concept/state-decorate.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ head:

- - meta
- name: 'description'
content: You can extend Elysia to fits your need with ".state" and ".decorate" to add custom value to the "Context", and handler, for example. Database connection, utility function, or cookie.
content: You can extend Elysia to fit your needs with ".state" and ".decorate" to add custom value to the "Context", and handler, for example. Database connection, utility function, or cookie.

- - meta
- property: 'og:description'
content: You can extend Elysia to fits your need with ".state" and ".decorate" to add custom value to the "Context", and handler, for example. Database connection, utility function, or cookie.
content: You can extend Elysia to fit your needs with ".state" and ".decorate" to add custom value to the "Context", and handler, for example. Database connection, utility function, or cookie.
---

# State and Decorate
You can extend Elysia to fit your need. This is useful when you need to access extra values in a handler (e.g. a database connection).
You can extend Elysia to fit your needs. This is useful when you need to access extra values in a handler (e.g. a database connection).

In summary:
- `state`: assign value to `Context.store` (a global state object of the Elysia instance)
- `decorate`: assign value to `Context`

::: tip
`Context` is a parameter in the callback of handler.
`Context` is a parameter in the callback of the handler.
:::

### Example
Expand All @@ -41,7 +41,7 @@ app
- `getDate` is registered using `decorate`, and accessible via `Context.getDate`.

## Remap
By providing a function as a first parameters, the callback will accept current value, allowing us to remap the value to anything we like.
By providing a function as the first parameter, the callback will accept the current value, allowing us to remap the value to anything we like.

```typescript
app
Expand Down
6 changes: 3 additions & 3 deletions docs/eden/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ const { id, name } = nendoroid
## When should I use Eden Fetch over Eden Treaty
Using Eden Treaty requires a lot of down-level iteration to map all possible types in a single go, while in contrast, Eden Fetch can be lazily executed until you pick a route.

With complex types and lot of server routes, using Eden Treaty on a low-end development device can lead to slow type inference and auto-completion.
With complex types and a lot of server routes, using Eden Treaty on a low-end development device can lead to slow type inference and auto-completion.

But as Elysia has tweak and optimized a lot of types and inference, Eden Treaty can be perform very well in the considerable amount of routes.
But as Elysia has tweaked and optimized a lot of types and inference, Eden Treaty can perform very well in the considerable amount of routes.

If your single process contains **more than 500 routes**, and you need to consume all of the routes **in a single frontend codebase**, then you might want to use Eden Fetch as it has a significant better TypeScript performance than Eden Treaty.
If your single process contains **more than 500 routes**, and you need to consume all of the routes **in a single frontend codebase**, then you might want to use Eden Fetch as it has a significantly better TypeScript performance than Eden Treaty.
8 changes: 4 additions & 4 deletions docs/eden/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bun add -d elysia
```

::: tip
Eden need Elysia to infers utilities type.
Eden needs Elysia to infer utilities type.

Make sure to install Elysia with the version matching on the server.
:::
Expand Down Expand Up @@ -68,7 +68,7 @@ client.mirror.post({
```

## Gotcha
Sometime Eden may not infers type from Elysia correctly, the following are the most common workaround to fix Eden type inference.
Sometimes Eden may not infer type from Elysia correctly, the following are the most common workaround to fix Eden type inference.

### Type Strict
Make sure to enable strict mode in **tsconfig.json**
Expand All @@ -86,9 +86,9 @@ Eden depends Elysia class to import Elysia instance and infers type correctly.
Make sure that both client and server have a matching Elysia version.

### TypeScript version
Elysia is using a newer feature and syntax of TypeScript to infers type in a most performance way, feature like Const Generic, Template Literal are heavily use.
Elysia uses newer features and syntax of TypeScript to infer types in a the most performant way. Features like Const Generic and Template Literal are heavily used.

Make sure your client have a **minimum TypeScript version if >= 5.0**
Make sure your client has a **minimum TypeScript version if >= 5.0**

### Method Chaining
To make Eden works, Elysia must be using **method chaining**
Expand Down
8 changes: 4 additions & 4 deletions docs/eden/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ head:

- - meta
- name: 'description'
content: Elysia support end-to-end type safety with Elysia Eden since start. End-to-end type-safety refers to a system in which every component of the system is checked for type consistency, meaning that data is passed between components only if the types of the data are compatible.
content: Elysia supports end-to-end type safety with Elysia Eden since start. End-to-end type-safety refers to a system in which every component of the system is checked for type consistency, meaning that data is passed between components only if the types of the data are compatible.

- - meta
- property: 'og:description'
content: Elysia support end-to-end type safety with Elysia Eden since start. End-to-end type-safety refers to a system in which every component of the system is checked for type consistency, meaning that data is passed between components only if the types of the data are compatible.
content: Elysia supports end-to-end type safety with Elysia Eden since start. End-to-end type-safety refers to a system in which every component of the system is checked for type consistency, meaning that data is passed between components only if the types of the data are compatible.
---

# End-to-End Type-Safety
Expand Down Expand Up @@ -49,7 +49,7 @@ Others framework that support e2e type safety:
Hover over variable and function to see type definition.
::: -->

Elysia allows you change the type on server and it will be instantly reflected on the client, helping with auto-completion and type-enforcement.
Elysia allows you to change the type on the server and it will be instantly reflected on the client, helping with auto-completion and type-enforcement.

## Eden
Eden is a RPC-like client to connect Elysia **end-to-end type safety** using only TypeScript's type inference instead of code generation.
Expand Down Expand Up @@ -104,7 +104,7 @@ const data = await fetch('/name/:name', {
})
```

Using Eden Treaty with a complex type and lot of routes (more than 500 routes per server) on a low-end development device can lead to slow type inference and auto-completion.
Using Eden Treaty with a complex type and a lot of routes (more than 500 routes per server) on a low-end development device can lead to slow type inference and auto-completion.

Eden Fetch is an alternative and solution for fastest type inference possible while providing full type support like Eden Treaty.

Expand Down
4 changes: 2 additions & 2 deletions docs/eden/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Using Eden, we can create an integration test with end-to-end type safety and au
> Using Eden Treaty to create tests by [irvilerodrigues on Twitter](https://twitter.com/irvilerodrigues/status/1724836632300265926)

## Setup
We can use [Bun test](https://bun.sh/guides/test/watch-mode) to create test.
We can use [Bun test](https://bun.sh/guides/test/watch-mode) to create tests.

Create **test/index.test.ts** in the root of project directory with the following:

Expand Down Expand Up @@ -56,4 +56,4 @@ Then we can perform tests by running **bun test**
bun test
```

This allows us to perform integration test programmatically instead of manual fetch while supporting type checking automatically.
This allows us to perform integration tests programmatically instead of manual fetch while supporting type checking automatically.
14 changes: 7 additions & 7 deletions docs/eden/treaty.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ head:

- - meta
- name: 'og:description'
content: Eden Treaty is a object-like representation of an Elysia server, providing an end-to-end type safety, and a significantly improved developer experience. With Eden, we can fetch an API from Elysia server fully type-safe without code generation.
content: Eden Treaty is an object-like representation of an Elysia server, providing an end-to-end type safety, and a significantly improved developer experience. With Eden, we can fetch an API from Elysia server fully type-safe without code generation.

- - meta
- name: 'og:description'
content: Eden Treaty is a object-like representation of an Elysia server, providing an end-to-end type safety, and a significantly improved developer experience. With Eden, we can fetch an API from Elysia server fully type-safe without code generation.
content: Eden Treaty is an object-like representation of an Elysia server, providing an end-to-end type safety, and a significantly improved developer experience. With Eden, we can fetch an API from Elysia server fully type-safe without code generation.
---

# Eden Treaty
Expand Down Expand Up @@ -81,7 +81,7 @@ Eden will transform `/` into `.` which can be called with a registered `method`,
- **/nested/path** -> .nested.path

### Path parameters
Path parameters will be mapped to automatically by their name in the URL.
Path parameters will be mapped automatically by their name in the URL.

- **/id/:id** -> .id.`<anyThing>`
- eg: .id.hi
Expand All @@ -108,7 +108,7 @@ Eden Treaty is a fetch wrapper, you can add any valid [Fetch](https://developer.
app.post({
$fetch: {
headers: {
'x-origanization': 'MANTIS'
'x-organization': 'MANTIS'
}
}
})
Expand Down Expand Up @@ -148,14 +148,14 @@ const { id, name } = nendoroid

Both **data**, and **error** will be typed as nullable until you can confirm their statuses with a type guard.

To put it simply, if fetch is sucessful, data will have a value and error will be null, and vice-versa.
To put it simply, if fetch is successful, data will have a value and error will be null, and vice-versa.

::: tip
Error is wrapped with an `Error` with its value return from the server can be retrieve from `Error.value`
:::

### Error type based on status
Both Eden Treaty and Eden Fetch can narrow down an error type based on status code if you explictly provided an error type in the Elysia server.
Both Eden Treaty and Eden Fetch can narrow down an error type based on status code if you explicitly provided an error type in the Elysia server.

```typescript
// server.ts
Expand Down Expand Up @@ -212,7 +212,7 @@ if(error) {
```

## WebSocket
Eden supports WebSocket using the same API as same as normal route.
Eden supports WebSocket using the same API as a normal route.
```typescript
// Server
import { Elysia, t } from 'elysia'
Expand Down
10 changes: 5 additions & 5 deletions docs/essential/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ head:

- - meta
- name: 'description'
content: Context is an information of each request from the client, unique to each request with global mutable store. Context can be customize by using state, decorate and derive.
content: Context is information about each request from the client, unique to each request with a global mutable store. Context can be customized using state, decorate and derive.

- - meta
- property: 'og:description'
content: Context is an information of each request from the client, unique to each request with global mutable store. Context can be customize by using state, decorate and derive.
content: Context is information about each request from the client, unique to each request with a global mutable store. Context can be customized using state, decorate and derive.
---

# Context
Expand All @@ -27,7 +27,7 @@ Elysia context is consists of:
- **headers** - [HTTP Header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers), additional information about the request like User-Agent, Content-Type, Cache Hint.
- **request** - [Web Standard Request](https://developer.mozilla.org/en-US/docs/Web/API/Request)
- **store** - A global mutable store for Elysia instance
- **cookie** - A global mutatable signal store for interacting with Cookie (including get/set)
- **cookie** - A global mutable signal store for interacting with Cookie (including get/set)
- **set** - Property to apply to Response:
- **status** - [HTTP status](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status), default to 200 if not set.
- **headers** - Response headers
Expand All @@ -40,7 +40,7 @@ Because Elysia only provides essential information about the Request, you can cu
Extraction of a user ID or another frequently used function related to the request, for example, into Context itself.

You can extend Elysia's context by using:
- **state** - Create a global mutatable state into **Context.store**
- **state** - Create a global mutable state into **Context.store**
- **decorate** - Add additional function or property assigned to **Context**
- **derive** - Add additional property based on existing property or request which is uniquely assigned to every request.

Expand Down Expand Up @@ -237,7 +237,7 @@ const app = new Elysia()
## Reference and value
To mutate the state, it's recommended to use **reference** to mutate rather than using an actual value.

When accessing the property from JavaScript, if you define a primitive value from an object property as a new value, the reference is lost, the value is treat as new separate value instead.
When accessing the property from JavaScript, if you define a primitive value from an object property as a new value, the reference is lost, the value is treated as new separate value instead.

For example:
```typescript
Expand Down
Loading