Skip to content

Commit c522d67

Browse files
committed
🔧 fix: exact mirror normalize doesn't apply correctly
1 parent d1eee9c commit c522d67

File tree

8 files changed

+50
-37
lines changed

8 files changed

+50
-37
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
# 1.3.13 - 18 Aug 2025
2+
Bug fix:
3+
- important performance degration, exact mirror normalize doesn't apply correctly
4+
- normalize optional property with special character
5+
6+
Change:
7+
- update `exact-mirror` to `0.1.6`
8+
19
# 1.3.12 - 19 Aug 2025
210
Bug fix:
3-
- [#1348](https://github.com/elysiajs/elysia/issues/1348) onAfterResponse runs twice if NotFoundError thrown and onError provided
11+
- [#1348](https://github.com/elysiajs/elysia/issues/1348) onAfterResponse runs twice if NotFoundError thrown and onError provided
412

513
# 1.3.11 - 18 Aug 2025
614
Bug fix:
7-
- [#1346](https://github.com/elysiajs/elysia/issues/1346) cannot declare 'mep' twice
15+
- [#1346](https://github.com/elysiajs/elysia/issues/1346) cannot declare 'mep' twice
816

917
# 1.3.10 - 18 Aug 2025
1018
Bug fix:

bun.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "elysia",
66
"dependencies": {
77
"cookie": "^1.0.2",
8-
"exact-mirror": "^0.1.5",
8+
"exact-mirror": "^0.1.6",
99
"fast-decode-uri-component": "^1.0.1",
1010
},
1111
"devDependencies": {
@@ -31,7 +31,7 @@
3131
},
3232
"peerDependencies": {
3333
"@sinclair/typebox": ">= 0.34.0",
34-
"exact-mirror": "^0.1.3",
34+
"exact-mirror": ">= 0.0.9",
3535
"file-type": ">= 20.0.0",
3636
"openapi-types": ">= 12.0.0",
3737
"typescript": ">= 5.0.0",
@@ -363,7 +363,7 @@
363363

364364
"eventsource-parser": ["[email protected]", "", {}, "sha512-VARTJ9CYeuQYb0pZEPbzi740OWFgpHe7AYJ2WFZVnUDUQp5Dk2yJUgF36YsZ81cOyxT0QxmXD2EQpapAouzWVA=="],
365365

366-
"exact-mirror": ["[email protected].5", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-NKLenPSYjWPoj2+IL3+NSXDTfddZMBAclnLPPZCEtWcSZYOVlKwedNpCCVQkdyIo6UYAMTiLd4wgtuQMPs4C/A=="],
366+
"exact-mirror": ["[email protected].6", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-EXGDixoDotCGrXCce63zmGHDA+3Id6PPkIwshBHuB10dwVc4YV4gfaYLuysHOxyURmwyt4UL186ann0oYa2CFQ=="],
367367

368368
"expect-type": ["[email protected]", "", {}, "sha512-/kP8CAwxzLVEeFrMm4kMmy4CCDlpipyA7MYLVrdJIkV0fYF0UaigQHRsxHiuY/GEea+bh4KSv3TIlgr+2UL6bw=="],
369369

example/a.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import { Elysia, t } from '../src'
22
import { req } from '../test/utils'
33

4-
let isAfterResponseCalled = false
5-
6-
const app = new Elysia({ precompile: true })
7-
.onAfterResponse(() => {
8-
isAfterResponseCalled = true
4+
const app = new Elysia().get('/', ({ headers }) => typeof headers['is-admin'], {
5+
headers: t.Object({
6+
'is-admin': t.Union([
7+
t.Boolean(),
8+
t.String({
9+
format: 'boolean'
10+
})
11+
])
912
})
10-
.onError(() => {
11-
return new Response('a', {
12-
status: 401,
13+
})
14+
15+
const value = await app
16+
.handle(
17+
req('/', {
1318
headers: {
14-
awd: 'b'
19+
'is-admin': 'true'
1520
}
1621
})
17-
})
18-
.compile()
19-
20-
// console.log(app.handleError.toString())
21-
22-
await app.handle(req('/'))
23-
// wait for next tick
24-
await Bun.sleep(1)
25-
26-
console.log(isAfterResponseCalled)
22+
)
23+
.then((x) => x.text())

package.json

Lines changed: 2 additions & 2 deletions
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.12",
4+
"version": "1.3.13",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",
@@ -184,7 +184,7 @@
184184
},
185185
"dependencies": {
186186
"cookie": "^1.0.2",
187-
"exact-mirror": "^0.1.5",
187+
"exact-mirror": "^0.1.6",
188188
"fast-decode-uri-component": "^1.0.1"
189189
},
190190
"devDependencies": {

src/compose.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,7 @@ export const composeHandler = ({
15641564
defaultConfig: app.config.cookie,
15651565
dynamic: !!app.config.aot,
15661566
config: validator.cookie?.config ?? {},
1567+
normalize: app.config.normalize,
15671568
// @ts-expect-error
15681569
models: app.definitions.type
15691570
})!

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ export default class Elysia<
605605
modules,
606606
validator: cloned.cookie,
607607
defaultConfig: this.config.cookie,
608+
normalize,
608609
config: cloned.cookie?.config ?? {},
609610
dynamic,
610611
models,
@@ -699,6 +700,7 @@ export default class Elysia<
699700
modules,
700701
dynamic,
701702
models,
703+
normalize,
702704
additionalProperties: !normalize,
703705
coerce: true,
704706
additionalCoerce:
@@ -719,6 +721,7 @@ export default class Elysia<
719721
modules,
720722
dynamic,
721723
models,
724+
normalize,
722725
coerce: true,
723726
additionalCoerce:
724727
stringToStructureCoercions(),
@@ -738,6 +741,7 @@ export default class Elysia<
738741
modules,
739742
dynamic,
740743
models,
744+
normalize,
741745
coerce: true,
742746
additionalCoerce:
743747
stringToStructureCoercions(),

src/schema.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,13 @@ export const getSchemaValidator = <T extends TSchema | string | undefined>(
974974
console.warn(
975975
'Failed to create exactMirror. Please report the following code to https://github.com/elysiajs/elysia/issues'
976976
)
977-
console.warn(schema)
977+
console.dir(schema, {
978+
depth: null
979+
})
978980

979981
compiled.Clean = createCleaner(schema)
980982
}
981-
} else compiled.Clean = createCleaner(schema)
983+
} else if (normalize === 'typebox') compiled.Clean = createCleaner(schema)
982984

983985
compiled.parse = (v) => {
984986
try {
@@ -1277,6 +1279,7 @@ export const getCookieValidator = ({
12771279
defaultConfig = {},
12781280
config,
12791281
dynamic,
1282+
normalize = false,
12801283
models,
12811284
validators,
12821285
sanitize
@@ -1286,6 +1289,7 @@ export const getCookieValidator = ({
12861289
defaultConfig: CookieOptions | undefined
12871290
config: CookieOptions
12881291
dynamic: boolean
1292+
normalize: ElysiaConfig<''>['normalize'] | undefined
12891293
models: Record<string, TSchema> | undefined
12901294
validators?: InputSchema['cookie'][]
12911295
sanitize?: () => ExactMirrorInstruction['sanitize']
@@ -1294,6 +1298,7 @@ export const getCookieValidator = ({
12941298
modules,
12951299
dynamic,
12961300
models,
1301+
normalize,
12971302
additionalProperties: true,
12981303
coerce: true,
12991304
additionalCoerce: stringToStructureCoercions(),

test/validator/header.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,13 @@ describe('Header Validator', () => {
232232
'/',
233233
({ headers }) => headers?.name ?? 'sucrose',
234234
{
235-
headers: t.Optional(
236-
t.Object(
237-
{
238-
name: t.String()
239-
},
240-
{
241-
additionalProperties: true
242-
}
243-
)
235+
headers: t.Object(
236+
{
237+
name: t.Optional(t.String())
238+
},
239+
{
240+
additionalProperties: true
241+
}
244242
)
245243
}
246244
)

0 commit comments

Comments
 (0)