Skip to content

chore(NODE-6939): update typescript to 5.8.3 #4526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
"socks": "^2.8.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.2",
"tsd": "^0.31.2",
"typescript": "5.5",
"tsd": "^0.32.0",
"typescript": "5.8.3",
"typescript-cached-transpile": "^0.0.6",
"v8-heapsnapshot": "^1.3.1",
"yargs": "^17.7.2"
Expand Down
8 changes: 3 additions & 5 deletions src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,16 +894,14 @@ export abstract class BulkOperationBase {
/** @internal */
s: BulkOperationPrivate;
operationId?: number;
private collection: Collection;

/**
* Create a new OrderedBulkOperation or UnorderedBulkOperation instance
* @internal
*/
constructor(
private collection: Collection,
options: BulkWriteOptions,
isOrdered: boolean
) {
constructor(collection: Collection, options: BulkWriteOptions, isOrdered: boolean) {
this.collection = collection;
// determine whether bulkOperation is ordered or unordered
this.isOrdered = isOrdered;

Expand Down
11 changes: 7 additions & 4 deletions src/client-side-encryption/state_machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,13 @@ export type StateMachineOptions = {
*/
// TODO(DRIVERS-2671): clarify CSOT behavior for FLE APIs
export class StateMachine {
constructor(
private options: StateMachineOptions,
private bsonOptions = pluckBSONSerializeOptions(options)
) {}
private options: StateMachineOptions;
private bsonOptions: BSONSerializeOptions;

constructor(options: StateMachineOptions, bsonOptions = pluckBSONSerializeOptions(options)) {
this.options = options;
this.bsonOptions = bsonOptions;
}

/**
* Executes the state machine according to the specification
Expand Down
47 changes: 31 additions & 16 deletions src/cmap/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ export class OpQueryRequest {
partial: boolean;
/** moreToCome is an OP_MSG only concept */
moreToCome = false;
databaseName: string;
query: Document;

constructor(
public databaseName: string,
public query: Document,
options: OpQueryOptions
) {
constructor(databaseName: string, query: Document, options: OpQueryOptions) {
// Basic options needed to be passed in
// TODO(NODE-3483): Replace with MongoCommandError
const ns = `${databaseName}.$cmd`;
Expand All @@ -97,7 +95,9 @@ export class OpQueryRequest {
throw new MongoRuntimeError('Namespace cannot contain a null character');
}

// Basic options
// Basic optionsa
this.databaseName = databaseName;
this.query = query;
this.ns = ns;

// Additional options
Expand Down Expand Up @@ -496,17 +496,18 @@ export class OpMsgRequest {
checksumPresent: boolean;
moreToCome: boolean;
exhaustAllowed: boolean;
databaseName: string;
command: Document;
options: OpQueryOptions;

constructor(
public databaseName: string,
public command: Document,
public options: OpQueryOptions
) {
constructor(databaseName: string, command: Document, options: OpQueryOptions) {
// Basic options needed to be passed in
if (command == null)
throw new MongoInvalidArgumentError('Query document must be specified for query');

// Basic options
// Basic optionsa
this.databaseName = databaseName;
this.command = command;
this.command.$db = databaseName;

// Ensure empty options
Expand Down Expand Up @@ -724,16 +725,30 @@ export class OpMsgResponse {
const MESSAGE_HEADER_SIZE = 16;
const COMPRESSION_DETAILS_SIZE = 9; // originalOpcode + uncompressedSize, compressorID

/**
* @internal
*/
export interface OpCompressesRequestOptions {
zlibCompressionLevel: number;
agreedCompressor: CompressorName;
}

/**
* @internal
*
* An OP_COMPRESSED request wraps either an OP_QUERY or OP_MSG message.
*/
export class OpCompressedRequest {
constructor(
private command: WriteProtocolMessageType,
private options: { zlibCompressionLevel: number; agreedCompressor: CompressorName }
) {}
private command: WriteProtocolMessageType;
private options: OpCompressesRequestOptions;

constructor(command: WriteProtocolMessageType, options: OpCompressesRequestOptions) {
this.command = command;
this.options = {
zlibCompressionLevel: options.zlibCompressionLevel,
agreedCompressor: options.agreedCompressor
};
}

// Return whether a command contains an uncompressible command term
// Will return true if command contains no uncompressible command terms
Expand Down
6 changes: 5 additions & 1 deletion src/cmap/handshake/client_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export class LimitedSizeDocument {
private document = new Map();
/** BSON overhead: Int32 + Null byte */
private documentSize = 5;
constructor(private maxSize: number) {}
private maxSize: number;

constructor(maxSize: number) {
this.maxSize = maxSize;
}

/** Only adds key/value if the bsonByteLength is less than MAX_SIZE */
public ifItFitsItSits(key: string, value: Record<string, any> | string): boolean {
Expand Down
3 changes: 2 additions & 1 deletion src/cmap/wire_protocol/compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MongoDecompressionError, MongoInvalidArgumentError } from '../../error'
import {
type MessageHeader,
OpCompressedRequest,
type OpCompressesRequestOptions,
OpMsgResponse,
OpReply,
type WriteProtocolMessageType
Expand Down Expand Up @@ -60,7 +61,7 @@ function loadSnappy() {

// Facilitate compressing a message using an agreed compressor
export async function compress(
options: { zlibCompressionLevel: number; agreedCompressor: CompressorName },
options: OpCompressesRequestOptions,
dataToBeCompressed: Buffer
): Promise<Buffer> {
const zlibOptions = {} as zlib.ZlibOptions;
Expand Down
5 changes: 5 additions & 0 deletions src/cmap/wire_protocol/on_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export function onData(

[Symbol.asyncIterator]() {
return this;
},

// Note this should currently not be used, but is required by the AsyncGenerator interface.
async [Symbol.asyncDispose]() {
await closeHandler();
}
};

Expand Down
33 changes: 19 additions & 14 deletions src/cmap/wire_protocol/on_demand/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import {
toUTF8
} from '../../../bson';

// eslint-disable-next-line no-restricted-syntax
const enum BSONElementOffset {
type = 0,
nameOffset = 1,
nameLength = 2,
offset = 3,
length = 4
}
const BSONElementOffset = {
type: 0,
nameOffset: 1,
nameLength: 2,
offset: 3,
length: 4
} as const;

/** @internal */
export type JSTypeOf = {
Expand Down Expand Up @@ -67,17 +66,23 @@ export class OnDemandDocument {

/** All bson elements in this document */
private readonly elements: ReadonlyArray<BSONElement>;
/** BSON bytes, this document begins at offset */
protected readonly bson: Uint8Array;
/** The start of the document */
private readonly offset: number;
/** If this is an embedded document, indicates if this was a BSON array */
public readonly isArray: boolean;

constructor(
/** BSON bytes, this document begins at offset */
protected readonly bson: Uint8Array,
/** The start of the document */
private readonly offset = 0,
/** If this is an embedded document, indicates if this was a BSON array */
public readonly isArray = false,
bson: Uint8Array,
offset = 0,
isArray = false,
/** If elements was already calculated */
elements?: BSONElement[]
) {
this.bson = bson;
this.offset = offset;
this.isArray = isArray;
this.elements = elements ?? parseToElementsToArray(this.bson, offset);
}

Expand Down
16 changes: 8 additions & 8 deletions src/cmap/wire_protocol/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import {
type OnDemandDocumentDeserializeOptions
} from './on_demand/document';

// eslint-disable-next-line no-restricted-syntax
const enum BSONElementOffset {
type = 0,
nameOffset = 1,
nameLength = 2,
offset = 3,
length = 4
}
const BSONElementOffset = {
type: 0,
nameOffset: 1,
nameLength: 2,
offset: 3,
length: 4
} as const;

/**
* Accepts a BSON payload and checks for na "ok: 0" element.
* This utility is intended to prevent calling response class constructors
Expand Down
2 changes: 2 additions & 0 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ function setOption(
if (values[0] == null) {
break;
}
// The value should always be a string here, but since the array is typed as unknown
// there still needs to be an explicit cast.
// eslint-disable-next-line @typescript-eslint/no-base-to-string
mongoOptions[name] = String(values[0]);
break;
Expand Down
10 changes: 6 additions & 4 deletions src/cursor/abstract_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1213,11 +1213,13 @@ configureResourceManagement(AbstractCursor.prototype);
* All timeout behavior is exactly the same as the wrapped timeout context's.
*/
export class CursorTimeoutContext extends TimeoutContext {
constructor(
public timeoutContext: TimeoutContext,
public owner: symbol | AbstractCursor
) {
timeoutContext: TimeoutContext;
owner: symbol | AbstractCursor;

constructor(timeoutContext: TimeoutContext, owner: symbol | AbstractCursor) {
super();
this.timeoutContext = timeoutContext;
this.owner = owner;
}
override get serverSelectionTimeout(): Timeout | null {
return this.timeoutContext.serverSelectionTimeout;
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export type { TokenCache } from './cmap/auth/mongodb_oidc/token_cache';
export type {
MessageHeader,
OpCompressedRequest,
OpCompressesRequestOptions,
OpMsgOptions,
OpMsgRequest,
OpMsgResponse,
Expand Down
1 change: 1 addition & 0 deletions src/operations/distinct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class DistinctOperation extends CommandOperation<any[]> {

const result = await super.executeCommand(server, session, cmd, timeoutContext);

// @ts-expect-error: Explain always returns a document
return this.explain ? result : result.values;
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/operations/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ export interface RenameOptions extends CommandOperationOptions {

/** @internal */
export class RenameOperation extends CommandOperation<Document> {
constructor(
public collection: Collection,
public newName: string,
public override options: RenameOptions
) {
collection: Collection;
newName: string;
override options: RenameOptions;

constructor(collection: Collection, newName: string, options: RenameOptions) {
super(collection, options);
this.collection = collection;
this.newName = newName;
this.options = options;
this.ns = new MongoDBNamespace('admin', '$cmd');
}

Expand Down
Loading