something is working
This commit is contained in:
+96
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.decompress = exports.compress = exports.uncompressibleCommands = exports.Compressor = void 0;
|
||||
const zlib = require("zlib");
|
||||
const constants_1 = require("../../constants");
|
||||
const deps_1 = require("../../deps");
|
||||
const error_1 = require("../../error");
|
||||
/** @public */
|
||||
exports.Compressor = Object.freeze({
|
||||
none: 0,
|
||||
snappy: 1,
|
||||
zlib: 2,
|
||||
zstd: 3
|
||||
});
|
||||
exports.uncompressibleCommands = new Set([
|
||||
constants_1.LEGACY_HELLO_COMMAND,
|
||||
'saslStart',
|
||||
'saslContinue',
|
||||
'getnonce',
|
||||
'authenticate',
|
||||
'createUser',
|
||||
'updateUser',
|
||||
'copydbSaslStart',
|
||||
'copydbgetnonce',
|
||||
'copydb'
|
||||
]);
|
||||
const MAX_COMPRESSOR_ID = 3;
|
||||
const ZSTD_COMPRESSION_LEVEL = 3;
|
||||
// Facilitate compressing a message using an agreed compressor
|
||||
function compress(self, dataToBeCompressed, callback) {
|
||||
const zlibOptions = {};
|
||||
switch (self.options.agreedCompressor) {
|
||||
case 'snappy': {
|
||||
if ('kModuleError' in deps_1.Snappy) {
|
||||
return callback(deps_1.Snappy['kModuleError']);
|
||||
}
|
||||
if (deps_1.Snappy[deps_1.PKG_VERSION].major <= 6) {
|
||||
deps_1.Snappy.compress(dataToBeCompressed, callback);
|
||||
}
|
||||
else {
|
||||
deps_1.Snappy.compress(dataToBeCompressed).then(buffer => callback(undefined, buffer), error => callback(error));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'zlib':
|
||||
// Determine zlibCompressionLevel
|
||||
if (self.options.zlibCompressionLevel) {
|
||||
zlibOptions.level = self.options.zlibCompressionLevel;
|
||||
}
|
||||
zlib.deflate(dataToBeCompressed, zlibOptions, callback);
|
||||
break;
|
||||
case 'zstd':
|
||||
if ('kModuleError' in deps_1.ZStandard) {
|
||||
return callback(deps_1.ZStandard['kModuleError']);
|
||||
}
|
||||
deps_1.ZStandard.compress(dataToBeCompressed, ZSTD_COMPRESSION_LEVEL).then(buffer => callback(undefined, buffer), error => callback(error));
|
||||
break;
|
||||
default:
|
||||
throw new error_1.MongoInvalidArgumentError(`Unknown compressor ${self.options.agreedCompressor} failed to compress`);
|
||||
}
|
||||
}
|
||||
exports.compress = compress;
|
||||
// Decompress a message using the given compressor
|
||||
function decompress(compressorID, compressedData, callback) {
|
||||
if (compressorID < 0 || compressorID > MAX_COMPRESSOR_ID) {
|
||||
throw new error_1.MongoDecompressionError(`Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID})`);
|
||||
}
|
||||
switch (compressorID) {
|
||||
case exports.Compressor.snappy: {
|
||||
if ('kModuleError' in deps_1.Snappy) {
|
||||
return callback(deps_1.Snappy['kModuleError']);
|
||||
}
|
||||
if (deps_1.Snappy[deps_1.PKG_VERSION].major <= 6) {
|
||||
deps_1.Snappy.uncompress(compressedData, { asBuffer: true }, callback);
|
||||
}
|
||||
else {
|
||||
deps_1.Snappy.uncompress(compressedData, { asBuffer: true }).then(buffer => callback(undefined, buffer), error => callback(error));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case exports.Compressor.zstd: {
|
||||
if ('kModuleError' in deps_1.ZStandard) {
|
||||
return callback(deps_1.ZStandard['kModuleError']);
|
||||
}
|
||||
deps_1.ZStandard.decompress(compressedData).then(buffer => callback(undefined, buffer), error => callback(error));
|
||||
break;
|
||||
}
|
||||
case exports.Compressor.zlib:
|
||||
zlib.inflate(compressedData, callback);
|
||||
break;
|
||||
default:
|
||||
callback(undefined, compressedData);
|
||||
}
|
||||
}
|
||||
exports.decompress = decompress;
|
||||
//# sourceMappingURL=compression.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"compression.js","sourceRoot":"","sources":["../../../src/cmap/wire_protocol/compression.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAE7B,+CAAuD;AACvD,qCAA4D;AAC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AAC,CAAC,IAAI,CACxD,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,EACrC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzB,CAAC;aACH;YACD,MAAM;SACP;QACD,KAAK,kBAAU,CAAC,IAAI,CAAC,CAAC;YACpB,IAAI,cAAc,IAAI,gBAAS,EAAE;gBAC/B,OAAO,QAAQ,CAAC,gBAAS,CAAC,cAAc,CAAC,CAAC,CAAC;aAC5C;YAED,gBAAS,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,IAAI,CACvC,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,EACrC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzB,CAAC;YACF,MAAM;SACP;QACD,KAAK,kBAAU,CAAC,IAAI;YAClB,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,QAAiC,CAAC,CAAC;YAChE,MAAM;QACR;YACE,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;KACvC;AACH,CAAC;AA5CD,gCA4CC"}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OP_MSG = exports.OP_COMPRESSED = exports.OP_DELETE = exports.OP_QUERY = exports.OP_INSERT = exports.OP_UPDATE = exports.OP_REPLY = exports.MAX_SUPPORTED_WIRE_VERSION = exports.MIN_SUPPORTED_WIRE_VERSION = exports.MAX_SUPPORTED_SERVER_VERSION = exports.MIN_SUPPORTED_SERVER_VERSION = void 0;
|
||||
exports.MIN_SUPPORTED_SERVER_VERSION = '3.6';
|
||||
exports.MAX_SUPPORTED_SERVER_VERSION = '6.0';
|
||||
exports.MIN_SUPPORTED_WIRE_VERSION = 6;
|
||||
exports.MAX_SUPPORTED_WIRE_VERSION = 17;
|
||||
exports.OP_REPLY = 1;
|
||||
exports.OP_UPDATE = 2001;
|
||||
exports.OP_INSERT = 2002;
|
||||
exports.OP_QUERY = 2004;
|
||||
exports.OP_DELETE = 2006;
|
||||
exports.OP_COMPRESSED = 2012;
|
||||
exports.OP_MSG = 2013;
|
||||
//# sourceMappingURL=constants.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/cmap/wire_protocol/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,4BAA4B,GAAG,KAAK,CAAC;AACrC,QAAA,4BAA4B,GAAG,KAAK,CAAC;AACrC,QAAA,0BAA0B,GAAG,CAAC,CAAC;AAC/B,QAAA,0BAA0B,GAAG,EAAE,CAAC;AAChC,QAAA,QAAQ,GAAG,CAAC,CAAC;AACb,QAAA,SAAS,GAAG,IAAI,CAAC;AACjB,QAAA,SAAS,GAAG,IAAI,CAAC;AACjB,QAAA,QAAQ,GAAG,IAAI,CAAC;AAChB,QAAA,SAAS,GAAG,IAAI,CAAC;AACjB,QAAA,aAAa,GAAG,IAAI,CAAC;AACrB,QAAA,MAAM,GAAG,IAAI,CAAC"}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isSharded = exports.applyCommonQueryOptions = exports.getReadPreference = void 0;
|
||||
const error_1 = require("../../error");
|
||||
const read_preference_1 = require("../../read_preference");
|
||||
const common_1 = require("../../sdam/common");
|
||||
const topology_description_1 = require("../../sdam/topology_description");
|
||||
function getReadPreference(cmd, options) {
|
||||
// Default to command version of the readPreference
|
||||
let readPreference = cmd.readPreference || read_preference_1.ReadPreference.primary;
|
||||
// If we have an option readPreference override the command one
|
||||
if (options === null || options === void 0 ? void 0 : options.readPreference) {
|
||||
readPreference = options.readPreference;
|
||||
}
|
||||
if (typeof readPreference === 'string') {
|
||||
readPreference = read_preference_1.ReadPreference.fromString(readPreference);
|
||||
}
|
||||
if (!(readPreference instanceof read_preference_1.ReadPreference)) {
|
||||
throw new error_1.MongoInvalidArgumentError('Option "readPreference" must be a ReadPreference instance');
|
||||
}
|
||||
return readPreference;
|
||||
}
|
||||
exports.getReadPreference = getReadPreference;
|
||||
function applyCommonQueryOptions(queryOptions, options) {
|
||||
Object.assign(queryOptions, {
|
||||
raw: typeof options.raw === 'boolean' ? options.raw : false,
|
||||
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
|
||||
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
|
||||
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
|
||||
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
|
||||
enableUtf8Validation: typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true
|
||||
});
|
||||
if (options.session) {
|
||||
queryOptions.session = options.session;
|
||||
}
|
||||
return queryOptions;
|
||||
}
|
||||
exports.applyCommonQueryOptions = applyCommonQueryOptions;
|
||||
function isSharded(topologyOrServer) {
|
||||
if (topologyOrServer == null) {
|
||||
return false;
|
||||
}
|
||||
if (topologyOrServer.description && topologyOrServer.description.type === common_1.ServerType.Mongos) {
|
||||
return true;
|
||||
}
|
||||
// NOTE: This is incredibly inefficient, and should be removed once command construction
|
||||
// happens based on `Server` not `Topology`.
|
||||
if (topologyOrServer.description && topologyOrServer.description instanceof topology_description_1.TopologyDescription) {
|
||||
const servers = Array.from(topologyOrServer.description.servers.values());
|
||||
return servers.some((server) => server.type === common_1.ServerType.Mongos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isSharded = isSharded;
|
||||
//# sourceMappingURL=shared.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/cmap/wire_protocol/shared.ts"],"names":[],"mappings":";;;AACA,uCAAwD;AAExD,2DAAuD;AACvD,8CAA+C;AAI/C,0EAAsE;AAQtE,SAAgB,iBAAiB,CAAC,GAAa,EAAE,OAA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