Skip to content

Commit ecc19f2

Browse files
committed
pr feedback: undo test changes and remove ByteUtils
1 parent 45c9875 commit ecc19f2

4 files changed

Lines changed: 11 additions & 32 deletions

File tree

src/utils.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { clearTimeout, setTimeout } from 'timers';
99
import {
1010
allocateBuffer,
1111
allocateUnsafeBuffer,
12-
ByteUtils as BSONByteUtils,
12+
ByteUtils,
1313
deserialize,
1414
type Document,
1515
getInt32LE,
@@ -53,24 +53,6 @@ export type Callback<T = any> = (error?: AnyError, result?: T) => void;
5353

5454
export type AnyOptions = Document;
5555

56-
export const ByteUtils = {
57-
toLocalBufferType(this: void, buffer: Buffer | Uint8Array): Buffer {
58-
return BSONByteUtils.toLocalBufferType(buffer) as Buffer;
59-
},
60-
61-
equals(this: void, seqA: Uint8Array, seqB: Uint8Array) {
62-
return ByteUtils.toLocalBufferType(seqA).equals(seqB);
63-
},
64-
65-
compare(this: void, seqA: Uint8Array, seqB: Uint8Array) {
66-
return ByteUtils.toLocalBufferType(seqA).compare(seqB);
67-
},
68-
69-
toBase64(this: void, uint8array: Uint8Array) {
70-
return ByteUtils.toLocalBufferType(uint8array).toString('base64');
71-
}
72-
};
73-
7456
/**
7557
* Returns true if value is a Uint8Array or a Buffer
7658
* @param value - any value that may be a Uint8Array
@@ -1338,10 +1320,10 @@ export function decorateDecryptionResult(
13381320
): void {
13391321
if (isTopLevelDecorateCall) {
13401322
// The original value could have been either a JS object or a BSON buffer
1341-
if (BSONByteUtils.isUint8Array(original)) {
1323+
if (ByteUtils.isUint8Array(original)) {
13421324
original = deserialize(original);
13431325
}
1344-
if (BSONByteUtils.isUint8Array(decrypted)) {
1326+
if (ByteUtils.isUint8Array(decrypted)) {
13451327
throw new MongoRuntimeError('Expected result of decryption to be deserialized BSON object');
13461328
}
13471329
}

test/tools/runner/config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
TopologyType,
2020
type WriteConcernSettings
2121
} from '../../../src';
22-
import { ByteUtils } from '../../../src/bson';
2322
import { type CompressorName } from '../../../src/cmap/wire_protocol/compression';
2423
import { HostAddress } from '../../../src/utils';
2524
import { getEnvironmentalOptions } from '../utils';
@@ -494,7 +493,7 @@ export class TestConfiguration {
494493
// @ts-expect-error: toExtendedJSON internal on double but not on long
495494
return { number: new Double(value).toExtendedJSON() };
496495
}
497-
if (ByteUtils.isUint8Array(value))
496+
if (Buffer.isBuffer(value))
498497
return { [value.constructor.name]: Buffer.prototype.base64Slice.call(value) };
499498
if (value === undefined) return { undefined: 'key was set but equal to undefined' };
500499
return value;

test/unit/cmap/commands.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as BSON from 'bson';
22
import { expect } from 'chai';
33

4-
import { ByteUtils, readInt32LE } from '../../../src/bson';
54
import { DocumentSequence, OpMsgRequest, OpReply } from '../../../src/cmap/commands';
65

76
describe('commands', function () {
@@ -42,12 +41,12 @@ describe('commands', function () {
4241

4342
it('sets the length of the document sequence', function () {
4443
// Bytes starting at index 1 is a 4 byte length.
45-
expect(readInt32LE(buffers[3], 1)).to.equal(25);
44+
expect(buffers[3].readInt32LE(1)).to.equal(25);
4645
});
4746

4847
it('sets the name of the first field to be replaced', function () {
4948
// Bytes starting at index 5 is the field name.
50-
expect(ByteUtils.toUTF8(buffers[3], 5, 10, true)).to.equal('field');
49+
expect(buffers[3].toString('utf8', 5, 10)).to.equal('field');
5150
});
5251
});
5352

@@ -82,12 +81,12 @@ describe('commands', function () {
8281

8382
it('sets the length of the first document sequence', function () {
8483
// Bytes starting at index 1 is a 4 byte length.
85-
expect(readInt32LE(buffers[3], 1)).to.equal(28);
84+
expect(buffers[3].readInt32LE(1)).to.equal(28);
8685
});
8786

8887
it('sets the name of the first field to be replaced', function () {
8988
// Bytes starting at index 5 is the field name.
90-
expect(ByteUtils.toUTF8(buffers[3], 5, 13, true)).to.equal('fieldOne');
89+
expect(buffers[3].toString('utf8', 5, 13)).to.equal('fieldOne');
9190
});
9291

9392
it('sets the document sequence sections second type to 1', function () {
@@ -97,12 +96,12 @@ describe('commands', function () {
9796

9897
it('sets the length of the second document sequence', function () {
9998
// Bytes starting at index 1 is a 4 byte length.
100-
expect(readInt32LE(buffers[3], 30)).to.equal(28);
99+
expect(buffers[3].readInt32LE(30)).to.equal(28);
101100
});
102101

103102
it('sets the name of the second field to be replaced', function () {
104103
// Bytes starting at index 33 is the field name.
105-
expect(ByteUtils.toUTF8(buffers[3], 34, 42, true)).to.equal('fieldTwo');
104+
expect(buffers[3].toString('utf8', 34, 42)).to.equal('fieldTwo');
106105
});
107106
});
108107
});

test/unit/utils.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { setTimeout } from 'node:timers';
22

3-
import { ObjectId } from 'bson';
3+
import { ByteUtils, ObjectId } from 'bson';
44
import { expect } from 'chai';
55
import * as sinon from 'sinon';
66

@@ -10,7 +10,6 @@ import { decorateWithExplain, Explain } from '../../src/explain';
1010
import {
1111
abortable,
1212
BufferPool,
13-
ByteUtils,
1413
checkParentDomainMatch,
1514
compareObjectId,
1615
hasAtomicOperators,

0 commit comments

Comments
 (0)