Skip to content

Commit 2eba287

Browse files
committed
📘 doc: add type popup
1 parent 37b66ab commit 2eba287

File tree

17 files changed

+113
-43
lines changed

17 files changed

+113
-43
lines changed

components/midori/just-return.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<header class="flex flex-col gap-3 w-full">
77
<h3
88
class="text-5xl leading-tight font-bold text-transparent bg-clip-text bg-gradient-to-br from-green-300 to-sky-300">
9-
Just Function
9+
Just Value
1010
</h3>
1111
<p class="text-xl leading-normal text-gray-400 w-full max-w-lg mb-4">
1212
No need for an additional method, just return the value to send data

docs/.vitepress/theme/custom.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ button.copy::after {
131131
z-index: 50 !important;
132132

133133
& > .VPNavBar {
134-
@apply dark:!bg-slate-900/0 dark:transition-none;
134+
@apply dark:!bg-slate-900/40;
135135
background-color: rgba(255, 255, 255, .4) !important;
136+
137+
& > .wrapper > .container > .content > .content-body {
138+
@apply bg-transparent;
139+
}
136140
}
137141
}
138142
}

docs/at-glance.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import { Elysia } from 'elysia'
108108

109109
new Elysia()
110110
.get('/user/:id', ({ params: { id } }) => id)
111+
// ^?
111112
.listen(3000)
112113
```
113114

@@ -129,9 +130,9 @@ Elysia's goal is to help you write less TypeScript and focus more on Business lo
129130

130131
TypeScript is not needed to use Elysia, but it's recommended to use Elysia with TypeScript.
131132

132-
## Unified Type
133+
## Type Integrity
133134

134-
To take a step further, Elysia provide **Elysia.t**, a schema builder to validate type and value in both runtime and compile-time to create a single source of truth for your data-type. Elysia refers this term as **Unified Type**.
135+
To take a step further, Elysia provide **Elysia.t**, a schema builder to validate type and value in both runtime and compile-time to create a single source of truth for your data-type.
135136

136137
Let's modify the previous code to accept only a numeric value instead of a string.
137138

@@ -140,6 +141,7 @@ import { Elysia, t } from 'elysia'
140141

141142
new Elysia()
142143
.get('/user/:id', ({ params: { id } }) => id, {
144+
// ^?
143145
params: t.Object({
144146
id: t.Numeric()
145147
})
@@ -225,6 +227,9 @@ const app = treaty<App>('localhost:3000')
225227

226228
// Get data from /user/617
227229
const { data } = await app.user({ id: 617 }).get()
230+
// ^?
231+
232+
console.log(data)
228233
```
229234

230235
With Eden, you can use the existing Elysia type to query Elysia server **without code generation** and synchronize type for both frontend and backend automatically.

docs/eden/installation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ const { data: nendoroid } = await client.mirror.post({
8383
id: 1895,
8484
name: 'Skadi'
8585
})
86+
87+
// @noErrors
88+
client.
89+
// ^|
8690
```
8791

8892
## Gotcha

docs/eden/overview.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ import { Elysia, t } from 'elysia'
7474

7575
const app = new Elysia()
7676
.get('/', 'hi')
77+
.get('/users', () => 'Skadi')
7778
.put('/nendoroid/:id', ({ body }) => body, {
7879
body: t.Object({
7980
name: t.String(),
8081
from: t.String()
8182
})
8283
})
84+
.get('/nendoroid/:id/name', () => 'Skadi')
8385
.listen(3000)
8486

8587
export type App = typeof app
@@ -91,6 +93,13 @@ import type { App } from './server'
9193

9294
const app = treaty<App>('localhost:3000')
9395

96+
// @noErrors
97+
app.
98+
// ^|
99+
100+
101+
102+
94103
// Call [GET] at '/'
95104
const { data } = await app.index.get()
96105

docs/eden/treaty/unit-test.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ describe('Elysia', () => {
3333
const { data } = await api.hello.get()
3434

3535
expect(data).toBe('hi')
36+
// ^?
37+
3638
})
3739
})
3840
```

docs/essential/context.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import { Elysia } from 'elysia'
2121

2222
const demo1 = new Elysia()
2323
.state('version', 1)
24-
.get('/', ({ store: { version } }) => version)
24+
.get('/a', ({ store: { version } }) => version)
25+
.get('/b', ({ store }) => store)
26+
.get('/c', () => 'still ok')
2527

2628
const demo2 = new Elysia()
2729
// @ts-expect-error
@@ -134,7 +136,11 @@ import { Elysia } from 'elysia'
134136

135137
new Elysia()
136138
.state('version', 1)
137-
.get('/', ({ store: { version } }) => version)
139+
.get('/a', ({ store: { version } }) => version)
140+
// ^?
141+
.get('/b', ({ store }) => store)
142+
.get('/c', () => 'still ok')
143+
.listen(3000)
138144
```
139145
140146
<Playground :elysia="demo1" />
@@ -260,11 +266,12 @@ Assigning multiple properties is better contained in an object for a single assi
260266
```typescript
261267
import { Elysia } from 'elysia'
262268

263-
new Elysia().decorate({
264-
logger: new Logger(),
265-
trace: new Trace(),
266-
telemetry: new Telemetry()
267-
})
269+
new Elysia()
270+
.decorate({
271+
logger: new Logger(),
272+
trace: new Trace(),
273+
telemetry: new Telemetry()
274+
})
268275
```
269276
270277
The object offers a less repetitive API for setting multiple values.
@@ -325,7 +332,7 @@ const app = new Elysia()
325332
setup
326333
.prefix('decorator', 'setup')
327334
)
328-
.get('/', ({ setupCarbon }) => setupCarbon)
335+
.get('/', ({ setupCarbon, ...rest }) => setupCarbon)
329336
```
330337
331338
<Playground :elysia="demo5" />
@@ -348,7 +355,7 @@ const setup = new Elysia({ name: 'setup' })
348355

349356
const app = new Elysia()
350357
.use(setup.prefix('all', 'setup')) // [!code ++]
351-
.get('/', ({ setupCarbon }) => setupCarbon)
358+
.get('/', ({ setupCarbon, ...rest }) => setupCarbon)
352359
```
353360
354361
## Reference and value

docs/essential/handler.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ HTTP Status indicates the type of response. If the route handler is executed suc
135135
You can also set a status code using the common name of the status code instead of using a number.
136136

137137
```typescript twoslash
138+
// @errors 2322
138139
import { Elysia } from 'elysia'
139140

140141
new Elysia()
141142
.get('/', ({ set }) => {
142-
// with auto-completion
143-
set.status = "I'm a teapot"
143+
set.status
144+
// ^?
144145

145146
return 'Kirifuji Nagisa'
146147
})

docs/essential/life-cycle.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ We refer to each function that intercepts the life cycle event as **"hook"**, as
9292
Hooks can be categorized into 2 types:
9393

9494
1. Local Hook: Execute on a specific route
95-
2. Global Hook: Execute on every route
95+
2. Interceptor Hook: Execute on every route
9696

9797
::: tip
9898
The hook will accept the same Context as a handler, you can imagine you adding a route handler but at a specific point.
@@ -126,11 +126,11 @@ The response should be listed as follows:
126126
| / | text/html; charset=utf8 |
127127
| /hi | text/plain; charset=utf8 |
128128

129-
## Global Hook
129+
## Interceptor Hook
130130

131-
Register hook into **every** handler that came after.
131+
Register hook into every handler **of the current instance** that came after.
132132

133-
To add a global hook, you can use `.on` followed by a life cycle event in camelCase:
133+
To add an interceptor hook, you can use `.on` followed by a life cycle event in camelCase:
134134

135135
```typescript twoslash
136136
import { Elysia } from 'elysia'

docs/essential/path.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import { Elysia } from 'elysia'
9191

9292
new Elysia()
9393
.get('/id/:id', ({ params: { id } }) => id)
94+
// ^?
9495
.listen(3000)
9596
```
9697

@@ -153,6 +154,7 @@ import { Elysia } from 'elysia'
153154
new Elysia()
154155
.get('/id/:id', ({ params: { id } }) => id)
155156
.get('/id/:id/:name', ({ params: { id, name } }) => id + ' ' + name)
157+
// ^?
156158
.listen(3000)
157159
```
158160

@@ -196,6 +198,7 @@ import { Elysia } from 'elysia'
196198

197199
new Elysia()
198200
.get('/id/*', ({ params }) => params['*'])
201+
// ^?
199202
.listen(3000)
200203
```
201204

0 commit comments

Comments
 (0)