Skip to content

Commit 3da4d1c

Browse files
committed
Allow passing a promise of build info
1 parent 9316c03 commit 3da4d1c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/mongodb-build-info/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ export function getGenuineMongoDB(uri: string): {
146146
type IdentifyServerNameOptions = {
147147
connectionString: string;
148148
adminCommand: (command: Document) => Promise<Document>;
149+
/** Pass this to prevent multiple requests for the same data */
150+
buildInfo?: Promise<Document>;
149151
};
150152

151153
/**
@@ -155,6 +157,7 @@ type IdentifyServerNameOptions = {
155157
export async function identifyServerName({
156158
connectionString,
157159
adminCommand,
160+
buildInfo,
158161
}: IdentifyServerNameOptions): Promise<string> {
159162
try {
160163
const hostname = getHostnameFromUrl(connectionString);
@@ -175,7 +178,7 @@ export async function identifyServerName({
175178
}
176179

177180
const candidates = await Promise.all([
178-
adminCommand({ buildInfo: 1 }).then(
181+
(buildInfo ?? adminCommand({ buildInfo: 1 })).then(
179182
(response) => {
180183
if ('ferretdb' in response) {
181184
return ['ferretdb'];

0 commit comments

Comments
 (0)