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-07.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,7 +115,7 @@ Reactive Cookie take a more modern approach like signal to handle cookie with an
115
115
There's no `getCookie`, `setCookie`, everything is just a cookie object.
116
116
117
117
When you want to use cookie, you just extract the name get/set its value like:
118
-
```ts
118
+
```typescript
119
119
app.get('/', ({ cookie: { name } }) => {
120
120
// Get
121
121
name.value
@@ -134,7 +134,7 @@ With the merge of cookie into the core of Elysia, we introduce a new **Cookie Sc
134
134
135
135
This is useful when you have to strictly validate cookie session or want to have a strict type or type inference for handling cookie.
136
136
137
-
```ts
137
+
```typescript
138
138
app.get('/', ({ cookie: { name } }) => {
139
139
// Set
140
140
name.value= {
@@ -161,7 +161,7 @@ Cookie signature is a cryptographic hash appended to a cookie's value, generated
161
161
This make sure that the cookie value is not modified by malicious actor, helps in verifying the authenticity and integrity of the cookie data.
162
162
163
163
To handle cookie signature in Elysia, it's a simple as providing a `secert` and `sign` property:
164
-
```ts
164
+
```typescript
165
165
newElysia({
166
166
cookie: {
167
167
secret: 'Fischl von Luftschloss Narfidort'
@@ -189,7 +189,7 @@ By provide a cookie secret, and `sign` property to indicate which cookie should
189
189
Elysia then sign and unsign cookie value automatically, eliminate the need of **sign** / **unsign** function manually.
190
190
191
191
Elysia handle Cookie's secret rotation automatically, so if you have to migrate to a new cookie secret, you can just append the secret, and Elysia will use the first value to sign a new cookie, while trying to unsign cookie with the rest of the secret if match.
192
-
```ts
192
+
```typescript
193
193
newElysia({
194
194
cookie: {
195
195
secret: ['Vengeance will be mine', 'Fischl von Luftschloss Narfidort']
@@ -207,7 +207,7 @@ This brings new exciting feature like support for TypeBox's `Decode` in Elysia n
207
207
Previously, a custom type like `Numeric` require a dynamic code injection to convert numeric string to number, but with the use of TypeBox's decode, we are allow to define a custom function to encode and decode the value of a type automatically.
@@ -231,7 +231,7 @@ We can't wait to see what you will brings with the introduction of `t.Transform`
231
231
With an introduction **Transform**, we have add a new type like `t.ObjectString` to automatically decode a value of Object in request.
232
232
233
233
This is useful when you have to use **multipart/formdata** for handling file uploading but doesn't support object. You can now just use `t.ObjectString()` to tells Elysia that the field is a stringified JSON, so Elysia can decode it automatically.
234
-
```ts
234
+
```typescript
235
235
newElysia({
236
236
cookie: {
237
237
secret: 'Fischl von Luftschloss Narfidort'
@@ -279,7 +279,7 @@ To summarize, Elysia allows us to decorate and request and store with any value
279
279
As the name suggest, this allow us to remap existing `state`, `decorate`, `model`, `derive` to anything we like to prevent name collision, or just wanting to rename a property.
280
280
281
281
By providing a function as a first parameters, the callback will accept current value, allowing us to remap the value to anything we like.
282
-
```ts
282
+
```typescript
283
283
newElysia()
284
284
.state({
285
285
a: "a",
@@ -290,7 +290,7 @@ new Elysia()
290
290
```
291
291
292
292
This is useful when you have to deal with a plugin that has some duplicate name, allowing you to remap the name of the plugin:
293
-
```ts
293
+
```typescript
294
294
newElysia()
295
295
.use(
296
296
plugin
@@ -304,11 +304,11 @@ new Elysia()
304
304
Remap function can be use with `state`, `decorate`, `model`, `derive` to helps you define a correct property name and preventing name collision.
305
305
306
306
### Affix
307
-
The provide a smoother experience, some plugins might have a lot of property value which can be overwhelming to remap one-by-one.
307
+
To provide a smoother experience, some plugins might have a lot of property value which can be overwhelming to remap one-by-one.
308
308
309
-
The **Affix** function which consists of **prefix** and **suffix**, allowing us to remap all property of an instance.
309
+
The **Affix** function, which consists of a **prefix** and **suffix**, allows us to remap all properties of an instance, preventing the name collision of the plugin.
310
310
311
-
```ts
311
+
```typescript
312
312
const setup =newElysia({ name: 'setup' })
313
313
.decorate({
314
314
argon: 'a',
@@ -329,7 +329,7 @@ Allowing us to bulk remap a property of the plugin effortlessly, preventing the
329
329
By default, **affix** will handle both runtime, type-level code automatically, remapping the property to camelCase as naming convention.
330
330
331
331
In some condition, you can also remap `all` property of the plugin:
332
-
```ts
332
+
```typescript
333
333
const app =newElysia()
334
334
.use(
335
335
setup
@@ -345,7 +345,7 @@ With the introduction of Elysia 0.7, Elysia can now truly encapsulate an instanc
345
345
346
346
The new scope model can even prevent event like `onRequest` to be resolve on a main instance which is not possible.
0 commit comments