diff --git a/.evergreen/config.yml b/.evergreen/config.yml index ff30804760c..c0190ad1ecb 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -1860,17 +1860,6 @@ tasks: - {key: NODE_LTS_VERSION, value: '22'} - func: install dependencies - func: run lint checks - - name: run-resource-management-async-dispose - tags: - - resource-management - commands: - - command: expansions.update - type: setup - params: - updates: - - {key: NODE_LTS_VERSION, value: '22'} - - func: install dependencies - - func: check resource management - name: test-explicit-resource-management-feature-integration tags: - resource-management diff --git a/.evergreen/generate_evergreen_tasks.js b/.evergreen/generate_evergreen_tasks.js index c7f761daa6d..53312f2cd37 100644 --- a/.evergreen/generate_evergreen_tasks.js +++ b/.evergreen/generate_evergreen_tasks.js @@ -510,17 +510,6 @@ SINGLETON_TASKS.push( { func: 'run lint checks' } ] }, - { - name: 'run-resource-management-async-dispose', - tags: ['resource-management'], - commands: [ - updateExpansions({ - NODE_LTS_VERSION: LATEST_LTS - }), - { func: 'install dependencies' }, - { func: 'check resource management' } - ] - }, { name: 'test-explicit-resource-management-feature-integration', tags: ['resource-management'], diff --git a/.evergreen/run-resource-management.sh b/.evergreen/run-resource-management.sh deleted file mode 100644 index f656bec4930..00000000000 --- a/.evergreen/run-resource-management.sh +++ /dev/null @@ -1,5 +0,0 @@ -#! /bin/bash - -source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh - -npm run check:resource-management diff --git a/api-extractor.json b/api-extractor.json index bbf8b9d173a..bda873c16bf 100644 --- a/api-extractor.json +++ b/api-extractor.json @@ -10,8 +10,7 @@ "dtsRollup": { "enabled": true, "untrimmedFilePath": "", - "publicTrimmedFilePath": "/.d.ts", - "betaTrimmedFilePath": "/lib/beta.d.ts" + "publicTrimmedFilePath": "/.d.ts" }, "tsdocMetadata": { "enabled": false diff --git a/package.json b/package.json index 83c4fbc862e..1353f8ab2e2 100644 --- a/package.json +++ b/package.json @@ -124,7 +124,7 @@ "scripts": { "build:evergreen": "node .evergreen/generate_evergreen_tasks.js", "build:ts": "node ./node_modules/typescript/bin/tsc", - "build:dts": "npm run build:ts && api-extractor run && node etc/clean_definition_files.cjs && ESLINT_USE_FLAT_CONFIG=false eslint --no-ignore --fix mongodb.d.ts lib/beta.d.ts", + "build:dts": "npm run build:ts && api-extractor run && node etc/clean_definition_files.cjs && ESLINT_USE_FLAT_CONFIG=false eslint --no-ignore --fix mongodb.d.ts", "build:docs": "./etc/docs/build.ts", "build:typedoc": "typedoc", "build:nightly": "node ./.github/scripts/nightly.mjs", @@ -143,7 +143,6 @@ "check:unit": "nyc mocha test/unit", "check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit", "check:atlas": "nyc mocha --config test/manual/mocharc.js test/manual/atlas_connectivity.test.ts", - "check:resource-management": "nyc mocha --config test/manual/mocharc.js test/manual/resource_management.test.ts", "check:drivers-atlas-testing": "nyc mocha --config test/mocha_mongodb.js test/atlas/drivers_atlas_testing.test.ts", "check:aws": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/mongodb_aws.test.ts", "check:oidc-auth": "nyc mocha --config test/mocha_mongodb.js test/integration/auth/auth.spec.test.ts", diff --git a/src/beta.ts b/src/beta.ts deleted file mode 100644 index 05c60fa7069..00000000000 --- a/src/beta.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { type Document } from './bson'; - -export * from './index'; - -/** - * @internal - * - * Since we don't bundle tslib helpers, we need to polyfill this method. - * - * This is used in the generated JS. Adapted from https://github.com/microsoft/TypeScript/blob/aafdfe5b3f76f5c41abeec412ce73c86da94c75f/src/compiler/factory/emitHelpers.ts#L1202. - */ - -function __exportStar(mod: Document) { - for (const key of Object.keys(mod)) { - Object.defineProperty(exports, key, { - enumerable: true, - get: function () { - return mod[key]; - } - }); - } -} diff --git a/src/change_stream.ts b/src/change_stream.ts index 26833124120..6cb118cb095 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -18,7 +18,6 @@ import { MongoClient } from './mongo_client'; import { type InferIdType, TypedEventEmitter } from './mongo_types'; import type { AggregateOptions } from './operations/aggregate'; import type { OperationParent } from './operations/command'; -import { type AsyncDisposable, configureResourceManagement } from './resource_management'; import type { ServerSessionId } from './sessions'; import { CSOTTimeoutContext, type TimeoutContext } from './timeout'; import { filterOptions, getTopology, type MongoDBNamespace, squashError } from './utils'; @@ -574,13 +573,10 @@ export class ChangeStream< implements AsyncDisposable { /** - * @beta * @experimental * An alias for {@link ChangeStream.close|ChangeStream.close()}. */ - declare [Symbol.asyncDispose]: () => Promise; - /** @internal */ - async asyncDispose() { + async [Symbol.asyncDispose]() { await this.close(); } @@ -1090,5 +1086,3 @@ export class ChangeStream< } } } - -configureResourceManagement(ChangeStream.prototype); diff --git a/src/cursor/abstract_cursor.ts b/src/cursor/abstract_cursor.ts index a69f9fbabf9..f60ae2a44af 100644 --- a/src/cursor/abstract_cursor.ts +++ b/src/cursor/abstract_cursor.ts @@ -18,7 +18,6 @@ import { GetMoreOperation } from '../operations/get_more'; import { KillCursorsOperation } from '../operations/kill_cursors'; import { ReadConcern, type ReadConcernLike } from '../read_concern'; import { ReadPreference, type ReadPreferenceLike } from '../read_preference'; -import { type AsyncDisposable, configureResourceManagement } from '../resource_management'; import type { Server } from '../sdam/server'; import { type ClientSession, maybeClearPinnedConnection } from '../sessions'; import { type CSOTTimeoutContext, type Timeout, TimeoutContext } from '../timeout'; @@ -437,13 +436,10 @@ export abstract class AbstractCursor< } /** - * @beta * @experimental * An alias for {@link AbstractCursor.close|AbstractCursor.close()}. */ - declare [Symbol.asyncDispose]: () => Promise; - /** @internal */ - async asyncDispose() { + async [Symbol.asyncDispose]() { await this.close(); } @@ -1223,8 +1219,6 @@ class ReadableCursorStream extends Readable { } } -configureResourceManagement(AbstractCursor.prototype); - /** * @internal * The cursor timeout context is a wrapper around a timeout context diff --git a/src/index.ts b/src/index.ts index 13bfe15642b..630fa7a4110 100644 --- a/src/index.ts +++ b/src/index.ts @@ -87,7 +87,6 @@ export { MongoWriteConcernError, WriteConcernErrorResult } from './error'; -export { configureExplicitResourceManagement } from './resource_management'; export { AbstractCursor, // Actual driver classes exported @@ -564,7 +563,6 @@ export type { ReadPreferenceLikeOptions, ReadPreferenceOptions } from './read_preference'; -export type { AsyncDisposable } from './resource_management'; export type { ClusterTime } from './sdam/common'; export type { Monitor, diff --git a/src/mongo_client.ts b/src/mongo_client.ts index 474edc44f70..4b0ff63681c 100644 --- a/src/mongo_client.ts +++ b/src/mongo_client.ts @@ -48,7 +48,6 @@ import { executeOperation } from './operations/execute_operation'; import { AbstractOperation } from './operations/operation'; import type { ReadConcern, ReadConcernLevel, ReadConcernLike } from './read_concern'; import { ReadPreference, type ReadPreferenceMode } from './read_preference'; -import { type AsyncDisposable, configureResourceManagement } from './resource_management'; import type { ServerMonitoringMode } from './sdam/monitor'; import type { TagSet } from './sdam/server_description'; import { readPreferenceServerSelector } from './sdam/server_selection'; @@ -485,13 +484,10 @@ export class MongoClient extends TypedEventEmitter implements } /** - * @beta * @experimental * An alias for {@link MongoClient.close|MongoClient.close()}. */ - declare [Symbol.asyncDispose]: () => Promise; - /** @internal */ - async asyncDispose() { + async [Symbol.asyncDispose]() { await this.close(); } @@ -1037,8 +1033,6 @@ export class MongoClient extends TypedEventEmitter implements } } -configureResourceManagement(MongoClient.prototype); - /** * Parsed Mongo Client Options. * diff --git a/src/resource_management.ts b/src/resource_management.ts deleted file mode 100644 index 461f49970a8..00000000000 --- a/src/resource_management.ts +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @public - */ -export interface AsyncDisposable { - /** - * @beta - * @experimental - */ - [Symbol.asyncDispose](): Promise; - - /** - * @internal - * - * A method that wraps disposal semantics for a given resource in the class. - */ - asyncDispose(): Promise; -} - -/** @internal */ -export function configureResourceManagement(target: AsyncDisposable) { - Symbol.asyncDispose && - Object.defineProperty(target, Symbol.asyncDispose, { - value: async function asyncDispose(this: AsyncDisposable) { - await this.asyncDispose(); - }, - enumerable: false, - configurable: true, - writable: true - }); -} - -/** - * @beta - * @experimental - * - * Attaches `Symbol.asyncDispose` methods to the MongoClient, Cursors, sessions and change streams - * if Symbol.asyncDispose is defined. - * - * It's usually not necessary to call this method - the driver attempts to attach these methods - * itself when its loaded. However, sometimes the driver may be loaded before `Symbol.asyncDispose` - * is defined, in which case it is necessary to call this method directly. This can happen if the - * application is polyfilling `Symbol.asyncDispose`. - * - * Example: - * - * ```typescript - * import { configureExplicitResourceManagement, MongoClient } from 'mongodb/lib/beta'; - * - * Symbol.asyncDispose ??= Symbol('dispose'); - * load(); - * - * await using client = new MongoClient(...); - * ``` - */ -export function configureExplicitResourceManagement() { - // We must import lazily here, because there's a circular dependency between the resource management - // file and each resources' file. We could move `configureResourceManagement` to a separate - // function, but keeping all resource-management related code together seemed preferable and I chose - // lazy requiring of resources instead. - - // eslint-disable-next-line @typescript-eslint/no-require-imports - const { MongoClient } = require('./mongo_client'); - // eslint-disable-next-line @typescript-eslint/no-require-imports - const { ClientSession } = require('./sessions'); - // eslint-disable-next-line @typescript-eslint/no-require-imports - const { AbstractCursor } = require('./cursor/abstract_cursor'); - // eslint-disable-next-line @typescript-eslint/no-require-imports - const { ChangeStream } = require('./change_stream'); - - configureResourceManagement(MongoClient.prototype); - configureResourceManagement(ClientSession.prototype); - configureResourceManagement(AbstractCursor.prototype); - configureResourceManagement(ChangeStream.prototype); -} diff --git a/src/sessions.ts b/src/sessions.ts index 441ee030782..0788ff15386 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -26,7 +26,6 @@ import { executeOperation } from './operations/execute_operation'; import { RunCommandOperation } from './operations/run_command'; import { ReadConcernLevel } from './read_concern'; import { ReadPreference } from './read_preference'; -import { type AsyncDisposable, configureResourceManagement } from './resource_management'; import { _advanceClusterTime, type ClusterTime, TopologyType } from './sdam/common'; import { TimeoutContext } from './timeout'; import { @@ -289,13 +288,10 @@ export class ClientSession } } /** - * @beta * @experimental * An alias for {@link ClientSession.endSession|ClientSession.endSession()}. */ - declare [Symbol.asyncDispose]: () => Promise; - /** @internal */ - async asyncDispose() { + async [Symbol.asyncDispose]() { await this.endSession({ force: true }); } @@ -823,8 +819,6 @@ export class ClientSession } } -configureResourceManagement(ClientSession.prototype); - const NON_DETERMINISTIC_WRITE_CONCERN_ERRORS = new Set([ 'CannotSatisfyWriteConcern', 'UnknownReplWriteConcern', diff --git a/test/explicit-resource-management/main.test.ts b/test/explicit-resource-management/main.test.ts index f540a4c1af5..746aac078f5 100644 --- a/test/explicit-resource-management/main.test.ts +++ b/test/explicit-resource-management/main.test.ts @@ -1,12 +1,6 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; -import { - AbstractCursor, - ChangeStream, - ClientSession, - GridFSBucket, - MongoClient -} from 'mongodb/lib/beta'; +import { AbstractCursor, ChangeStream, ClientSession, GridFSBucket, MongoClient } from 'mongodb'; import * as sinon from 'sinon'; import { Readable } from 'stream'; import { pipeline } from 'stream/promises'; diff --git a/test/manual/resource_management.test.ts b/test/integration/node-specific/async_dispose.test.ts similarity index 53% rename from test/manual/resource_management.test.ts rename to test/integration/node-specific/async_dispose.test.ts index d92315ba3bd..dfd6ad6a89e 100644 --- a/test/manual/resource_management.test.ts +++ b/test/integration/node-specific/async_dispose.test.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; -import { AbstractCursor, ChangeStream, ClientSession, MongoClient } from '../mongodb'; +import { type MongoClient } from '../../../src'; describe('Symbol.asyncDispose implementation tests', function () { let client: MongoClient; @@ -11,16 +11,9 @@ describe('Symbol.asyncDispose implementation tests', function () { }); describe('Symbol.asyncDispose defined', function () { - beforeEach(function () { - if (!('asyncDispose' in Symbol)) { - this.currentTest.skipReason = 'Test must run with asyncDispose available.'; - this.skip(); - } - }); - describe('MongoClient', function () { it('the Symbol.asyncDispose method calls close()', async function () { - client = new MongoClient('mongodb://localhost:27017'); + client = this.configuration.newClient(); const spy = sinon.spy(client, 'close'); await client[Symbol.asyncDispose](); @@ -30,7 +23,7 @@ describe('Symbol.asyncDispose implementation tests', function () { describe('ClientSession', function () { it('the Symbol.asyncDispose method calls endSession()', async function () { - client = new MongoClient('mongodb://localhost:27017'); + client = this.configuration.newClient(); const session = client.startSession(); const spy = sinon.spy(session, 'endSession'); @@ -41,7 +34,7 @@ describe('Symbol.asyncDispose implementation tests', function () { describe('ChangeStreams', function () { it('the Symbol.asyncDispose method calls close()', async function () { - client = new MongoClient('mongodb://localhost:27017'); + client = this.configuration.newClient(); const changeStream = client.watch(); const spy = sinon.spy(changeStream, 'close'); @@ -52,7 +45,7 @@ describe('Symbol.asyncDispose implementation tests', function () { describe('cursors', function () { it('the Symbol.asyncDispose method calls close()', async function () { - client = new MongoClient('mongodb://localhost:27017'); + client = this.configuration.newClient(); const cursor = client.db('foo').collection('bar').find(); const spy = sinon.spy(cursor, 'close'); @@ -61,29 +54,4 @@ describe('Symbol.asyncDispose implementation tests', function () { }); }); }); - - describe('Symbol.asyncDispose not defined', function () { - beforeEach(function () { - if ('asyncDispose' in Symbol) { - this.currentTest.skipReason = 'Test must run without asyncDispose available.'; - this.skip(); - } - }); - - it('does not define symbol.asyncDispose on MongoClient', function () { - expect(MongoClient[Symbol.asyncDispose]).not.to.exist; - }); - - it('does not define symbol.asyncDispose on ClientSession', function () { - expect(ClientSession[Symbol.asyncDispose]).not.to.exist; - }); - - it('does not define symbol.asyncDispose on ChangeStream', function () { - expect(ChangeStream[Symbol.asyncDispose]).not.to.exist; - }); - - it('does not define symbol.asyncDispose on cursors', function () { - expect(AbstractCursor[Symbol.asyncDispose]).not.to.exist; - }); - }); }); diff --git a/test/mongodb.ts b/test/mongodb.ts index ec5a7d8ad3f..0c1783dfcec 100644 --- a/test/mongodb.ts +++ b/test/mongodb.ts @@ -194,7 +194,6 @@ export * from '../src/operations/update'; export * from '../src/operations/validate_collection'; export * from '../src/read_concern'; export * from '../src/read_preference'; -export * from '../src/resource_management'; export * from '../src/sdam/common'; export * from '../src/sdam/events'; export * from '../src/sdam/monitor'; diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index 5b0658d1038..7b73c22b82b 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -27,7 +27,6 @@ const EXPECTED_EXPORTS = [ 'CommandStartedEvent', 'CommandSucceededEvent', 'Compressor', - 'configureExplicitResourceManagement', 'ConnectionCheckedInEvent', 'ConnectionCheckedOutEvent', 'ConnectionCheckOutFailedEvent',