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
Copy file name to clipboardExpand all lines: docs/blog/elysia-06.md
+38-38Lines changed: 38 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,11 +72,11 @@ const group = new Elysia({ prefix: '/v1' })
72
72
.get('/hello', () =>'Hello World')
73
73
```
74
74
75
-
We encourage you to use the new model of Elysia plugin instance, as we can take advantage of Plugin Checksum and new possible feature in the future.
75
+
We encourage you to use the new model of Elysia plugin instance, as we can take advantage of Plugin Checksum and new possible features in the future.
76
76
77
77
However, we are **NOT deprecating** the callback function method as there's some case function model is useful like:
78
78
- Inline function
79
-
-Plugin that required an information of main instance (for example accessing OpenAPI schema)
79
+
-Plugins that required an information of main instance (for example accessing OpenAPI schema)
80
80
81
81
With this new plugin model, we hope that you can make your codebase even easier to maintain.
82
82
@@ -87,7 +87,7 @@ This means that if you register a plugin for type declaration, it will duplicate
87
87
88
88
Which is why Plugin Checksum is introduced, to de-duplicated plugin registered for type declaration.
89
89
90
-
To opt-in to Plugin Checksum, you need to use a new plugin model, and provided a `name` property to tell Elysia to not deduplicated the plugin
90
+
To opt-in to Plugin Checksum, you need to use a new plugin model, and provide a `name` property to tell Elysia to prevent the plugin from being deduplicate
91
91
```ts
92
92
const plugin =newElysia({
93
93
name: 'plugin'
@@ -96,9 +96,9 @@ const plugin = new Elysia({
96
96
97
97
This allows Elysia to identify the plugin and deduplicated based on name.
98
98
99
-
Any duplicated name will be registered only once but type-safety will be provided after registered even if the plugin is deduplicated.
99
+
Any duplicated name will be registered only once but type-safety will be provided after registration even if the plugin is deduplicated.
100
100
101
-
In case if your plugin need configuration, you can provided the configuration into a **seed** property to generate a checksum to deduplicate the plugin.
101
+
In case your plugin needs configuration, you can provide the configuration into a **seed** property to generate a checksum for deduplicating the plugin.
name and seed will be used to generate a checksum to de-duplicated registration, which leads to even better performance improvement.
110
+
Name and seed will be used to generate a checksum to de-duplicated registration, which leads to even better performance improvement.
111
111
112
-
This update also fixed the deduplication of the plugin's lifecycle accidentally inline life-cycle when Elysia is not sured if plugin is local and global event.
112
+
This update also fixed the deduplication of the plugin's lifecycle accidentally inline lifecycle when Elysia is not sure if plugin is local and global event.
113
113
114
114
As always, means performance improvement for an app that's larger than "Hello World".
115
115
@@ -138,7 +138,7 @@ A **fetch** function is a function that accept Web Standard Request and return W
138
138
typefetch= (request:RequestLike) =>Response
139
139
```
140
140
141
-
By default, this declaration are used by:
141
+
By default, this declaration is used by:
142
142
- Bun
143
143
- Deno
144
144
- Vercel Edge Runtime
@@ -178,25 +178,25 @@ new Elysia()
178
178
179
179
If an instance passed to mount is an Elysia instance, it will resolve to `use` automatically, providing type-safety and support for Eden by default.
180
180
181
-
This made the possiblility of interlopable framework and runtime to a reality.
181
+
This made the possibility of interlopable framework and runtime to a reality.
182
182
183
183
## Improved starts up time
184
-
Starts up time is an important metric in an serverless environment which Elysia excels it incredibly, but we have taken it even further.
184
+
Starts up time is an important metric in a serverless environment which Elysia excels it incredibly, but we have taken it even further.
185
185
186
-
By default, Elysia generate OpenAPI schema for every route automatically and stored it internally when if not used.
186
+
By default, Elysia generates OpenAPI schema for every route automatically and stored it internally when if not used.
187
187
188
-
In this version, Elysia defers the compliation and moved to `@elysiajs/swagger` instead allowing Elysia starts up time to be even faster.
188
+
In this version, Elysia defers the compilation and moved to `@elysiajs/swagger` instead allowing Elysia starts up time to be even faster.
189
189
190
190
And with various micro-optimization, and made possible by new Plugin model, starts up time is now up to 35% faster.
191
191
192
192
## Dynamic Mode
193
-
Elysia introduce Static Code Analysis and Ahead of Time compliation to push to boundary of performance.
193
+
Elysia introduces Static Code Analysis and Ahead of Time compilation to push the boundary of performance.
194
194
195
-
Static Code Analysis allow Elysia to read your code then produce the most optimized version code, allowing Elysia to push the performance to it's limit.
195
+
Static Code Analysis allow Elysia to read your code then produce the most optimized version code, allowing Elysia to push the performance to its limit.
196
196
197
197
Even if Elysia is WinterCG compliance, environment like Cloudflare worker doesn't support function composition.
198
198
199
-
This means that Ahead of Time Compliation isn't possible, leading us to create a dynamic mode which use JIT compliation instead of AoT, allowing Elysia to runs in Cloudflare Worker as well.
199
+
This means that Ahead of Time Compliation isn't possible, leading us to create a dynamic mode which use JIT compilation instead of AoT, allowing Elysia to run in Cloudflare Worker as well.
200
200
201
201
To enable dynamic mode, set `aot` to false.
202
202
```ts
@@ -207,18 +207,18 @@ new Elysia({
207
207
208
208
Dynamic Mode is enabled by default in cloudflare worker.
209
209
210
-
#### It's worth note that, enabling Dynamic Mode will disable some feature like dynamic injected code like `t.Numeric` which parse string to number automatically.
210
+
#### It's worth noting that, enabling Dynamic Mode will disable some feature like dynamic injected code like `t.Numeric` which parse strings to numbers automatically.
211
211
212
-
Ahead of Time compliation can read, detect and optimized your code in exchange of start up time in exchange of extra performance gain, while dynamic mode use JIT compilation, allowing start up time to be even faster up to 6x.
212
+
Ahead of Time compilation can read, detect and optimize your code in exchange for startup time in exchange for extra performance gain, while dynamic mode uses JIT compilation, allowing start up time to be even faster up to 6x.
213
213
214
-
But it should be note that starts up time in Elysia is fast enough by default.
214
+
But it should be noted that startup time in Elysia is fast enough by default.
215
215
216
-
Elysia is able to registered 10,000 routes in just 78ms which means in an average of 0.0079 ms/route
216
+
Elysia is able to register 10,000 routes in just 78ms which means in an average of 0.0079 ms/route
217
217
218
218
That being said, we are leaving a choice for you to decided yourself.
219
219
220
220
## Declarative Custom Error
221
-
This update add support for adding type support for handling custom error.
221
+
This update adds support for adding type support for handling custom error.
222
222
223
223
```ts
224
224
classCustomErrorextendsError {
@@ -242,20 +242,20 @@ new Elysia()
242
242
})
243
243
```
244
244
245
-
This allows us to handle custom type with type narrowing for handling custom error and auto-completion for error code to narrow down the correct type, fully type-safe declaratively.
245
+
This allows us to handle custom types with type narrowing for handling custom errors and auto-completion for error codes to narrow down the correct types, fully type-safe declaratively.
246
246
247
-
This fulfills one of the our main philosophy is focused on Developer Experience especially with types.
247
+
This fulfills one of our main philosophies is focused on Developer Experience especially with types.
248
248
249
-
Elysia Type System is complex, yet we try to refrained our user's need to write a custom type or passing a custom generic, retaining all the code to looks just like JavaScript.
249
+
Elysia Type System is complex, yet we try to refrained our users need to write a custom type or passing a custom generic, retaining all the code to look just like JavaScript.
250
250
251
251
It just works, and all the code looks just like JavaScript.
252
252
253
253
## TypeBox 0.30
254
-
TypeBox is a core library that powered Elysia's strict type system known as **Elysia.t**.
254
+
TypeBox is a core library that powers Elysia's strict type system known as **Elysia.t**.
255
255
256
-
In this update, we update TypeBox from 0.28 to 0.30 to make even more fine-grained Type System near strictly typed language.
256
+
In this update, we update TypeBox from 0.28 to 0.30 to make even more fine-grained Type System nearly strictly typed language.
257
257
258
-
This updates introduce new features and many interesting changes, for example **Iterator** type, reducing package size, TypeScript code generation.
258
+
These updates introduce new features and many interesting changes, for example **Iterator** type, reducing packages size, TypeScript code generation.
259
259
260
260
And with support for Utility Types like:
261
261
-`t.Awaited`
@@ -298,18 +298,18 @@ new Elysia({
298
298
We hope that this will clear any questions regards to path matching and its expected behavior
299
299
300
300
## onResponse
301
-
This update introduce a new life-cycle hook call`onResponse`.
301
+
This update introduce a new lifecycle hook called`onResponse`.
302
302
303
-
This is a proposal, proposed by [elysia#67](https://github.com/elysiajs/elysia/issues/67)
303
+
This is a proposal proposed by [elysia#67](https://github.com/elysiajs/elysia/issues/67)
304
304
305
305
Previously Elysia life-cycle works as illustrated in this diagram.
For any metric, data-collection or logging purpose, you can use `onAfterHandle` to run the function to collect metrics, however this life-cycle doesn't executed when handler runs into an error, whether it's routing error, or custom error provided.
308
+
For any metric, data-collection or logging purpose, you can use `onAfterHandle` to run the function to collect metrics, however, this lifecycle isn't executed when handler runs into an error, whether it's a routing error or a custom error provided.
309
309
310
310
Which is why we introduced `onResponse` to handle all cases of Response.
311
311
312
-
You can use `onRequest`, and `onResponse` together to measure a metric of performance or any logging requred.
312
+
You can use `onRequest`, and `onResponse` together to measure a metric of performance or any required logging.
313
313
314
314
Quoted
315
315
> However, the onAfterHandle function only fires on successful responses. For instance, if the route is not found, or the body is invalid, or an error is thrown, it is not fired. How can I listen to both successful and non-successful requests? This is why I suggested onResponse.
@@ -320,15 +320,15 @@ Quoted
320
320
---
321
321
322
322
### Notable Improvement:
323
-
-Add `error` field to Elysia type system for adding custom error message
323
+
-Added an error field to the Elysia type system for adding custom error messages
324
324
- Support Cloudflare worker with Dynamic Mode (and ENV)
325
325
- AfterHandle now automatically maps the value
326
326
- Using bun build to target Bun environment, improving the overall performance by 5-10%
327
-
- Deduplicated inline life-cycle when using plugin registration
327
+
- Deduplicated inline lifecycle when using plugin registration
328
328
- Support for setting `prefix`
329
329
- Recursive path typing
330
-
-Slighty improve type checking speed
331
-
- Recursive schema collision causing infinite type
- Moved **registerSchemaPath** to @elysiajs/swagger
@@ -342,19 +342,19 @@ Quoted
342
342
## Afterward
343
343
We have just passed a one year milestone, and really excited how Elysia and Bun have improved over the year!
344
344
345
-
Pushing performance boundary of JavaScript with Bun, and developer experience with Elysia, we are thrilled to have keeps in touch with you and our community.
345
+
Pushing the performance boundaries of JavaScript with Bun, and developer experience with Elysia, we are thrilled to have kept in touch with you and our community.
346
346
347
-
Every updates, keeps making Elysia even more stable, and having better developer experience gradually without a drop in performance and features.
347
+
Every updates, keeps making Elysia even more stable, and gradually providing a better developer experience without a drop in performance and features.
348
348
349
-
We're thrilled to see our community of open-source developers bring Elysia to life with their works like
349
+
We're thrilled to see our community of open-source developers bringing Elysia to life with their projects like.
350
350
-[Elysia Vite Plugin SSR](https://github.com/timnghg/elysia-vite-plugin-ssr) allowing us to use Vite Server Side Rendering using Elysia as the server.
351
351
-[Elysia Connect](https://github.com/timnghg/elysia-connect) which made Connect's plugin compatible with Elysia
352
352
353
353
And much more developers that choose Elysia for their next big project.
354
354
355
355
With our commitment, we also recently introduced [Mobius](https://github.com/saltyaom/mobius), and open-source TypeScript library to parse GraphQL to TypeScript type without relying on code generation by using TypeScript template literal type entirely to be the very first framework to achieve end-to-end type safety without relying on code generation.
356
356
357
-
We incredibly thanksful for your overwhelming continous support for Elysia, and we hope to see you pushing the boundary together on the next release.
357
+
We incredibly thankful for your overwhelming continous support for Elysia, and we hope to see you pushing the boundaries together in the next release.
0 commit comments