Skip to content

Commit 916f78b

Browse files
remove additionalDriverInfo
1 parent d4782ac commit 916f78b

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/cmap/handshake/client_metadata.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class LimitedSizeDocument {
107107
}
108108
}
109109

110-
type MakeClientMetadataOptions = Pick<MongoOptions, 'appName' | 'additionalDriverInfo'>;
110+
type MakeClientMetadataOptions = Pick<MongoOptions, 'appName'>;
111111
/**
112112
* From the specs:
113113
* Implementors SHOULD cumulatively update fields in the following order until the document is under the size limit:
@@ -116,15 +116,17 @@ type MakeClientMetadataOptions = Pick<MongoOptions, 'appName' | 'additionalDrive
116116
* 3. Omit the `env` document entirely.
117117
* 4. Truncate `platform`. -- special we do not truncate this field
118118
*/
119-
export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMetadata {
119+
export function makeClientMetadata(
120+
driverInfos: DriverInfo[],
121+
{ appName = '' }: MakeClientMetadataOptions
122+
): ClientMetadata {
120123
const metadataDocument = new LimitedSizeDocument(512);
121124

122-
const { appName = '' } = options;
123125
// Add app name first, it must be sent
124126
if (appName.length > 0) {
125127
const name =
126128
Buffer.byteLength(appName, 'utf8') <= 128
127-
? options.appName
129+
? appName
128130
: Buffer.from(appName, 'utf8').subarray(0, 128).toString('utf8');
129131
metadataDocument.ifItFitsItSits('application', { name });
130132
}
@@ -135,7 +137,7 @@ export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMe
135137
};
136138

137139
// This is where we handle additional driver info added after client construction.
138-
for (const { name: n = '', version: v = '' } of options.additionalDriverInfo) {
140+
for (const { name: n = '', version: v = '' } of driverInfos) {
139141
if (n.length > 0) {
140142
driverInfo.name = `${driverInfo.name}|${n}`;
141143
}
@@ -152,7 +154,7 @@ export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMe
152154

153155
let runtimeInfo = getRuntimeInfo();
154156
// This is where we handle additional driver info added after client construction.
155-
for (const { platform = '' } of options.additionalDriverInfo) {
157+
for (const { platform = '' } of driverInfos) {
156158
if (platform.length > 0) {
157159
runtimeInfo = `${runtimeInfo}|${platform}`;
158160
}

src/mongo_client.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,14 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
431431
| 'extendedMetadata'
432432
>;
433433

434+
private driverInfos: DriverInfo[] = [];
435+
434436
constructor(url: string, options?: MongoClientOptions) {
435437
super();
436438
this.on('error', noop);
437439

438440
this.options = parseOptions(url, this, options);
439441

440-
this.options.additionalDriverInfo = [];
441442
this.appendMetadata(this.options.driverInfo);
442443

443444
const shouldSetLogger = Object.values(this.options.mongoLoggerOptions.componentSeverities).some(
@@ -496,13 +497,13 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
496497
* @param driverInfo - Information about the application or library.
497498
*/
498499
appendMetadata(driverInfo: DriverInfo) {
499-
const isDuplicateDriverInfo = this.options.additionalDriverInfo.some(info =>
500+
const isDuplicateDriverInfo = this.driverInfos.some(info =>
500501
isDriverInfoEqual(info, driverInfo)
501502
);
502503
if (isDuplicateDriverInfo) return;
503504

504-
this.options.additionalDriverInfo.push(driverInfo);
505-
this.options.metadata = makeClientMetadata(this.options);
505+
this.driverInfos.push(driverInfo);
506+
this.options.metadata = makeClientMetadata(this.driverInfos, this.options);
506507
this.options.extendedMetadata = addContainerMetadata(this.options.metadata)
507508
.then(undefined, squashError)
508509
.then(result => result ?? {}); // ensure Promise<Document>

0 commit comments

Comments
 (0)