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-04.md
+36-37Lines changed: 36 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,41 +38,40 @@ head:
38
38
date="30 Mar 2023"
39
39
>
40
40
41
-
Named after the opening music of ["The Liar Princess and the Blind Prince" trailer](https://youtu.be/UdBespMvxaA), [「月夜の音楽会」(Moonlit Night Concert)](https://youtu.be/o8b-IQulh1c) composed and sang by Akiko Shikata.
41
+
Named after the opening music of ["The Liar Princess and the Blind Prince" trailer](https://youtu.be/UdBespMvxaA), [「月夜の音楽会」(Moonlit Night Concert)](https://youtu.be/o8b-IQulh1c), composed and performed by Akiko Shikata.
42
42
43
-
This version doesn't introduce an exciting new feature, later but a foundation for more solid ground, and internal improvement for the future of Elysia.
43
+
This version doesn't introduce a single exciting new featurebut rather lays a foundation for a more solid platform, focusing on internal improvements for the future of Elysia.
44
44
45
-
## Ahead of Time Complie
46
-
By default, Elysia has to deal with conditional checking in various situations, for example, checking if the life-cycle of the route existed before performing, or unwrapping validation schema if provided.
45
+
## Ahead-of-Time Compile
46
+
By default, Elysia must deal with conditional checks in various situations, for example, checking if a route's life-cycle exists before executing it, or unwrapping a validation schema if provided.
47
47
48
-
This introduces a minimal overhead to Elysia and overall because even if the route doesn't have a life-cycle event attached to it, it needs to be runtime checked.
48
+
This introduces a small runtime overhead because even if a route doesn't have a life-cycle event attached, it still needs to be checked at runtime.
49
49
50
50
Since every function is checked on compile time, it's not possible to have a conditional async, for example, a simple route that returns a file should be synced, but since it's compile-time checking, some routes might be async thus making the same simple route async too.
51
51
52
-
An async function introduces an additional tick to the function, making it a bit slower. But since Elysia is a foundation for web servers, we want to optimize every part to make sure that you don't run into performance problems.
52
+
An async function introduces an additional tick, making it slightly slower. Since Elysia is a foundation for web servers, we optimize every part to help you avoid performance problems.
53
53
54
-
We fix this small overhead by introducing AheadTime Compilation.
54
+
We address this overhead by introducing Ahead-of-Time Compilation.
55
55
56
-
As the name suggests, instead of checking dynamic life-cycle and validation on the runtime, Elysia checks life-cycle, validation, and the possibility of an async function and generates a compact function, removing an unnecessary part like an un-used life-cycle and validation.
56
+
As the name suggests, instead of checking dynamic life-cycle hooks and validation at runtime, Elysia checks life-cycle hooks, validation, and the possibility of an async function at compile time and generates a compact function, removing unnecessary parts like unused life-cycle hooks and validation.
57
57
58
-
Making conditional async function possible, since instead of using a centralized function for handling, we compose a new function especially created for each route instead. Elysia then checks all life-cycle functions and handlers to see if there's an async, and if not, the function will be synced to reduce additional overhead.
58
+
Conditional async functions become possible because, instead of using a centralized handler, we compose a new function specifically created for each route. Elysia checks all life-cycle functions and handlers to see if any are async; if not, the generated function will be synchronous to reduce overhead.
59
59
60
60
## TypeBox 0.26
61
-
TypeBox is a library that powered Elysia's validation and type provider to create a type-level single source of truth, re-exported as **Elysia.t**.
61
+
TypeBox is the library that powers Elysia's validation and type system, providing a single source of truth at the type level and re-exported as **Elysia.t**.
62
62
63
-
In this update, we update TypeBox from 0.25.4 to 0.26.
63
+
In this update, we upgrade TypeBox from 0.25.4 to 0.26.
64
64
65
-
This brings a lot of improvement and new features, for example, a `Not` type and `Convert` for `coercion`value which we might support in some next version of Elysia.
65
+
This brings many improvements and new features, for example, a `Not` type and `Convert` for `coercion`values which we may support in a future version of Elysia.
66
66
67
-
But the one benefit for Elysia would be, `Error.First()` which allows us to get the first error of type instead of using Iterator, this reduces overhead in creating a new Error to send back to the client.
67
+
One notable benefit for Elysia is `Error.First()`, which lets us get the first error instead of using an iterator. This reduces overhead when creating a new `Error` to send back to the client.
68
68
69
-
There are some changes to **TypeBox** and **Elysia.t** that normally wouldn't have much effect on your end, but you can see what's a new feature in [TypeBox release here.](https://github.com/sinclairzx81/typebox/blob/master/changelog/0.26.0.md)
69
+
There are some changes to **TypeBox** and **Elysia.t** that normally won't affect you much, but you can see what's new in the [TypeBox release notes](https://github.com/sinclairzx81/typebox/blob/master/changelog/0.26.0.md).
70
70
71
71
## Validate response per status
72
-
Previously, Elysia's response validate multiple status responses using union type.
72
+
Previously, Elysia validated multiple status responses using a union type.
73
73
74
-
This might have unexpected results for highly dynamic apps with a strict response for status.
75
-
For example if you have a route like:
74
+
This could produce unexpected results for highly dynamic apps that require strict validation per status. For example, if you have a route like:
It's expected that if 200 response is not a string, then it should throw a validation error, but in reality, it wouldn't throw an error because response validation is using union. This might leave an unexpected value to the end user and a type error for Eden Treaty.
86
+
It's expected that if a 200 response is not a string, it should throw a validation error, but in reality it wouldn't because response validation used a union. This could leave an unexpected value for the end user and cause a type error for Eden Treaty.
88
87
89
-
With this release, a response is validated per status instead of union, which means that it will strictly validate based on response status instead of unioned type.
88
+
With this release, responses are validated per status instead of using a union, which means validation is strict based on the response status.
90
89
91
90
## Separation of Elysia Fn
92
-
Elysia Fn is a great addition to Elysia, with Eden, it breaks the boundary between client and server allowing you to use any server-side function in your client, fully type-safe and even with primitive types like Error, Set, and Map.
91
+
Elysia Fn is a great addition to Elysia. With Eden, it breaks the boundary between client and server, allowing you to use server-side functions in your client app, fully type-safe and with primitive types like Error, Set, and Map.
93
92
94
-
But with the primitive type support, Elysia Fn depends on "superjson" which is around 38% of Elysia's dependency size.
93
+
However, because of primitive type support, Elysia Fn depends on `superjson`, which accounts for around 38% of Elysia's dependency size.
95
94
96
-
In this release, to use Elysia Fn, you're required to explicitly install `@elysiajs/fn` to use Elysia Fn. This approach is like installing an additional feature same as `cargo add --feature`.
95
+
In this release, to use Elysia Fn you must explicitly install `@elysiajs/fn`. This approach is similar to installing an optional feature (e.g., `cargo add --feature`).
97
96
98
-
This makes Elysia lighter for servers that don't use Elysia Fn, Following our philosophy,**To ensure that you have what you actually need**
97
+
This makes Elysia lighter for servers that don't use Elysia Fn—following our philosophy:**To ensure that you have only what you actually need**.
99
98
100
-
However, if you forgot to install Elysia Fn and accidentally use Elysia Fn, there will be a type warning reminding you to install Elysia Fn before usage, and a runtime error telling the same thing.
99
+
If you forget to install Elysia Fn and attempt to use it, you'll get a type warning reminding you to install `@elysiajs/fn`, and a runtime error with the same message.
101
100
102
-
For migration, besides a breaking change of installing `@elysiajs/fn` explicitly, there's no migration need.
101
+
For migration, besides the breaking change of installing `@elysiajs/fn` explicitly, no other migration is required.
103
102
104
103
## Conditional Route
105
-
This release introduces `.if` method for registering a conditional route or plugin.
104
+
This release introduces the `.if` method for registering a conditional route or plugin.
106
105
107
-
This allows you to declaratively for a specific conditional, for example excluding Swagger documentation from the production environment.
106
+
This allows you to declaratively register conditional—for example, excluding Swagger documentation in production:
Eden Treaty will be able to recognize the route as if it's a normal route/plugin.
115
+
Eden Treaty will be able to recognize the route as a normal route/plugin.
117
116
118
117
## Custom Validation Error
119
-
Big thanks to amirrezamahyari on [#31](https://github.com/elysiajs/elysia/pull/31) which allows Elysia to access TypeBox's error property, for a better programmatically error response.
118
+
Big thanks to amirrezamahyari on [#31](https://github.com/elysiajs/elysia/pull/31) which allows Elysia to access TypeBox's error property for better programmatic error responses.
120
119
121
120
```ts
122
121
newElysia()
@@ -146,26 +145,26 @@ new Elysia()
146
145
.listen(3000)
147
146
```
148
147
149
-
Now you can create a validation error for your API not limited to only the first error.
148
+
Now you can create a validation error for your API that is not limited to only the first error.
150
149
151
150
---
152
151
153
-
### Notable Improvement:
152
+
### Notable Improvements:
154
153
- Update TypeBox to 0.26.8
155
154
- Inline a declaration for response type
156
-
- Refactor some type for faster response
157
-
- Use Typebox`Error().First()` instead of iteration
155
+
- Refactor some types for faster responses
156
+
- Use TypeBox`Error().First()` instead of iteration
158
157
- Add `innerHandle` for returning an actual response (for benchmark)
159
158
160
159
### Breaking Change:
161
-
- Separate `.fn`to`@elysiajs/fn`
160
+
- Separate `.fn`into`@elysiajs/fn`
162
161
163
162
## Afterward
164
-
This release might not be a big release with a new exciting feature, but this improve a solid foundation, and Proof of Concept for planned I have for Elysia in the future, and making Elysia even faster and more versatile than it was.
163
+
This release might not introduce an exciting new feature, but it improves the foundation and serves as a proof of concept for planned features in Elysia's future, making Elysia faster and more versatile.
165
164
166
-
I'm really excited for what will be unfold in the future.
165
+
I'm really excited about what will unfold in the future.
0 commit comments