UNPKG

2.08 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.enable = exports.mongoCore = void 0;
4// Copyright (c) Microsoft Corporation. All rights reserved.
5// Licensed under the MIT license. See LICENSE file in the project root for details.
6var diagnostic_channel_1 = require("diagnostic-channel");
7var mongodbcorePatchFunction = function (originalMongoCore) {
8 var originalConnect = originalMongoCore.Server.prototype.connect;
9 originalMongoCore.Server.prototype.connect = function contextPreservingConnect() {
10 var ret = originalConnect.apply(this, arguments);
11 // Messages sent to mongo progress through a pool
12 // This can result in context getting mixed between different responses
13 // so we wrap the callbacks to restore appropriate state
14 var originalWrite = this.s.pool.write;
15 this.s.pool.write = function contextPreservingWrite() {
16 var cbidx = typeof arguments[1] === "function" ? 1 : 2;
17 if (typeof arguments[cbidx] === "function") {
18 arguments[cbidx] = diagnostic_channel_1.channel.bindToContext(arguments[cbidx]);
19 }
20 return originalWrite.apply(this, arguments);
21 };
22 // Logout is a special case, it doesn't call the write function but instead
23 // directly calls into connection.write
24 var originalLogout = this.s.pool.logout;
25 this.s.pool.logout = function contextPreservingLogout() {
26 if (typeof arguments[1] === "function") {
27 arguments[1] = diagnostic_channel_1.channel.bindToContext(arguments[1]);
28 }
29 return originalLogout.apply(this, arguments);
30 };
31 return ret;
32 };
33 return originalMongoCore;
34};
35exports.mongoCore = {
36 versionSpecifier: ">= 2.0.0 < 4.0.0",
37 patch: mongodbcorePatchFunction,
38};
39function enable() {
40 diagnostic_channel_1.channel.registerMonkeyPatch("mongodb-core", exports.mongoCore);
41}
42exports.enable = enable;
43//# sourceMappingURL=mongodb-core.pub.js.map
\No newline at end of file