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 5 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
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
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 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private options: { zLibCompressionLevel: number; agreedCompressor: CompressorName };
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zLibCompressionLevel: options.zlibCompressionLevel,
zlibCompressionLevel: options.zlibCompressionLevel,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be some sort of test that catches this?

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
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
);
const compressedMessage = await compress(this.options, messageToBeCompressed);

// Create the msgHeader of OP_COMPRESSED
const msgHeader = Buffer.alloc(MESSAGE_HEADER_SIZE);
msgHeader.writeInt32LE(
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
4 changes: 4 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,10 @@ export function onData(

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

[Symbol.asyncDispose]: function (): PromiseLike<void> {
return closeHandler().then(() => undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return closeHandler().then(() => undefined);
async [Symbol.asyncDispose]() {
await closeHandler();

a suggestion: nothing wrong with async syntax here I think, just a bit simpler to drop the return value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also probably worth leaving a comment about how this shouldn't be used (I don't think it will but in case).

On older Node versions this is going to be:

{
    throw() {/*...*/} // ...
    async undefined() {

    }
}

But typescript isn't going to let you know, ideally a test would fail on node 16 but might as well leave a paper trail.

}
};

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/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
21 changes: 17 additions & 4 deletions src/operations/run_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ export type RunCommandOptions = {

/** @internal */
export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
command: Document;
override options: RunCommandOptions & { responseType?: MongoDBResponseConstructor };

constructor(
parent: Db,
public command: Document,
public override options: RunCommandOptions & { responseType?: MongoDBResponseConstructor }
command: Document,
options: RunCommandOptions & { responseType?: MongoDBResponseConstructor }
) {
super(options);
this.command = command;
this.options = options;
this.ns = parent.s.namespace.withCollection('$cmd');
}

Expand Down Expand Up @@ -62,14 +67,22 @@ export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
}

export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T> {
command: Document;
override options: RunCommandOptions & {
noResponse?: boolean;
bypassPinningCheck?: boolean;
};

constructor(
public command: Document,
public override options: RunCommandOptions & {
command: Document,
options: RunCommandOptions & {
noResponse?: boolean;
bypassPinningCheck?: boolean;
}
) {
super(options);
this.command = command;
this.options = options;
this.ns = new MongoDBNamespace('admin', '$cmd');
}

Expand Down
Loading