Skip to content

Commit d078afd

Browse files
committed
🔧 fix: #1028 query array nuqs format in dynamic mode
1 parent dc44d08 commit d078afd

File tree

5 files changed

+111
-13
lines changed

5 files changed

+111
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.3.10 - 18 Aug 2025
2+
Bug fix:
3+
- [#1028](https://github.com/elysiajs/elysia/issues/1028) query array nuqs format in dynamic mode
4+
- unwrap t.Import in dynamic mode
5+
16
# 1.3.9 - 18 Aug 2025
27
Feature:
38
- [#932](https://github.com/elysiajs/elysia/issues/932) add `t.ArrayBuffer`, `t.Uint8Array`

example/a.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { Elysia, t } from '../src'
22

3-
new Elysia({ aot: false })
3+
const IdsModel = new Elysia().model({
4+
ids: t.Object({
5+
ids: t.Array(t.String())
6+
})
7+
})
8+
9+
const app = new Elysia({ aot: false })
10+
.use(IdsModel)
411
.get('/', ({ query }) => query, {
5-
query: t.Object({
6-
name: t.Array(t.String())
7-
})
12+
query: 'ids'
813
})
914
.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.3.9",
4+
"version": "1.3.10",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

src/dynamic-handle.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ const injectDefaultValues = (
3434
typeChecker: TypeCheck<any> | ElysiaTypeCheck<any>,
3535
obj: Record<string, any>
3636
) => {
37-
for (const [key, keySchema] of Object.entries(
38-
// @ts-expect-error private
39-
typeChecker.schema.properties
40-
)) {
37+
// @ts-expect-error private property
38+
let schema = typeChecker.schema
39+
if (!schema) return
40+
41+
if (schema.$defs?.[schema.$ref]) schema = schema.$defs[schema.$ref]
42+
43+
if (!schema?.properties) return
44+
45+
for (const [key, keySchema] of Object.entries(schema.properties)) {
4146
// @ts-expect-error private
4247
obj[key] ??= keySchema.default
4348
}
@@ -396,17 +401,20 @@ export const createDynamicHandler = (app: AnyElysia) => {
396401
context.params = validator.params.Decode(context.params)
397402

398403
if (validator.query?.schema) {
399-
const properties = validator.query?.schema.properties
404+
let schema = validator.query.schema
405+
if (schema.$defs?.[schema.$ref])
406+
schema = schema.$defs[schema.$ref]
407+
408+
const properties = schema.properties
400409

401410
for (const property of Object.keys(properties)) {
402411
const value = properties[property]
403412
if (
404413
(value.type === 'array' ||
405414
value.items?.type === 'string') &&
406415
typeof context.query[property] === 'string' &&
407-
context.query[property]?.includes(',')
416+
context.query[property]
408417
) {
409-
// If the query is an array of strings, we need to split it
410418
// @ts-ignore
411419
context.query[property] =
412420
context.query[property].split(',')

test/core/dynamic.test.ts

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,43 @@ describe('Dynamic Mode', () => {
640640
})
641641
})
642642

643-
it('handle query array', async () => {
643+
it('handle single query array', async () => {
644+
const app = new Elysia({ aot: false }).get('/', ({ query }) => query, {
645+
query: t.Object({
646+
name: t.String(),
647+
names: t.Array(t.String())
648+
})
649+
})
650+
651+
const data = await app
652+
.handle(req('/?name=neon&names=rapi'))
653+
.then((x) => x.json())
654+
655+
expect(data).toEqual({
656+
name: 'neon',
657+
names: ['rapi']
658+
})
659+
})
660+
661+
it('handle multiple query array in nuqs format', async () => {
662+
const app = new Elysia({ aot: false }).get('/', ({ query }) => query, {
663+
query: t.Object({
664+
name: t.String(),
665+
names: t.Array(t.String())
666+
})
667+
})
668+
669+
const data = await app
670+
.handle(req('/?name=neon&names=rapi,anis'))
671+
.then((x) => x.json())
672+
673+
expect(data).toEqual({
674+
name: 'neon',
675+
names: ['rapi', 'anis']
676+
})
677+
})
678+
679+
it('handle multiple query array in nuqs format', async () => {
644680
const app = new Elysia({ aot: false }).get('/', ({ query }) => query, {
645681
query: t.Object({
646682
name: t.String(),
@@ -657,4 +693,48 @@ describe('Dynamic Mode', () => {
657693
names: ['rapi', 'anis']
658694
})
659695
})
696+
697+
it('handle query array reference in multiple reference format', async () => {
698+
const IdsModel = new Elysia().model({
699+
name: t.Object({
700+
name: t.Array(t.String())
701+
})
702+
})
703+
704+
const app = new Elysia({ aot: false })
705+
.use(IdsModel)
706+
.get('/', ({ query }) => query, {
707+
name: 'ids'
708+
})
709+
710+
const data = await app
711+
.handle(req('/?names=rapi&names=anis'))
712+
.then((x) => x.json())
713+
714+
expect(data).toEqual({
715+
names: ['rapi', 'anis']
716+
})
717+
})
718+
719+
it('handle query array reference in multiple reference format', async () => {
720+
const IdsModel = new Elysia().model({
721+
name: t.Object({
722+
name: t.Array(t.String())
723+
})
724+
})
725+
726+
const app = new Elysia({ aot: false })
727+
.use(IdsModel)
728+
.get('/', ({ query }) => query, {
729+
name: 'ids'
730+
})
731+
732+
const data = await app
733+
.handle(req('/?names=rapi&names=anis'))
734+
.then((x) => x.json())
735+
736+
expect(data).toEqual({
737+
names: ['rapi', 'anis']
738+
})
739+
})
660740
})

0 commit comments

Comments
 (0)