Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 1.3: Red hood #1098

Closed
wants to merge 18 commits into from
Closed
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 1.3.0
Feature:
- add `jsonAccelerator`
- add `exactMirror`
- add `systemRouter` config
- add sucrose cache
- add `noValidate`
- support Ref inside inline schema

Improvement:
- reduce redundant type check when using Encode
- optimize isAsync
- unwrap Definition['typebox'] by default to prevent unnecessary UnwrapTypeModule call

# 1.2.25 - 6 Mar 2025
Bug fix:
- [#1108](https://github.com/elysiajs/elysia/issues/1108) use validation response instead of return type when schema is provided
Expand Down
Binary file modified bun.lockb
Binary file not shown.
36 changes: 16 additions & 20 deletions example/a.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { Elysia, error, t } from '../src'
import { req } from '../test/utils'
import { Elysia, t } from '../src'
import { post, req } from '../test/utils'

const app = new Elysia().mount(
'/test',
async (req) => new Response(await req.text())
const app = new Elysia().get(
'/',
() => ({
message: 'Hi' as const
}),
{
response: t.NoValidate(
t.Object({
message: t.Literal('Hi')
})
)
}
)

const testBody = JSON.stringify({ hello: 'world' })
const response = await app.handle(
new Request('http://localhost/test', {
method: 'POST',
body: testBody,
headers: {
'Content-Type': 'application/json'
}
})
)
const result = await app.handle(req('/')).then((x) => x.json())

const responseBody = await response.text()
console.log(responseBody)
console.log(response.status)
// expect(response.status).toBe(200)
// expect(responseBody).toBe(testBody)
console.log(app.routes[0].compile().toString())
174 changes: 174 additions & 0 deletions example/b.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import { TypeCompiler } from '../dist/type-system'
import { Elysia, t } from '../src'

const model = t.Object({
id: t.Number(),
name: t.Literal('SaltyAom'),
bio: t.String({
sanitize: true
}),
user: t.Object({
name: t.String(),
password: t.String()
}),
playing: t.Optional(t.String()),
games: t.Array(
t.Object({
name: t.String(),
hoursPlay: t.Number({ default: 0 }),
tags: t.Array(t.String())
})
),
metadata: t.Intersect([
t.Object({
alias: t.String()
}),
t.Object({
country: t.Nullable(t.String())
})
]),
social: t.Optional(
t.Object({
facebook: t.Optional(t.String()),
twitter: t.Optional(t.String()),
youtube: t.Optional(t.String())
})
)
})

const a = TypeCompiler.Compile(model)

const app1 = new Elysia({ jsonAccelerator: true })
.get(
'/',
() => ({
id: 1,
name: 'SaltyAom' as const,
bio: 'I like train\nhere',
user: {
name: 'SaltyAom',
password: '123456'
},
games: [
{
name: 'MiSide',
hoursPlay: 17,
tags: ['Psychological Horror', 'Cute', 'Dating Sim']
},
{
name: 'Strinova',
hoursPlay: 365,
tags: ['Free to Play', 'Anime', 'Third-Person Shooter']
},
{
name: "Tom Clancy's Rainbow Six Siege",
hoursPlay: 287,
tags: ['FPS', 'Multiplayer', 'Tactical']
}
],
metadata: {
alias: 'SaltyAom',
country: 'Thailand'
},
social: {
twitter: 'SaltyAom'
}
}),
{
response: model
}
)
.listen(3000)

const app2 = new Elysia({ jsonAccelerator: false })
.get(
'/',
() => ({
id: 1,
name: 'SaltyAom' as const,
bio: 'I like train\nhere',
user: {
name: 'SaltyAom',
password: '123456'
},
games: [
{
name: 'MiSide',
hoursPlay: 17,
tags: ['Psychological Horror', 'Cute', 'Dating Sim']
},
{
name: 'Strinova',
hoursPlay: 365,
tags: ['Free to Play', 'Anime', 'Third-Person Shooter']
},
{
name: "Tom Clancy's Rainbow Six Siege",
hoursPlay: 287,
tags: ['FPS', 'Multiplayer', 'Tactical']
}
],
metadata: {
alias: 'SaltyAom',
country: 'Thailand'
},
social: {
twitter: 'SaltyAom'
}
}),
{
response: model
}
)
.listen(3001)

const app3 = new Elysia()
.get('/', () => ({
id: 1,
name: 'SaltyAom' as const,
bio: 'I like train\nhere',
user: {
name: 'SaltyAom',
password: '123456'
},
games: [
{
name: 'MiSide',
hoursPlay: 17,
tags: ['Psychological Horror', 'Cute', 'Dating Sim']
},
{
name: 'Strinova',
hoursPlay: 365,
tags: ['Free to Play', 'Anime', 'Third-Person Shooter']
},
{
name: "Tom Clancy's Rainbow Six Siege",
hoursPlay: 287,
tags: ['FPS', 'Multiplayer', 'Tactical']
}
],
metadata: {
alias: 'SaltyAom',
country: 'Thailand'
},
social: {
twitter: 'SaltyAom'
}
}))
.listen(3002)

// console.log(
// `🦊 Elysia w/ JSON Accelerator is running at ${app1.server?.hostname}:${app1.server?.port}`
// )

// console.log(
// `🦊 Elysia w/o JSON Accelerator is running at ${app2.server?.hostname}:${app2.server?.port}`
// )

// console.log(
// `🦊 Elysia w/o response schema is running at ${app3.server?.hostname}:${app3.server?.port}`
// )

// console.log(app1.routes[0].compile().toString())
// console.log(app2.routes[0].compile().toString())
12 changes: 6 additions & 6 deletions example/stress/multiple-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { generateHeapSnapshot } from 'bun'
const total = 1000

{
console.log('Elysia')

const app = new Elysia({ precompile: true })

const t1 = performance.now()
const memory = process.memoryUsage().heapTotal / 1024 / 1024

for (let i = 0; i < total; i++)
app.onBeforeHandle(() => {
return { a: 'ok' }
}).get(`/id/${i}`, () => 'hello', {
body: t.String()
app.get(`/id/${i}`, () => 'hello', {
body: t.String(),
beforeHandle() {
return { a: 'ok' }
}
})

const memoryAfter = process.memoryUsage().heapTotal / 1024 / 1024
Expand Down
33 changes: 22 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "1.2.25",
"version": "1.3.0-exp.11",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
Expand Down Expand Up @@ -53,6 +53,11 @@
"import": "./dist/error.mjs",
"require": "./dist/cjs/error.js"
},
"./schema": {
"types": "./dist/schema.d.ts",
"import": "./dist/schema.mjs",
"require": "./dist/cjs/schema.js"
},
"./sucrose": {
"types": "./dist/sucrose.d.ts",
"import": "./dist/sucrose.mjs",
Expand Down Expand Up @@ -103,6 +108,11 @@
"import": "./dist/adapter/bun/handler.mjs",
"require": "./dist/cjs/adapter/bun/handler.js"
},
"./adapter/bun/compose": {
"types": "./dist/adapter/bun/compose.d.ts",
"import": "./dist/adapter/bun/compose.mjs",
"require": "./dist/cjs/adapter/bun/compose.js"
},
"./adapter/web-standard": {
"types": "./dist/adapter/web-standard/index.d.ts",
"import": "./dist/adapter/web-standard/index.mjs",
Expand Down Expand Up @@ -160,23 +170,24 @@
"dependencies": {
"@sinclair/typebox": "^0.34.27",
"cookie": "^1.0.2",
"exact-mirror": "^0.0.5",
"json-accelerator": "^0.1.3",
"memoirist": "^0.3.0",
"openapi-types": "^12.1.3"
},
"devDependencies": {
"@types/benchmark": "^2.1.5",
"@types/bun": "^1.2.0",
"@types/bun": "^1.2.4",
"@types/cookie": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"benchmark": "^2.1.4",
"eslint": "^8.49.0",
"eslint-plugin-security": "^2.1.0",
"eslint-plugin-sonarjs": "^0.23.0",
"expect-type": "^0.16.0",
"prettier": "^3.3.3",
"tsup": "^8.3.5",
"typescript": "^5.7.2"
"eslint": "^9.21.0",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-sonarjs": "^3.0.2",
"expect-type": "^1.2.0",
"mitata": "^1.0.34",
"prettier": "^3.5.3",
"tsup": "^8.4.0",
"typescript": "^5.8.2"
},
"peerDependencies": {
"@sinclair/typebox": ">= 0.34.0",
Expand Down
Loading
Loading