Skip to content

Commit

Permalink
fix: use utf8 instead of utf-8 for ws messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cameri committed Nov 12, 2022
1 parent 4b58bc7 commit 4dc2405
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/adapters/web-socket-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class WebSocketAdapter extends EventEmitter implements IWebSocketAdapter
private async onClientMessage(raw: Buffer) {
let abort: () => void
try {
const message = attemptValidation(messageSchema)(JSON.parse(raw.toString('utf-8')))
const message = attemptValidation(messageSchema)(JSON.parse(raw.toString('utf8')))

const messageHandler = this.createMessageHandler([message, this]) as IMessageHandler & IAbortable
if (typeof messageHandler.abort === 'function') {
Expand Down
1 change: 1 addition & 0 deletions src/factories/worker-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const workerFactory = (): AppWorker => {
const dbClient = getDbClient()
const eventRepository = new EventRepository(dbClient)

// deepcode ignore HttpToHttps: <please specify a reason of ignoring this>
const server = http.createServer()
const webSocketServer = new WebSocketServer({
server,
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/event-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class EventRepository implements IEventRepository {
}

public async create(event: Event): Promise<number> {
return this.insert(event).then(prop('rowCount') as () => number)
return this.insert(event).then(prop('rowCount') as () => number, () => 0)
}

private insert(event: Event) {
Expand Down
8 changes: 4 additions & 4 deletions test/integration/features/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export async function waitForEOSE(ws: WebSocket, subscription: string): Promise<
ws.once('error', onError)

function onMessage(raw: RawData) {
const message = JSON.parse(raw.toString('utf-8'))
const message = JSON.parse(raw.toString('utf8'))
if (message[0] === MessageType.EOSE && message[1] === subscription) {
resolve()
cleanup()
Expand Down Expand Up @@ -139,7 +139,7 @@ export async function waitForNextEvent(ws: WebSocket, subscription: string): Pro
}

function onMessage(raw: RawData) {
const message = JSON.parse(raw.toString('utf-8'))
const message = JSON.parse(raw.toString('utf8'))
if (message[0] === MessageType.EVENT && message[1] === subscription) {
resolve(message[2])
cleanup()
Expand Down Expand Up @@ -172,7 +172,7 @@ export async function waitForEventCount(
cleanup()
}
function onMessage(raw: RawData) {
const message = JSON.parse(raw.toString('utf-8'))
const message = JSON.parse(raw.toString('utf8'))
if (message[0] === MessageType.EVENT && message[1] === subscription) {
events.push(message[2])
if (!eose && events.length === count) {
Expand Down Expand Up @@ -213,7 +213,7 @@ export async function waitForNotice(ws: WebSocket): Promise<void> {
ws.once('error', onError)

function onMessage(raw: RawData) {
const message = JSON.parse(raw.toString('utf-8'))
const message = JSON.parse(raw.toString('utf8'))
if (message[0] === MessageType.NOTICE) {
resolve(message[1])
cleanup()
Expand Down
2 changes: 1 addition & 1 deletion test/unit/factories/websocket-adapter-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('webSocketAdapterFactory', () => {
onStub.returns(client)
const request: IncomingMessage = {
headers: {
'sec-websocket-key': Buffer.from('key', 'utf-8').toString('base64'),
'sec-websocket-key': Buffer.from('key', 'utf8').toString('base64'),
},
} as any
const webSocketServerAdapter: IWebSocketServerAdapter = {} as any
Expand Down

0 comments on commit 4dc2405

Please sign in to comment.