Skip to content

Commit 49173ca

Browse files
committed
🔧 fix: remove old test case
1 parent 5bbf6e5 commit 49173ca

File tree

6 files changed

+73
-177
lines changed

6 files changed

+73
-177
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 1.4.6 - 23 Dec 2025
2+
Bug fix:
3+
- [#235](https://github.com/elysiajs/eden/pull/235) SSE stream parser with partial chunks
4+
- [#234](https://github.com/elysiajs/eden/pull/234) Handle network errors in treaty and edenFetch
5+
- [#230](https://github.com/elysiajs/eden/pull/230) properly await async headers functions in treaty
6+
- [#229](https://github.com/elysiajs/eden/pull/229) auto-stringify ArrayString/ObjectString in FormData
7+
- [#227](https://github.com/elysiajs/eden/pull/227) correct type inference for t.Date() in query parameters
8+
19
# 1.4.5 - 13 Nov 2025
210
Improvement:
311
- export `EdenFetchError`

example/a.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
1-
import { Elysia, sse } from 'elysia'
1+
import { Elysia, t } from 'elysia'
22
import { treaty } from '../src'
33

4-
export const app = new Elysia()
5-
.get('/chunk', async function* () {
6-
const chunks = ['chunk1', 'chunk2\n\nhello world']
7-
8-
for (const chunk of chunks)
9-
yield sse({
10-
event: 'data',
11-
data: { text: chunk, attempt: 1 }
12-
})
13-
14-
yield sse({
15-
event: 'complete',
16-
data: { message: 'done' }
4+
const app = new Elysia()
5+
.post('/files', ({ body: { files } }) => files.map((file) => file.name), {
6+
body: t.Object({
7+
files: t.Files()
8+
})
9+
})
10+
.post('/any/file', ({ body: { file } }) => file.name, {
11+
body: t.Object({
12+
file: t.File({ type: 'image/*' })
1713
})
1814
})
19-
.listen(3000)
15+
.post('/png/file', ({ body: { file } }) => file.name, {
16+
body: t.Object({
17+
file: t.File({ type: 'image/png' })
18+
})
19+
})
20+
21+
const client = treaty(app)
22+
type client = typeof client
23+
24+
const filePath1 = `test/public/aris-yuzu.jpg`
25+
const filePath2 = `test/public/midori.png`
26+
const filePath3 = `test/public/kyuukurarin.mp4`
2027

21-
const api = treaty<typeof app>('localhost:3000')
28+
const bunFile1 = Bun.file(filePath1)
29+
const bunFile2 = Bun.file(filePath2)
30+
const bunFile3 = Bun.file(filePath3)
2231

23-
const { data } = await api.chunk.get()
32+
const { data: files } = await client.files.post({
33+
files: bunFile1
34+
})
2435

25-
for await (const datum of data!) {
26-
console.log(datum)
27-
}
36+
console.log(files)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elysiajs/eden",
3-
"version": "1.4.5",
3+
"version": "1.4.6",
44
"description": "Fully type-safe Elysia client",
55
"author": {
66
"name": "saltyAom",

src/treaty2/index.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ const createNewFile = (v: File) =>
5151
isServer
5252
? v
5353
: new Promise<File>((resolve) => {
54-
const reader = new FileReader()
54+
const reader = new FileReader()
5555

56-
reader.onload = () => {
57-
const file = new File([reader.result!], v.name, {
58-
lastModified: v.lastModified,
59-
type: v.type
60-
})
61-
resolve(file)
62-
}
56+
reader.onload = () => {
57+
const file = new File([reader.result!], v.name, {
58+
lastModified: v.lastModified,
59+
type: v.type
60+
})
61+
resolve(file)
62+
}
6363

64-
reader.readAsArrayBuffer(v)
65-
})
64+
reader.readAsArrayBuffer(v)
65+
})
6666

6767
const processHeaders = async (
6868
h: Treaty.Config['headers'],
@@ -139,9 +139,9 @@ function parseSSEBlock(block: string): Record<string, unknown> | null {
139139
* Extracts complete SSE events from buffer, yielding parsed events.
140140
* Mutates bufferRef.value to remove consumed events.
141141
*/
142-
function* extractEvents(
143-
bufferRef: { value: string }
144-
): Generator<Record<string, unknown>> {
142+
function* extractEvents(bufferRef: {
143+
value: string
144+
}): Generator<Record<string, unknown>> {
145145
let eventEnd: number
146146
while ((eventEnd = bufferRef.value.indexOf('\n\n')) !== -1) {
147147
const eventBlock = bufferRef.value.slice(0, eventEnd)
@@ -202,7 +202,7 @@ const createProxy = (
202202
paths: string[] = [],
203203
elysia?: Elysia<any, any, any, any, any, any>
204204
): any =>
205-
new Proxy(() => { }, {
205+
new Proxy(() => {}, {
206206
get(_, param: string): any {
207207
return createProxy(
208208
domain,
@@ -237,7 +237,7 @@ const createProxy = (
237237

238238
const query = isGetOrHead
239239
? (body as Record<string, string | string[] | undefined>)
240-
?.query
240+
?.query
241241
: options?.query
242242

243243
let q = ''
@@ -275,12 +275,12 @@ const createProxy = (
275275
domain.startsWith('https://')
276276
? 'wss://'
277277
: domain.startsWith('http://')
278+
? 'ws://'
279+
: locals.find((v) =>
280+
(domain as string).includes(v)
281+
)
278282
? 'ws://'
279-
: locals.find((v) =>
280-
(domain as string).includes(v)
281-
)
282-
? 'ws://'
283-
: 'wss://'
283+
: 'wss://'
284284
) +
285285
path +
286286
q
@@ -353,21 +353,22 @@ const createProxy = (
353353
if (isFile(value)) return false
354354

355355
// Objects and Arrays should be stringified
356-
if (typeof value === 'object' && value !== null) {
357-
return true
356+
if (typeof value === 'object') {
357+
if (value !== null) return true
358+
if (value instanceof Date) return false
358359
}
359360

360361
return false
361362
}
362363

363-
const prepareValue = async (value: any): Promise<any> => {
364-
if (value instanceof File) {
364+
const prepareValue = async (
365+
value: any
366+
): Promise<any> => {
367+
if (value instanceof File)
365368
return await createNewFile(value)
366-
}
367369

368-
if (shouldStringify(value)) {
370+
if (shouldStringify(value))
369371
return JSON.stringify(value)
370-
}
371372

372373
return value
373374
}
@@ -453,13 +454,13 @@ const createProxy = (
453454
// fetchInit.headers['content-type'] = 'multipart/form-data'
454455
fetchInit.body = formData
455456
} else if (typeof body === 'object') {
456-
; (fetchInit.headers as Record<string, string>)[
457+
;(fetchInit.headers as Record<string, string>)[
457458
'content-type'
458459
] = 'application/json'
459460

460461
fetchInit.body = JSON.stringify(body)
461462
} else if (body !== undefined && body !== null) {
462-
; (fetchInit.headers as Record<string, string>)[
463+
;(fetchInit.headers as Record<string, string>)[
463464
'content-type'
464465
] = 'text/plain'
465466
}
@@ -545,7 +546,7 @@ const createProxy = (
545546
}
546547

547548
switch (
548-
response.headers.get('Content-Type')?.split(';')[0]
549+
response.headers.get('Content-Type')?.split(';')[0]
549550
) {
550551
case 'text/event-stream':
551552
data = streamResponse(response)
@@ -566,7 +567,7 @@ const createProxy = (
566567
break
567568

568569
case 'multipart/form-data':
569-
const temp = await response.formData() as FormData
570+
const temp = (await response.formData()) as FormData
570571

571572
data = {}
572573
temp.forEach((value, key) => {

test/treaty2-files.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ const client = treaty(app)
2525
type client = typeof client
2626

2727
describe('Treaty2 - Using t.File() and t.Files() from server', async () => {
28-
const filePath1 = `${import.meta.dir}/public/aris-yuzu.jpg`
29-
const filePath2 = `${import.meta.dir}/public/midori.png`
30-
const filePath3 = `${import.meta.dir}/public/kyuukurarin.mp4`
28+
const filePath1 = `test/public/aris-yuzu.jpg`
29+
const filePath2 = `test/public/midori.png`
30+
const filePath3 = `test/public/kyuukurarin.mp4`
3131

3232
const bunFile1 = Bun.file(filePath1)
3333
const bunFile2 = Bun.file(filePath2)

test/treaty2.test.ts

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,128 +1208,6 @@ describe('Treaty2 - SSE Chunk Splitting (fast streaming edge cases)', () => {
12081208
{ event: 'third', data: 3 }
12091209
])
12101210
})
1211-
})
1212-
1213-
describe('Treaty2 - Using t.File() and t.Files() from server', async () => {
1214-
const filePath1 = `${import.meta.dir}/public/aris-yuzu.jpg`
1215-
const filePath2 = `${import.meta.dir}/public/midori.png`
1216-
const filePath3 = `${import.meta.dir}/public/kyuukurarin.mp4`
1217-
1218-
const bunFile1 = Bun.file(filePath1)
1219-
const bunFile2 = Bun.file(filePath2)
1220-
const bunFile3 = Bun.file(filePath3)
1221-
1222-
const file1 = new File([await bunFile1.arrayBuffer()], 'cumin.webp', {
1223-
type: 'image/webp'
1224-
})
1225-
const file2 = new File([await bunFile2.arrayBuffer()], 'curcuma.jpg', {
1226-
type: 'image/jpeg'
1227-
})
1228-
const file3 = new File([await bunFile3.arrayBuffer()], 'kyuukurarin.mp4', {
1229-
type: 'video/mp4'
1230-
})
1231-
1232-
const filesForm = new FormData()
1233-
filesForm.append('files', file1)
1234-
filesForm.append('files', file2)
1235-
filesForm.append('files', file3)
1236-
1237-
const bunFilesForm = new FormData()
1238-
bunFilesForm.append('files', bunFile1)
1239-
bunFilesForm.append('files', bunFile2)
1240-
bunFilesForm.append('files', bunFile3)
1241-
1242-
it('accept a single Bun.file', async () => {
1243-
const { data: files } = await client.files.post({
1244-
files: bunFile1 as unknown as File[]
1245-
})
1246-
1247-
expect(files).not.toBeNull()
1248-
expect(files).not.toBeUndefined()
1249-
expect(files).toEqual([bunFile1.name!])
1250-
1251-
const { data: filesbis } = await client.files.post({
1252-
files: [bunFile1] as unknown as File[]
1253-
})
1254-
1255-
expect(filesbis).not.toBeNull()
1256-
expect(filesbis).not.toBeUndefined()
1257-
expect(filesbis).toEqual([bunFile1.name!])
1258-
1259-
const { data: file } = await client.file.post({
1260-
file: bunFile1 as unknown as File
1261-
})
1262-
1263-
expect(file).not.toBeNull()
1264-
expect(file).not.toBeUndefined()
1265-
expect(file).toEqual(bunFile1.name!)
1266-
})
1267-
1268-
it('accept a single regular file', async () => {
1269-
const { data: files } = await client.files.post({
1270-
files: file1 as unknown as File[]
1271-
})
1272-
1273-
expect(files).not.toBeNull()
1274-
expect(files).not.toBeUndefined()
1275-
expect(files).toEqual([file1.name!])
1276-
1277-
const { data: filesbis } = await client.files.post({
1278-
files: [file1] as unknown as File[]
1279-
})
1280-
1281-
expect(filesbis).not.toBeNull()
1282-
expect(filesbis).not.toBeUndefined()
1283-
expect(filesbis).toEqual([file1.name!])
1284-
1285-
const { data: file } = await client.file.post({
1286-
file: file1 as unknown as File
1287-
})
1288-
1289-
expect(file).not.toBeNull()
1290-
expect(file).not.toBeUndefined()
1291-
expect(file).toEqual(file1.name!)
1292-
})
1293-
1294-
it('accept an array of multiple Bun.file', async () => {
1295-
const { data: files } = await client.files.post({
1296-
files: [bunFile1, bunFile2, bunFile3] as unknown as File[]
1297-
})
1298-
1299-
expect(files).not.toBeNull()
1300-
expect(files).not.toBeUndefined()
1301-
expect(files).toEqual([bunFile1.name!, bunFile2.name!, bunFile3.name!])
1302-
1303-
const { data: filesbis } = await client.files.post({
1304-
files: bunFilesForm.getAll('files') as unknown as File[]
1305-
})
1306-
1307-
expect(filesbis).not.toBeNull()
1308-
expect(filesbis).not.toBeUndefined()
1309-
expect(filesbis).toEqual([
1310-
bunFile1.name!,
1311-
bunFile2.name!,
1312-
bunFile3.name!
1313-
])
1314-
})
1315-
1316-
it('accept an array of multiple regular file', async () => {
1317-
const { data: files } = await client.files.post({
1318-
files: [file1, file2, file3] as unknown as File[]
1319-
})
1320-
1321-
expect(files).not.toBeNull()
1322-
expect(files).not.toBeUndefined()
1323-
expect(files).toEqual([file1.name!, file2.name!, file3.name!])
1324-
1325-
const { data: filesbis } = await client.files.post({
1326-
files: filesForm.getAll('files') as unknown as File[]
1327-
})
1328-
1329-
expect(filesbis).not.toBeNull()
1330-
expect(filesbis).not.toBeUndefined()
1331-
expect(filesbis).toEqual([file1.name!, file2.name!, file3.name!])
1332-
})
13331211

13341212
it('handle root dynamic parameter', async () => {
13351213
const app = new Elysia().get('/:id', ({ params: { id } }) => id, {

0 commit comments

Comments
 (0)