Skip to content

Commit 1a76618

Browse files
authored
fix: versioned api low node compat fix (#2970)
1 parent 7602f68 commit 1a76618

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

lib/core/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ try {
1919
const ServerApiVersion = Object.freeze({
2020
v1: '1'
2121
});
22+
const ValidServerApiVersions = Object.keys(ServerApiVersion).map(key => ServerApiVersion[key]);
2223

2324
module.exports = {
2425
// Versioned API
2526
ServerApiVersion,
27+
ValidServerApiVersions,
2628
// Errors
2729
MongoError: require('./error').MongoError,
2830
MongoNetworkError: require('./error').MongoNetworkError,

lib/mongo_client.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const Db = require('./db');
55
const EventEmitter = require('events').EventEmitter;
66
const inherits = require('util').inherits;
77
const MongoError = require('./core').MongoError;
8-
const ServerApiVersion = require('./core').ServerApiVersion;
8+
const ValidServerApiVersions = require('./core').ValidServerApiVersions;
99
const deprecate = require('util').deprecate;
1010
const WriteConcern = require('./write_concern');
1111
const MongoDBNamespace = require('./utils').MongoDBNamespace;
@@ -206,16 +206,16 @@ function MongoClient(url, options) {
206206
const versionToValidate = serverApiToValidate && serverApiToValidate.version;
207207
if (!versionToValidate) {
208208
throw new MongoError(
209-
`Invalid \`serverApi\` property; must specify a version from the following enum: ["${Object.values(
210-
ServerApiVersion
211-
).join('", "')}"]`
209+
`Invalid \`serverApi\` property; must specify a version from the following enum: ["${ValidServerApiVersions.join(
210+
'", "'
211+
)}"]`
212212
);
213213
}
214-
if (!Object.values(ServerApiVersion).some(v => v === versionToValidate)) {
214+
if (!ValidServerApiVersions.some(v => v === versionToValidate)) {
215215
throw new MongoError(
216-
`Invalid server API version=${versionToValidate}; must be in the following enum: ["${Object.values(
217-
ServerApiVersion
218-
).join('", "')}"]`
216+
`Invalid server API version=${versionToValidate}; must be in the following enum: ["${ValidServerApiVersions.join(
217+
'", "'
218+
)}"]`
219219
);
220220
}
221221
options.serverApi = serverApiToValidate;

test/functional/unified-spec-runner/unified-utils.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { expect } from 'chai';
22
import type { CollectionOrDatabaseOptions, RunOnRequirement, Document } from './schema';
33
import { gte as semverGte, lte as semverLte } from 'semver';
44
import { MongoClient } from '../../../index';
5-
import { isDeepStrictEqual } from 'util';
65
import { TestConfiguration } from './runner';
76

87
export async function topologySatisfies(
@@ -41,7 +40,11 @@ export async function topologySatisfies(
4140
if (!config.parameters) throw new Error('Configuration does not have server parameters');
4241
for (const [name, value] of Object.entries(r.serverParameters)) {
4342
if (name in config.parameters) {
44-
ok &&= isDeepStrictEqual(config.parameters[name], value);
43+
try {
44+
expect(config.parameters[name]).to.deep.equal(value);
45+
} catch (_err) {
46+
ok = false;
47+
}
4548
}
4649
}
4750
}

test/functional/versioned-api.test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
const expect = require('chai').expect;
44
const loadSpecTests = require('../spec/index').loadSpecTests;
55
const runUnifiedTest = require('./unified-spec-runner/runner').runUnifiedTest;
6-
const ServerApiVersion = require('../../lib/core').ServerApiVersion;
6+
const validVersions = require('../../lib/core').ValidServerApiVersions;
77

88
describe('Versioned API', function() {
99
describe('client option validation', function() {
1010
it('is supported as a client option when it is a valid ServerApiVersion string', function() {
11-
const validVersions = Object.values(ServerApiVersion);
1211
expect(validVersions.length).to.be.at.least(1);
1312
for (const version of validVersions) {
1413
const client = this.configuration.newClient('mongodb://localhost/', {
@@ -21,7 +20,6 @@ describe('Versioned API', function() {
2120
});
2221

2322
it('is supported as a client option when it is an object with a valid version property', function() {
24-
const validVersions = Object.values(ServerApiVersion);
2523
expect(validVersions.length).to.be.at.least(1);
2624
for (const version of validVersions) {
2725
const client = this.configuration.newClient('mongodb://localhost/', {

0 commit comments

Comments
 (0)