Skip to content

Commit 524db40

Browse files
authored
Merge pull request #1141 from elysiajs/herta
release 1.3: Herta
2 parents 29928d2 + 72c89db commit 524db40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+11742
-5442
lines changed

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
.husky
1111
.eslintrc.json
1212

13+
bun.lock
1314
bun.lockb
1415
node_modules
1516
tsconfig.json
1617
CHANGELOG.md
18+
heap.json
1719

1820
example
1921
tests
@@ -35,3 +37,4 @@ trace
3537
build.ts
3638
.scannerwork
3739
src
40+
server

CHANGELOG.md

+59
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
1+
# 1.3.0
2+
Feature:
3+
- add `exactMirror`
4+
- add `systemRouter` config
5+
- `standalone Validator`
6+
- add `Elysia.Ref` for referencing schema with autocompletion instead of `t.Ref`
7+
- support Ref inside inline schema
8+
- add sucrose cache
9+
- new validation `t.Form`, `t.NoValidate`
10+
- use `file-type` to check file type
11+
- add `INVALID_FILE_TYPE` error
12+
- add `sanitize` options
13+
14+
Improvement:
15+
- `encodeSchema` now stable and enabled by default
16+
- optimize types
17+
- reduce redundant type check when using Encode
18+
- optimize isAsync
19+
- unwrap Definition['typebox'] by default to prevent unnecessary UnwrapTypeModule call
20+
- Elysia.form can now be type check
21+
- refactor type-system
22+
- refactor `_types` into `~Types`
23+
- using aot compilation to check for custom Elysia type, eg. Numeric
24+
- refactor `app.router.static`, and move static router code generation to compile phase
25+
- optimize memory usage on `add`, `_use`, and some utility functions
26+
- improve start up time on multiple route
27+
- dynamically create cookie validator as needed in compilation process
28+
- reduce object cloning
29+
- optimize start index for finding delimiter of a content type header
30+
- Promise can now be a static response
31+
- `ParseError` now keeps stack trace
32+
- refactor `parseQuery` and `parseQueryFromURL`
33+
- add `config` options to `mount`
34+
- recompile automatically after async modules is mounted
35+
- support macro on when hook has function
36+
- support resolve macro on ws
37+
- [#1146](https://github.com/elysiajs/elysia/pull/1146) add support to return web API's File from handler
38+
- [#1165](https://github.com/elysiajs/elysia/pull/1165) skip non-numeric status codes in response schema validation
39+
- [#1177](https://github.com/elysiajs/elysia/issues/1177) cookie does not sign when an error is thrown
40+
41+
Bug fix:
42+
- `Response` returned from `onError` is using octet stream
43+
- unintentional memory allocation when using `mergeObjectArray`
44+
- handle empty space on Date query
45+
46+
Change:
47+
- only provide `c.request` to mapResponse when `maybeStream` is true
48+
- use plain object for `routeTree` instead of `Map`
49+
- remove `compressHistoryHook` and `decompressHistoryHook`
50+
- webstandard handler now return `text/plain` if not on Bun
51+
- use non const value for `decorate` unless explicitly specified
52+
- `Elysia.mount` now set `detail.hide = true` by default
53+
54+
Breaking Change:
55+
- remove `as('plugin')` in favor of `as('scoped')`
56+
- remove root `index` for Eden Treaty
57+
- remove `websocket` from `ElysiaAdapter`
58+
- remove `inference.request`
59+
160
# 1.2.25 - 6 Mar 2025
261
Bug fix:
362
- [#1108](https://github.com/elysiajs/elysia/issues/1108) use validation response instead of return type when schema is provided

build.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { $ } from 'bun'
22
import { build, type Options } from 'tsup'
33

4+
const external = ['@sinclair/typebox', 'file-type']
5+
46
const tsupConfig: Options = {
57
entry: ['src/**/*.ts'],
68
splitting: false,
79
sourcemap: false,
810
clean: true,
9-
bundle: false,
10-
minify: false
11+
bundle: true,
12+
minifySyntax: true,
13+
minifyWhitespace: false,
14+
minifyIdentifiers: false,
15+
target: 'node20',
16+
external
1117
// outExtension() {
1218
// return {
1319
// js: '.js'
@@ -20,15 +26,13 @@ await Promise.all([
2026
build({
2127
outDir: 'dist',
2228
format: 'esm',
23-
target: 'node20',
2429
cjsInterop: false,
2530
...tsupConfig
2631
}),
2732
// ? tsup cjs
2833
build({
2934
outDir: 'dist/cjs',
3035
format: 'cjs',
31-
target: 'node20',
3236
// dts: true,
3337
...tsupConfig
3438
})
@@ -74,13 +78,8 @@ await Bun.build({
7478
identifiers: false
7579
},
7680
target: 'bun',
77-
sourcemap: 'external',
78-
external: [
79-
'@sinclair/typebox',
80-
'cookie',
81-
'fast-decode-uri-component',
82-
'memoirist'
83-
]
81+
sourcemap: 'linked',
82+
external
8483
})
8584

8685
await Promise.all([

bun.lock

+760
Large diffs are not rendered by default.

bun.lockb

-94.8 KB
Binary file not shown.

example/a.ts

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
import { Elysia, error, t } from '../src'
2-
import { req } from '../test/utils'
1+
import { Elysia, t } from '../src'
32

4-
const app = new Elysia().mount(
5-
'/test',
6-
async (req) => new Response(await req.text())
7-
)
8-
9-
const testBody = JSON.stringify({ hello: 'world' })
10-
const response = await app.handle(
11-
new Request('http://localhost/test', {
12-
method: 'POST',
13-
body: testBody,
14-
headers: {
15-
'Content-Type': 'application/json'
16-
}
3+
const app = new Elysia()
4+
.get('/', ({ request }) => {
5+
request.url
176
})
18-
)
7+
.listen(3000)
198

20-
const responseBody = await response.text()
21-
console.log(responseBody)
22-
console.log(response.status)
23-
// expect(response.status).toBe(200)
24-
// expect(responseBody).toBe(testBody)
9+
// console.log(app.routes[0].compile().toString())

example/stress/instance.ts

+13-31
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,25 @@
11
import { Elysia, t } from '../../src'
2-
import { generateHeapSnapshot } from 'bun'
32

4-
const total = 500
5-
6-
const apps = []
7-
8-
const setup = (n = 0) => {
9-
let app = new Elysia()
10-
11-
for (let i = 0; i < 2; i++) {
12-
// app = app.decorate(`a/${i + n * total}`, () => i)
13-
app.get(`/a/${i + n * total}`, () => i)
14-
}
15-
16-
apps.push(app)
17-
18-
return app
19-
}
3+
const total = 100
4+
const sub = 5
205

216
const app = new Elysia()
227

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

26-
for (let i = 0; i < total; i++) app.use(setup(i))
11+
for (let i = 0; i < total; i++) {
12+
const plugin = new Elysia()
2713

28-
const memoryAfter = process.memoryUsage().heapTotal / 1024 / 1024
29-
const took = performance.now() - t1
14+
for (let j = 0; j < sub; j++) plugin.get(`/${i * sub + j}`, () => 'hi')
3015

31-
console.log(
32-
Intl.NumberFormat().format(total),
33-
'routes took',
34-
+took.toFixed(4),
35-
'ms'
36-
)
37-
console.log('Average', +(took / total).toFixed(4), 'ms / route')
38-
console.log(memoryAfter - memory, 'MB memory used')
16+
app.use(plugin)
17+
}
3918

40-
const snapshot = generateHeapSnapshot()
41-
await Bun.write('heap.json', JSON.stringify(snapshot, null, 2))
19+
const t2 = performance.now()
4220

43-
// console.log(app.router.history)
21+
Bun.gc(true)
22+
23+
const memoryAfter = process.memoryUsage().heapTotal / 1024 / 1024
24+
console.log(+(memoryAfter - memory).toFixed(2), 'MB memory used')
25+
console.log(+(t2 - t1).toFixed(2), 'ms')

example/stress/multiple-routes.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { Elysia, t } from '../../src'
2-
import { generateHeapSnapshot } from 'bun'
32

4-
const total = 1000
3+
const total = 500
54

65
{
7-
console.log('Elysia')
6+
const app = new Elysia()
87

9-
const app = new Elysia({ precompile: true })
108
const t1 = performance.now()
119
const memory = process.memoryUsage().heapTotal / 1024 / 1024
1210

1311
for (let i = 0; i < total; i++)
14-
app.onBeforeHandle(() => {
15-
return { a: 'ok' }
16-
}).get(`/id/${i}`, () => 'hello', {
17-
body: t.String()
12+
app.get(`/id/${i}`, () => 'hello', {
13+
response: t.Object({
14+
hello: t.String(),
15+
world: t.String(),
16+
extra: t.Object({
17+
a: t.Array(t.String()),
18+
b: t.Nullable(t.Array(t.String())),
19+
name: t.String()
20+
})
21+
})
1822
})
1923

2024
const memoryAfter = process.memoryUsage().heapTotal / 1024 / 1024
@@ -28,8 +32,6 @@ const total = 1000
2832
)
2933
console.log('Average', +(took / total).toFixed(4), 'ms / route')
3034

31-
const snapshot = generateHeapSnapshot()
32-
await Bun.write('heap.json', JSON.stringify(snapshot, null, 2))
33-
3435
console.log(memoryAfter - memory, 'MB memory used')
36+
console.log(((memoryAfter - memory) / total) * 1024, 'KB memory used')
3537
}

0 commit comments

Comments
 (0)