Skip to content

Commit

Permalink
🎉 feat: release 1.2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Feb 1, 2025
1 parent 1ca0ef1 commit caaf17c
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 185 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ trace
*.tsbuildinfo
.wrangler
.elysia
heap.json
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# 1.2.11
Feature:
- Compressed lifecycle event
- Lazily build radix tree for dynamic router
- Reduce memory usage:
- Compressed lifecycle event
- Avoid unnecessary declaration in compose.ts
- Lazily build radix tree for dynamic router

Change:
- Update TypeBox to 0.34.15

Bug fix:
- [#1039](vhttps://github.com/elysiajs/elysia/issues/1039) Elysia fails to start with an error inside its own code when using decorate twice with Object.create(null)
- [#1005](https://github.com/elysiajs/elysia/issues/1005) Parsing malformed body with NODE_ENV 'production' results in UNKNOWN error
- [#1037](https://github.com/elysiajs/elysia/issues/1037) Validation errors in production throw undefined is not an object (evaluating 'error2.schema')
- [#1036](https://github.com/elysiajs/elysia/issues/1036) Support Bun HTML import

# 1.2.10 - 5 Jan 2025
Feature:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
14 changes: 10 additions & 4 deletions example/a.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Elysia, t } from '../src'
import { req } from '../test/utils'
import { Elysia } from '../src'

const app = new Elysia().get('/', () => 'Static Content')
const app = new Elysia()
.ws('/ws/:id', {
message(ws, message) {
ws.send(message)
}
})
// .get('/ws/:id', () => 'hi')
.listen(3000)

console.dir(app, { depth: 10 })
// console.log(app.fetch.toString())
7 changes: 7 additions & 0 deletions example/html-import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Elysia, t } from '../src'
import Page from './index.html'

new Elysia()
.get('/', Page)
.get('/mika.mp4', Bun.file('test/kyuukurarin.mp4'))
.listen(3000)
12 changes: 12 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<title>Bun HTML Import</title>
</head>
<body>
<h1>Hi</h1>
<video>
<!-- <source src="/mika.mp4" type="video/mp4" /> -->
</video>
</body>
</html>
19 changes: 15 additions & 4 deletions example/stress/instance.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { Elysia, t } from '../../src'
import { generateHeapSnapshot } from 'bun'

const total = 100
const total = 500

const apps = []

const setup = (n = 0) => {
const app = new Elysia()
let app = new Elysia()

for(let i = 0; i < 10; i++) {
app.get(`/:a/${i + (n * total)}`, () => i)
for (let i = 0; i < 2; i++) {
// app = app.decorate(`a/${i + n * total}`, () => i)
app.get(`/a/${i + n * total}`, () => i)
}

apps.push(app)

return app
}

Expand All @@ -30,3 +36,8 @@ console.log(
)
console.log('Average', +(took / total).toFixed(4), 'ms / route')
console.log(memoryAfter - memory, 'MB memory used')

const snapshot = generateHeapSnapshot()
await Bun.write('heap.json', JSON.stringify(snapshot, null, 2))

// console.log(app.router.history)
33 changes: 33 additions & 0 deletions example/stress/memoir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { t } from '../../src'
import { Memoirist } from 'memoirist'

const total = 1000
const stack: Memoirist<any>[] = []

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

for (let i = 0; i < total; i++) {
for (let i = 0; i < 2; i++) {
const router = new Memoirist()
router.add('GET', '/a', () => 'Hello, World!')
router.add('GET', '/b', () => 'Hello, World!')

stack.push(router)
}
}

const memoryAfter = process.memoryUsage().heapTotal / 1024 / 1024
const took = performance.now() - t1

console.log(
Intl.NumberFormat().format(total),
'routes took',
+took.toFixed(4),
'ms'
)
console.log('Average', +(took / total).toFixed(4), 'ms / route')

console.log(memoryAfter - memory, 'MB memory used')
}
17 changes: 13 additions & 4 deletions example/stress/multiple-routes.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { Elysia } from '../../src'
import { Elysia, t } from '../../src'
import { generateHeapSnapshot } from 'bun'

const total = 1000

{
console.log('Elysia')

const app = new Elysia({ precompile: true })
const t = performance.now()
const t1 = performance.now()
const memory = process.memoryUsage().heapTotal / 1024 / 1024

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

const memoryAfter = process.memoryUsage().heapTotal / 1024 / 1024
const took = performance.now() - t
const took = performance.now() - t1

console.log(
Intl.NumberFormat().format(total),
Expand All @@ -22,5 +28,8 @@ const total = 1000
)
console.log('Average', +(took / total).toFixed(4), 'ms / route')

const snapshot = generateHeapSnapshot()
await Bun.write('heap.json', JSON.stringify(snapshot, null, 2))

console.log(memoryAfter - memory, 'MB memory used')
}
6 changes: 3 additions & 3 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.11-exp.1",
"version": "1.2.11",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
Expand Down Expand Up @@ -158,14 +158,14 @@
"release": "npm run build && npm run test && npm publish"
},
"dependencies": {
"@sinclair/typebox": "^0.34.13",
"@sinclair/typebox": "^0.34.15",
"cookie": "^1.0.2",
"memoirist": "^0.3.0",
"openapi-types": "^12.1.3"
},
"devDependencies": {
"@types/benchmark": "^2.1.5",
"@types/bun": "^1.1.2",
"@types/bun": "^1.2.0",
"@types/cookie": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
Expand Down
7 changes: 7 additions & 0 deletions src/adapter/bun/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export const createNativeStaticHandler = (
): (() => Response) | undefined => {
if (typeof handle === 'function' || handle instanceof Blob) return

if (
typeof handle === 'object' &&
handle?.toString() === '[object HTMLBundle]'
)
// Bun HTMLBundle
return () => handle as any

const response = mapResponse(handle, {
headers: setHeaders
})
Expand Down
7 changes: 5 additions & 2 deletions src/adapter/bun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ export const BunAdapter: ElysiaAdapter = {
...(app.config.serve || {}),
...(options || {}),
// @ts-ignore
static: app.router.static.http.static,
static: {
...app.router.static.http.static,
...app.config.serve?.static
},
websocket: {
...(app.config.websocket || {}),
...(websocket || {})
Expand Down Expand Up @@ -101,7 +104,7 @@ export const BunAdapter: ElysiaAdapter = {

process.on('beforeExit', () => {
if (app.server) {
app.server.stop()
app.server.stop?.()
app.server = null

if (app.event.stop)
Expand Down
12 changes: 9 additions & 3 deletions src/adapter/web-standard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ export const WebStandardAdapter: ElysiaAdapter = {
let fnLiteral = ''

const wsPaths = app.router.static.ws
const wsRouter = app.router.ws
const router = app.router.http

if (Object.keys(wsPaths).length || wsRouter.history.length) {
router.build()

if (
Object.keys(wsPaths).length ||
router.root.ws ||
router.history.find((x) => x['0'] === 'ws')
) {
fnLiteral += `if(r.method==='GET'){switch(p){`

for (const [path, index] of Object.entries(wsPaths)) {
Expand All @@ -135,7 +141,7 @@ export const WebStandardAdapter: ElysiaAdapter = {
fnLiteral +=
`default:` +
`if(r.headers.get('upgrade')==='websocket'){` +
`const route=wsRouter.find('ws',p)\n` +
`const route=router.find('ws',p)\n` +
`if(route){` +
`c.params=route.params\n` +
`if(route.store.handler)return route.store.handler(c)\n` +
Expand Down
Loading

0 comments on commit caaf17c

Please sign in to comment.