Skip to content

Commit 51e7f2f

Browse files
committed
🔧 fix: wsRouter
1 parent 55c92b7 commit 51e7f2f

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Improvement:
1515
- add test case for all life-cycle
1616
- resolve, mapResolve, derive, mapDerive use ephemeral type to scope down accurately
1717
- inference query dynamic variable
18+
- Fine-grained reactive cookie
19+
- Using single source of truth for cookie
1820

1921
Breaking Change:
2022
- Lifecycle is now local first

example/a.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ import { Elysia, t } from '../src'
22
import { cors } from '../../cors/src'
33

44
const app = new Elysia({ precompile: true })
5-
.post('/', ({ body, cookie: { session } }) => {
6-
session!.value = 'hi'
7-
8-
return body
5+
.ws('/ws', {
6+
open(ws) {
7+
ws.send('Hi')
8+
}
9+
})
10+
.ws('/ws/:id', {
11+
open(ws) {
12+
ws.send('Hi')
13+
},
14+
message(ws, data) {
15+
ws.send(data)
16+
}
917
})
1018
.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.0.0-rc.15",
4+
"version": "1.0.0-rc.16",
55
"author": {
66
"name": "saltyAom",
77
"url": "https://github.com/SaltyAom",

src/compose.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ export const composeGeneralHandler = (
14191419
14201420
const store = app.singleton.store
14211421
const staticRouter = app.router.static.http
1422-
const wsRouter = app.router.static.ws
1422+
const wsRouter = app.router.ws
14231423
const router = app.router.http
14241424
14251425
const notFound = new NotFoundError()

src/error.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class ValidationError extends Error {
117117
: error.schema.error
118118
: undefined
119119

120-
const accessor = error?.path?.slice(1) || 'root'
120+
const accessor = error?.path || 'root'
121121
let message = ''
122122

123123
if (customError) {
@@ -127,8 +127,10 @@ export class ValidationError extends Error {
127127
: customError + ''
128128
} else if (isProduction) {
129129
message = JSON.stringify({
130-
type,
131-
message: error?.message
130+
type: "validation",
131+
on: type,
132+
message: error?.message,
133+
found: value
132134
})
133135
} else {
134136
// @ts-ignore private field
@@ -138,12 +140,26 @@ export class ValidationError extends Error {
138140
? [...validator.Errors(value)]
139141
: [...Value.Errors(validator, value)]
140142

143+
let expected
144+
145+
try {
146+
expected = Value.Create(schema)
147+
} catch (error) {
148+
expected = {
149+
type: 'Could not create expected value',
150+
// @ts-expect-error
151+
message: error?.message,
152+
error
153+
}
154+
}
155+
141156
message = JSON.stringify(
142157
{
143-
type,
144-
at: accessor,
158+
type: "validation",
159+
on: type,
160+
property: accessor,
145161
message: error?.message,
146-
expected: Value.Create(schema),
162+
expected,
147163
found: value,
148164
errors
149165
},

test/types/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,3 +1157,11 @@ app.resolve(({ headers }) => {
11571157
418: 'Nagisa'
11581158
}>()
11591159
}
1160+
1161+
app.get('/', ({ set }) => {
1162+
// ? Able to set literal type to set.status
1163+
set.status = 'I\'m a teapot'
1164+
1165+
// ? Able to number to set.status
1166+
set.status = 418
1167+
})

0 commit comments

Comments
 (0)