Skip to content

Commit 0632bf7

Browse files
authored
Merge pull request #115 from adarshaacharya/bugfix/encode-params
Stringify query params to allow the nested object
2 parents b7a7c9d + b8bd111 commit 0632bf7

File tree

8 files changed

+52
-12
lines changed

8 files changed

+52
-12
lines changed

bun.lockb

0 Bytes
Binary file not shown.

example/client/bun.lockb

119 KB
Binary file not shown.

example/client/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import './style.css'
33
// import './fetch'
44
// import './fn'
55
import './treaty'
6-
import './treaty-file'
6+
// import './treaty-file'

example/client/src/treaty-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference lib="dom" />
22
/// <reference lib="dom.iterable" />
3-
import { edenTreaty } from '@elysia/eden'
3+
import { edenTreaty } from '../../../src/treaty'
44
import type { Server } from '../../server.js'
55

66
export const client = edenTreaty<Server>('http://localhost:8080')

example/client/src/treaty.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import { edenTreaty, EdenTreaty } from '../../../src/treaty'
1+
import { treaty, Treaty } from '../../../src/treaty2'
22
import type { Server } from '../../server'
33

4-
export const client = edenTreaty<Server>('http://localhost:8080')
4+
export const client = treaty<Server>('http://localhost:8080')
55

66
const { data } = await client.products.nendoroid.skadi.get({
7-
$query: {
8-
username: 'A'
7+
query: {
8+
username: 'A',
9+
filter: {
10+
name: 'A',
11+
address: 'A',
12+
age: 'A'
13+
}
914
}
1015
})
1116

17+
await client['sign-in'].get()
18+
1219
// const data = await client.products.nendoroid.skadi.post({
1320
// username: 'A'
1421
// })

example/server.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,33 @@ const app = new Elysia()
6464
})
6565
})
6666
.get('/sign-in', () => 'ok')
67-
.get('/products/nendoroid/skadi', () => 1, {
68-
query: t.Object({
69-
username: t.String()
70-
})
71-
})
67+
.get(
68+
'/products/nendoroid/skadi',
69+
({ query }) => {
70+
console.log({ query })
71+
return query
72+
},
73+
{
74+
query: t.Object({
75+
username: t.String(),
76+
filter: t.Object({
77+
name: t.Optional(t.String()),
78+
address: t.Optional(t.String()),
79+
age: t.Optional(t.String())
80+
})
81+
}),
82+
response: {
83+
200: t.Object({
84+
username: t.String(),
85+
filter: t.Object({
86+
name: t.Optional(t.String()),
87+
address: t.Optional(t.String()),
88+
age: t.Optional(t.String())
89+
})
90+
})
91+
}
92+
}
93+
)
7294
.post('/products/nendoroid/skadi', () => 1, {
7395
body: t.Object({
7496
username: t.String()

example/treaty.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ const eden = treaty<Server>('http://localhost:8080')
55

66
const a = await eden.products.nendoroid.skadi.get({
77
query: {
8-
username: 'a'
8+
username: 'a',
9+
filter: {
10+
name: 'b',
11+
address: 'c',
12+
age: '10'
13+
}
914
}
1015
})
1116

src/treaty2/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ const createProxy = (
196196
continue
197197
}
198198

199+
if (typeof value === 'object') {
200+
append(key, JSON.stringify(value))
201+
continue
202+
}
203+
204+
199205
append(key, `${value}`)
200206
}
201207
}

0 commit comments

Comments
 (0)