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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ tasks:
type: setup
params:
updates:
- {key: NODE_LTS_VERSION, value: '16'}
- {key: NODE_LTS_VERSION, value: '22'}
- {key: NPM_VERSION, value: '9'}
- func: install dependencies
- func: run lint checks
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/generate_evergreen_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ SINGLETON_TASKS.push(
tags: ['lint-checks'],
commands: [
updateExpansions({
NODE_LTS_VERSION: LOWEST_LTS,
NODE_LTS_VERSION: LATEST_LTS,
NPM_VERSION: 9
}),
{ func: 'install dependencies' },
Expand Down
233 changes: 118 additions & 115 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@aws-sdk/credential-providers": "^3.632.0",
"@iarna/toml": "^2.2.5",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@microsoft/api-extractor": "^7.49.2",
"@microsoft/api-extractor": "^7.52.5",
"@microsoft/tsdoc-config": "^0.17.1",
"@mongodb-js/zstd": "^2.0.0",
"@types/chai": "^4.3.17",
Expand All @@ -79,8 +79,8 @@
"@types/sinon": "^17.0.3",
"@types/sinon-chai": "^3.2.12",
"@types/whatwg-url": "^11.0.5",
"@typescript-eslint/eslint-plugin": "8.4.0",
"@typescript-eslint/parser": "8.4.0",
"@typescript-eslint/eslint-plugin": "8.31.1",
"@typescript-eslint/parser": "8.31.1",
"chai": "^4.4.1",
"chai-subset": "^1.6.0",
"chalk": "^4.1.2",
Expand All @@ -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
13 changes: 8 additions & 5 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 Expand Up @@ -275,7 +278,7 @@ export class StateMachine {
// See docs on EMPTY_V
result = EMPTY_V ??= serialize({ v: [] });
}
for await (const key of keys) {
for (const key of keys) {
context.addMongoOperationResponse(serialize(key));
}

Expand Down
48 changes: 32 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 @@ -730,10 +731,19 @@ const COMPRESSION_DETAILS_SIZE = 9; // originalOpcode + uncompressedSize, compre
* An OP_COMPRESSED request wraps either an OP_QUERY or OP_MSG message.
*/
export class OpCompressedRequest {
private command: WriteProtocolMessageType;
private options: { zLibCompressionLevel: number; agreedCompressor: CompressorName };

constructor(
private command: WriteProtocolMessageType,
private options: { zlibCompressionLevel: number; agreedCompressor: CompressorName }
) {}
command: WriteProtocolMessageType,
options: { zlibCompressionLevel: number; agreedCompressor: CompressorName }
) {
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 All @@ -752,7 +762,13 @@ export class OpCompressedRequest {
const originalCommandOpCode = concatenatedOriginalCommandBuffer.readInt32LE(12);

// Compress the message body
const compressedMessage = await compress(this.options, messageToBeCompressed);
const compressedMessage = await compress(
{
zlibCompressionLevel: this.options.zLibCompressionLevel,
agreedCompressor: this.options.agreedCompressor
},
messageToBeCompressed
);
// Create the msgHeader of OP_COMPRESSED
const msgHeader = Buffer.alloc(MESSAGE_HEADER_SIZE);
msgHeader.writeInt32LE(
Expand Down
2 changes: 1 addition & 1 deletion src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ export class CryptoConnection extends Connection {
ns: MongoDBNamespace,
cmd: Document,
options?: CommandOptions,
responseType?: T | undefined
responseType?: T
): Promise<Document> {
const { autoEncrypter } = this;
if (!autoEncrypter) {
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
35 changes: 20 additions & 15 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 Expand Up @@ -262,7 +267,7 @@ export class OnDemandDocument {
public get<const T extends keyof JSTypeOf>(
name: string | number,
as: T,
required?: boolean | undefined
required?: boolean
): JSTypeOf[T] | null;

/** `required` will make `get` throw if name does not exist or is null/undefined */
Expand Down
20 changes: 10 additions & 10 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 Expand Up @@ -77,7 +77,7 @@ export class MongoDBResponse extends OnDemandDocument {
public override get<const T extends keyof JSTypeOf>(
name: string | number,
as: T,
required?: false | undefined
required?: false
): JSTypeOf[T] | null;
public override get<const T extends keyof JSTypeOf>(
name: string | number,
Expand All @@ -87,7 +87,7 @@ export class MongoDBResponse extends OnDemandDocument {
public override get<const T extends keyof JSTypeOf>(
name: string | number,
as: T,
required?: boolean | undefined
required?: boolean
): JSTypeOf[T] | null {
try {
return super.get(name, as, required);
Expand Down
3 changes: 3 additions & 0 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ 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;
case 'record':
Expand Down
1 change: 0 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
export const SYSTEM_NAMESPACE_COLLECTION = 'system.namespaces';
export const SYSTEM_INDEX_COLLECTION = 'system.indexes';
export const SYSTEM_PROFILE_COLLECTION = 'system.profile';
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: 0 additions & 1 deletion src/operations/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { type CollationOptions, CommandOperation, type CommandOperationOptions }
import { Aspect, defineAspects, type Hint } from './operation';

/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
export const DB_AGGREGATE_COLLECTION = 1 as const;
const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8;

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