Skip to content

Commit 183640a

Browse files
committed
🎉 feat: rapid stream
1 parent 5472291 commit 183640a

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# 1.4.13 - 23 Oct 2025
2-
Improvement:
2+
Feature:
33
- [#1453](https://github.com/elysiajs/elysia/issues/1453) add `allowUnsafeValidationDetails` for disabling unsafe validation details in production mode
4+
- allow rapid stream in non browser mode or `ELYSIA_RAPID_STREAM` is set
45

56
Bug fix:
6-
- [#1502](https://github.com/elysiajs/elysia/issues/1502) afterHandle doesn't update status
7+
- [#1502](https://github.com/elysiajs/elysia/issues/1502), [#1501](https://github.com/elysiajs/elysia/issues/1501) afterHandle doesn't update status
8+
- [#1500](https://github.com/elysiajs/elysia/issues/1500) export `InvalidFileType` from root
79
- [#1495](https://github.com/elysiajs/elysia/pull/1495) request server hook parameters are typed as any (Bun 1.3.0)
810
- [#1483](https://github.com/elysiajs/elysia/pull/1483) handle standard schema validators in ValidationError.all
911
- [#1459](https://github.com/elysiajs/elysia/pull/1459) fix strictPath behavior when aot: false is set
1012
- [#1455](https://github.com/elysiajs/elysia/pull/1455) graceful shutdown not awaiting server.stop
1113
- [#1499](https://github.com/elysiajs/elysia/pull/1449) fails when merging with t.Optional schema
14+
- remove encoding chunk from native static response in Bun adapter
1215

1316
change:
1417
- make `@types/bun` an optional dependency

example/a.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import { Elysia, t } from '../src'
2-
import { req } from '../test/utils'
1+
import { Elysia, file } from '../src'
32

43
const app = new Elysia({
54
allowUnsafeValidationDetails: true
65
})
7-
.onError(({ error }) => {
8-
// console.log(error)
9-
})
10-
.get('/q', () => {}, {
11-
query: t.Object({
12-
a: t.String()
13-
})
14-
})
6+
.get('/', file('test/images/aris-yuzu.jpg'))
157
.listen(3000)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "elysia",
33
"description": "Ergonomic Framework for Human",
4-
"version": "1.4.12",
4+
"version": "1.4.13",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

src/adapter/bun/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,11 @@ export const BunAdapter: ElysiaAdapter = {
340340
createStaticRoute(app.router.response),
341341
mapRoutes(app)
342342
),
343-
// @ts-expect-error private property
344343
app.config.serve?.routes
345344
),
346345
websocket: {
347346
...(app.config.websocket || {}),
348347
...(websocket || {}),
349-
// @ts-expect-error not available in this variant of options type
350348
...(options.websocket || {})
351349
},
352350
fetch: app.fetch
@@ -362,7 +360,6 @@ export const BunAdapter: ElysiaAdapter = {
362360
createStaticRoute(app.router.response),
363361
mapRoutes(app)
364362
),
365-
// @ts-expect-error private property
366363
app.config.serve?.routes
367364
),
368365
websocket: {
@@ -405,7 +402,6 @@ export const BunAdapter: ElysiaAdapter = {
405402
}),
406403
mapRoutes(app)
407404
),
408-
// @ts-expect-error private property
409405
app.config.serve?.routes
410406
)
411407
})
@@ -528,7 +524,7 @@ export const BunAdapter: ElysiaAdapter = {
528524
}
529525

530526
if (
531-
server?.upgrade<any>(context.request, {
527+
server?.upgrade(context.request, {
532528
headers: isNotEmpty(set.headers)
533529
? (set.headers as Record<string, string>)
534530
: undefined,

src/adapter/utils.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ export const handleFile = (
2020
set.status === 416)
2121

2222
const defaultHeader = immutable
23-
? ({
24-
'transfer-encoding': 'chunked'
25-
} as Record<string, string>)
23+
? {}
2624
: ({
2725
'accept-ranges': 'bytes',
2826
'content-range': size
2927
? `bytes 0-${size - 1}/${size}`
30-
: undefined,
31-
'transfer-encoding': 'chunked'
28+
: undefined
3229
} as Record<string, string>)
3330

3431
if (!set && !size) return new Response(response as Blob)
@@ -147,6 +144,8 @@ type CreateHandlerParameter = {
147144
mapCompactResponse(response: unknown, request?: Request): Response
148145
}
149146

147+
const allowRapidStream = process.env.ELYSIA_RAPID_STREAM === 'true'
148+
150149
export const createStreamHandler =
151150
({ mapResponse, mapCompactResponse }: CreateHandlerParameter) =>
152151
async (
@@ -207,6 +206,8 @@ export const createStreamHandler =
207206
}
208207
}
209208

209+
const isBrowser = request?.headers.has('Origin')
210+
210211
return new Response(
211212
new ReadableStream({
212213
async start(controller) {
@@ -265,7 +266,7 @@ export const createStreamHandler =
265266
else
266267
controller.enqueue(format(chunk.toString()))
267268

268-
if (!isSSE)
269+
if (!allowRapidStream && isBrowser && !isSSE)
269270
/**
270271
* Wait for the next event loop
271272
* otherwise the data will be mixed up

src/error.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export class ValidationError extends Error {
269269
| StandardSchemaV1Like,
270270
public value: unknown,
271271
private allowUnsafeValidationDetails = false,
272-
errors?: ValueErrorIterator,
272+
errors?: ValueErrorIterator
273273
) {
274274
let message = ''
275275
let error
@@ -438,7 +438,9 @@ export class ValidationError extends Error {
438438
'~standard' in this.validator ||
439439
// @ts-ignore
440440
('schema' in this.validator &&
441+
// @ts-ignore
441442
this.validator.schema &&
443+
// @ts-ignore
442444
'~standard' in this.validator.schema)
443445
) {
444446
const standard = // @ts-ignore

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8264,6 +8264,7 @@ export {
82648264
ParseError,
82658265
NotFoundError,
82668266
ValidationError,
8267+
InvalidFileType,
82678268
InternalServerError,
82688269
InvalidCookieSignature,
82698270
ERROR_CODE,

src/type-system/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const compile = <T extends TAnySchema>(schema: T) => {
4444

4545
compiler.Create = () => Value.Create(schema)
4646
compiler.Error = (v: unknown) =>
47+
// @ts-ignore
4748
new ValidationError('property', schema, v, compiler.Errors(v))
4849

4950
return compiler
@@ -56,6 +57,7 @@ export const compile = <T extends TAnySchema>(schema: T) => {
5657
'property',
5758
schema,
5859
v,
60+
// @ts-ignore
5961
Value.Errors(schema, v)
6062
)
6163
},
@@ -66,6 +68,7 @@ export const compile = <T extends TAnySchema>(schema: T) => {
6668
'property',
6769
schema,
6870
v,
71+
// @ts-ignore
6972
Value.Errors(schema, v)
7073
)
7174
}
@@ -132,9 +135,7 @@ export const fileType = async (
132135
name = file?.name ?? ''
133136
): Promise<boolean> => {
134137
if (Array.isArray(file)) {
135-
await Promise.all(
136-
file.map((f) => fileType(f, extension, name))
137-
)
138+
await Promise.all(file.map((f) => fileType(f, extension, name)))
138139

139140
return true
140141
}

0 commit comments

Comments
 (0)