Skip to content

Commit

Permalink
🔧 fix: type
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Dec 4, 2024
1 parent 1a3ecad commit f84e678
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
20 changes: 17 additions & 3 deletions src/adapter/web-standard/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,20 @@ const handleStream = async (
if (typeof init.value === 'object')
try {
controller.enqueue(
// @ts-expect-error this is a valid operation
Buffer.from(JSON.stringify(init.value))
)
} catch {
controller.enqueue(
// @ts-expect-error this is a valid operation
Buffer.from(init.value.toString())
)
}
else controller.enqueue(Buffer.from(init.value.toString()))
else
controller.enqueue(
// @ts-expect-error this is a valid operation
Buffer.from(init.value.toString())
)
}

for await (const chunk of generator) {
Expand All @@ -141,12 +147,20 @@ const handleStream = async (
if (typeof chunk === 'object')
try {
controller.enqueue(
// @ts-expect-error this is a valid operation
Buffer.from(JSON.stringify(chunk))
)
} catch {
controller.enqueue(Buffer.from(chunk.toString()))
controller.enqueue(
// @ts-expect-error this is a valid operation
Buffer.from(chunk.toString())
)
}
else controller.enqueue(Buffer.from(chunk.toString()))
else
controller.enqueue(
// @ts-expect-error this is a valid operation
Buffer.from(chunk.toString())
)

// Wait for the next event loop
// Otherwise the data will be mixed up
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5515,8 +5515,9 @@ export default class Elysia<
if (!(key in this.definitions.type))
this.definitions.type[key] = value as TSchema
})
// @ts-expect-error
this.definitions.typebox = t.Module({
...this.definitions.typebox['$defs'],
...this.definitions.typebox['$defs'] as TModule<{}>,
...name
} as any)

Expand Down
2 changes: 1 addition & 1 deletion src/ws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export const createHandleWSResponse = (
if (data instanceof Promise)
return data.then((data) => handleWSResponse(ws, data))

if (Buffer.isBuffer(data)) return ws.send(data)
if (Buffer.isBuffer(data)) return ws.send(data.toString())

if (data === undefined) return

Expand Down

0 comments on commit f84e678

Please sign in to comment.