-
Type: Sub-task
-
Resolution: Done
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
Acceptance Criteria
Create new connection class and introduce compress, decompress, and buffer response helpers. Add generic socket read, socket write, and socket readMany helpers and refactor.
Implementation Requirements
- Add compression helpers
- compressCommand(command: Uint8Array): Promise<Uint8Array>)
- decompressResponse(buffer: Uint8Array) : Promise<OpMsgResponse | OpQueryResponse>
- Add socket write helper
-
- write(command: Uint8Array): Promise<void>
- pushes a command into the socket's buffer and waits until a `drain` event has been emitted
- write(command: Uint8Array): Promise<void>
-
- Add wire protocol message buffer helper
- bufferReponse(socket) : AsyncGenerator<Uint8Array>
- Add socket read helpers
- read(socket): Promise<OpMsgResponse | OpQueryResponse>
- readMany(socket): AsyncGenerator<OpMsgResponse | OpQueryResponse>
- Create a copy of the connection class.
- This is done now primarily so that future PRs have an easy diff, once refactors are started on the connection.
Testing Requirements
- Add compression helpers
- compressCommand
- when compression is disabled, compress returns the raw buffer
- when compression is enabled, it returns a compressed command
- when compression is enabled but the command is not a compressible command, the uncompressed command is returned
- decompressResponse
- when the command is not OP_COMPRESSED, it returns the raw buffer
- when the command is OP_COMPRESSED, it returns a decompressed buffer
- compressCommand
- Add socket write helper
- when `drain` is not emitted, this function never resolves
- when the `drain` event is emitted, this function resolves
- Add wire protocol message buffer helper
- when an invalid message size is received from the socket, an error is thrown
- when a chunk is received but it is not a full message, no message is returned
- when a full message is received, a buffer is yielded to the consumer
- when multiple wire protocol messages are received, it yields multiple wire protocol messages
- Add socket read helpers
- read(socket)
- when a single wire protocol message is received, it returns the message
- when multiple wire protocol messages received, it only returns the first
- readMany(socket): AsyncGenerator<OpMsgResponse | OpQueryResponse>
- when a single message without moreToCome set is received, only one message is returned
- when multiple messages without moreToCome set are received, only one message is returned
- when multiple messages with moreToCome set are received, all messages are yielded
- no more messages are returned after a message with moreToCome unset is received
- read(socket)