New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-memory-server-core

Package Overview
Dependencies
Maintainers
1
Versions
277
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-memory-server-core - npm Package Compare versions

Comparing version 6.7.5 to 6.7.6

13

lib/util/__tests__/MongoBinary-test.js

@@ -137,10 +137,5 @@ "use strict";

return __generator(this, function (_a) {
switch (_a.label) {
case 0:
MongoBinary_1.default.cache['3.4.2'] = '/bin/mongod';
return [4 /*yield*/, expect(MongoBinary_1.default.getCachePath('3.4.2')).resolves.toEqual('/bin/mongod')];
case 1:
_a.sent();
return [2 /*return*/];
}
MongoBinary_1.default.cache['3.4.2'] = '/bin/mongod';
expect(MongoBinary_1.default.getCachePath('3.4.2')).toEqual('/bin/mongod');
return [2 /*return*/];
});

@@ -158,3 +153,3 @@ }); });

case 1:
_a.sent();
_a.sent(); // ignoring return, because this depends on the host system
expect(accessSpy).toHaveBeenCalledWith('/usr/bin/mongod', expect.any(Function));

@@ -161,0 +156,0 @@ accessSpy.mockClear();

@@ -123,3 +123,3 @@ "use strict";

process.chdir(tmpObj.name + "/project");
resolve_config_1.reInitializePackageJson();
resolve_config_1.findPackageJson();
var got = resolve_config_1.default('VERSION');

@@ -130,3 +130,3 @@ expect(got).toBe('3.0.0');

process.chdir(tmpObj.name + "/project/subproject");
resolve_config_1.reInitializePackageJson();
resolve_config_1.findPackageJson();
var got = resolve_config_1.default('VERSION');

@@ -137,3 +137,3 @@ expect(got).toBe('4.0.0');

process.chdir(tmpObj.name + "/project");
resolve_config_1.reInitializePackageJson(tmpObj.name + "/project/subproject");
resolve_config_1.findPackageJson(tmpObj.name + "/project/subproject");
var got = resolve_config_1.default('VERSION');

@@ -140,0 +140,0 @@ expect(got).toBe('4.0.0');

@@ -14,8 +14,27 @@ export declare const LATEST_VERSION: string;

static cache: MongoBinaryCache;
/**
* Probe if the provided "systemBinary" is an existing path
* @param systemBinary The Path to probe for an System-Binary
* @return System Binary path or empty string
*/
static getSystemPath(systemBinary: string): Promise<string>;
static getCachePath(version: string): Promise<string>;
/**
* Check if specified version already exists in the cache
* @param version The Version to check for
*/
static getCachePath(version: string): string;
/**
* Probe download path and download the binary
* @param options Options Configuring which binary to download and to which path
* @returns The BinaryPath the binary has been downloaded to
*/
static getDownloadPath(options: Required<MongoBinaryOpts>): Promise<string>;
/**
* Probe all supported paths for an binary and return the binary path
* @param opts Options configuring which binary to search for
* @throws {Error} if no valid BinaryPath has been found
* @return The first found BinaryPath
*/
static getPath(opts?: MongoBinaryOpts): Promise<string>;
static hasValidBinPath(files: string[]): boolean;
}
//# sourceMappingURL=MongoBinary.d.ts.map

@@ -92,2 +92,7 @@ "use strict";

}
/**
* Probe if the provided "systemBinary" is an existing path
* @param systemBinary The Path to probe for an System-Binary
* @return System Binary path or empty string
*/
MongoBinary.getSystemPath = function (systemBinary) {

@@ -106,3 +111,3 @@ return __awaiter(this, void 0, void 0, function () {

_a.sent();
log("MongoBinary: found sytem binary path at " + systemBinary);
log("MongoBinary: found system binary path at \"" + systemBinary + "\"");
binaryPath = systemBinary;

@@ -112,3 +117,3 @@ return [3 /*break*/, 4];

err_1 = _a.sent();
log("MongoBinary: can't find system binary at " + systemBinary + ". " + err_1.message);
log("MongoBinary: can't find system binary at \"" + systemBinary + "\".\n" + err_1.message);
return [3 /*break*/, 4];

@@ -120,9 +125,14 @@ case 4: return [2 /*return*/, binaryPath];

};
/**
* Check if specified version already exists in the cache
* @param version The Version to check for
*/
MongoBinary.getCachePath = function (version) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.cache[version]];
});
});
return this.cache[version];
};
/**
* Probe download path and download the binary
* @param options Options Configuring which binary to download and to which path
* @returns The BinaryPath the binary has been downloaded to
*/
MongoBinary.getDownloadPath = function (options) {

@@ -135,29 +145,28 @@ return __awaiter(this, void 0, void 0, function () {

downloadDir = options.downloadDir, platform = options.platform, arch = options.arch, version = options.version, checkMD5 = options.checkMD5;
// create downloadDir if not exists
// create downloadDir
return [4 /*yield*/, mkdirp_1.default(downloadDir)];
case 1:
// create downloadDir if not exists
// create downloadDir
_c.sent();
lockfile = path_1.default.resolve(downloadDir, version + ".lock");
// wait lock
// wait to get a lock
// downloading of binaries may be quite long procedure
// that's why we are using so big wait/stale periods
return [4 /*yield*/, new Promise(function (resolve, reject) {
lockfile_1.default.lock(lockfile, {
wait: 120000,
wait: 1000 * 120,
pollPeriod: 100,
stale: 110000,
stale: 1000 * 110,
retries: 3,
retryWait: 100,
}, function (err) {
if (err) {
reject(err);
}
else {
resolve();
}
return err ? reject(err) : resolve();
});
})];
case 2:
// wait lock
// wait to get a lock
// downloading of binaries may be quite long procedure
// that's why we are using so big wait/stale periods
_c.sent();
if (!!this.cache[version]) return [3 /*break*/, 4];
if (!!this.getCachePath(version)) return [3 /*break*/, 4];
downloader = new MongoBinaryDownload_1.default({

@@ -176,10 +185,16 @@ downloadDir: downloadDir,

_c.label = 4;
case 4:
case 4:
// remove lock
return [4 /*yield*/, new Promise(function (res) {
lockfile_1.default.unlock(lockfile, function (err) {
log(err
? "MongoBinary: Error when removing download lock " + err
: "MongoBinary: Download lock removed");
res(); // we don't care if it was successful or not
});
})];
case 5:
// remove lock
lockfile_1.default.unlock(lockfile, function (err) {
log(err
? "MongoBinary: Error when removing download lock " + err
: "MongoBinary: Download lock removed");
});
return [2 /*return*/, this.cache[version]];
_c.sent();
return [2 /*return*/, this.getCachePath(version)];
}

@@ -189,9 +204,14 @@ });

};
/**
* Probe all supported paths for an binary and return the binary path
* @param opts Options configuring which binary to search for
* @throws {Error} if no valid BinaryPath has been found
* @return The first found BinaryPath
*/
MongoBinary.getPath = function (opts) {
var _a;
if (opts === void 0) { opts = {}; }
return __awaiter(this, void 0, void 0, function () {
var legacyDLDir, nodeModulesDLDir, defaultOptions, options, version, systemBinary, binaryPath, binaryVersion;
return __generator(this, function (_b) {
switch (_b.label) {
var legacyDLDir, nodeModulesDLDir, defaultOptions, options, binaryPath, binaryVersion;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:

@@ -215,14 +235,13 @@ legacyDLDir = path_1.default.resolve(os_1.default.homedir(), '.cache/mongodb-binaries');

systemBinary: resolve_config_1.default('SYSTEM_BINARY'),
checkMD5: resolve_config_1.envToBool((_a = resolve_config_1.default('MD5_CHECK')) !== null && _a !== void 0 ? _a : ''),
checkMD5: resolve_config_1.envToBool(resolve_config_1.default('MD5_CHECK')),
};
options = __assign(__assign({}, defaultOptions), opts);
log("MongoBinary options: " + JSON.stringify(options));
version = options.version, systemBinary = options.systemBinary;
log("MongoBinary options:", JSON.stringify(options, null, 2));
binaryPath = '';
if (!systemBinary) return [3 /*break*/, 2];
return [4 /*yield*/, this.getSystemPath(systemBinary)];
if (!options.systemBinary) return [3 /*break*/, 2];
return [4 /*yield*/, this.getSystemPath(options.systemBinary)];
case 1:
binaryPath = _b.sent();
binaryPath = _a.sent();
if (binaryPath) {
if (~binaryPath.indexOf(' ')) {
if (binaryPath.indexOf(' ') >= 0) {
binaryPath = "\"" + binaryPath + "\"";

@@ -234,25 +253,25 @@ }

.split(' ')[2];
if (version !== exports.LATEST_VERSION && version !== binaryVersion) {
if (options.version !== exports.LATEST_VERSION && options.version !== binaryVersion) {
// we will log the version number of the system binary and the version requested so the user can see the difference
log('MongoMemoryServer: Possible version conflict\n' +
(" SystemBinary version: " + binaryVersion + "\n") +
(" Requested version: " + version + "\n\n") +
(" Requested version: " + options.version + "\n\n") +
' Using SystemBinary!');
}
}
_b.label = 2;
_a.label = 2;
case 2:
if (!binaryPath) {
binaryPath = this.getCachePath(options.version);
}
if (!!binaryPath) return [3 /*break*/, 4];
return [4 /*yield*/, this.getCachePath(version)];
return [4 /*yield*/, this.getDownloadPath(options)];
case 3:
binaryPath = _b.sent();
_b.label = 4;
binaryPath = _a.sent();
_a.label = 4;
case 4:
if (!!binaryPath) return [3 /*break*/, 6];
return [4 /*yield*/, this.getDownloadPath(options)];
case 5:
binaryPath = _b.sent();
_b.label = 6;
case 6:
log("MongoBinary: Mongod binary path: " + binaryPath);
if (!binaryPath) {
throw new Error("MongoBinary.getPath: could not find an valid binary path! (Got: \"" + binaryPath + "\")");
}
log("MongoBinary: Mongod binary path: \"" + binaryPath + "\"");
return [2 /*return*/, binaryPath];

@@ -263,11 +282,2 @@ }

};
MongoBinary.hasValidBinPath = function (files) {
if (files.length === 1) {
return true;
}
else if (files.length > 1) {
return false;
}
return false;
};
MongoBinary.cache = {};

@@ -274,0 +284,0 @@ return MongoBinary;

@@ -83,3 +83,2 @@ "use strict";

var platform = _a.platform, arch = _a.arch, downloadDir = _a.downloadDir, version = _a.version, checkMD5 = _a.checkMD5;
var _b;
this.platform = platform !== null && platform !== void 0 ? platform : os_1.default.platform();

@@ -89,3 +88,3 @@ this.arch = arch !== null && arch !== void 0 ? arch : os_1.default.arch();

this.downloadDir = path_1.default.resolve(downloadDir || 'mongodb-download');
this.checkMD5 = checkMD5 !== null && checkMD5 !== void 0 ? checkMD5 : resolve_config_1.envToBool((_b = resolve_config_1.default('MD5_CHECK')) !== null && _b !== void 0 ? _b : '');
this.checkMD5 = checkMD5 !== null && checkMD5 !== void 0 ? checkMD5 : resolve_config_1.envToBool(resolve_config_1.default('MD5_CHECK'));
this.dlProgress = {

@@ -92,0 +91,0 @@ current: 0,

@@ -0,4 +1,15 @@

/**
* Set an Default value for an specific key
* Mostly only used internally (for the "global-x.x" packages)
* @param key The Key the default value should be assigned to
* @param value The Value what the default should be
*/
export declare function setDefaultValue(key: string, value: string): void;
export declare function reInitializePackageJson(directory?: string): void;
/**
* Find the nearest package.json for the provided directory
* @param directory Set an custom directory to search the config in (default: process.cwd())
*/
export declare function findPackageJson(directory?: string): void;
export declare const reInitializePackageJson: typeof findPackageJson;
/**
* Resolve "variableName" with a prefix of "ENV_CONFIG_PREFIX"

@@ -12,3 +23,3 @@ * @param variableName The variable to use

*/
export declare function envToBool(env: string): boolean;
export declare function envToBool(env?: string): boolean;
//# sourceMappingURL=resolve-config.d.ts.map

@@ -5,14 +5,16 @@ "use strict";

};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.envToBool = exports.reInitializePackageJson = exports.setDefaultValue = void 0;
exports.envToBool = exports.reInitializePackageJson = exports.findPackageJson = exports.setDefaultValue = void 0;
var camelcase_1 = __importDefault(require("camelcase"));
var find_package_json_1 = __importDefault(require("find-package-json"));
var debug_1 = __importDefault(require("debug"));
var log = debug_1.default('MongoMS:ResolveConfig');
var ENV_CONFIG_PREFIX = 'MONGOMS_';
var defaultValues = new Map();
function getPackageJson(directory) {
var pjIterator = find_package_json_1.default(directory);
return pjIterator.next().value;
}
/**
* Set an Default value for an specific key
* Mostly only used internally (for the "global-x.x" packages)
* @param key The Key the default value should be assigned to
* @param value The Value what the default should be
*/
function setDefaultValue(key, value) {

@@ -22,8 +24,16 @@ defaultValues.set(key, value);

exports.setDefaultValue = setDefaultValue;
var packageJson;
function reInitializePackageJson(directory) {
packageJson = getPackageJson(directory || process.cwd());
var packageJsonConfig = {};
/**
* Find the nearest package.json for the provided directory
* @param directory Set an custom directory to search the config in (default: process.cwd())
*/
function findPackageJson(directory) {
var _a, _b, _c;
var finderIterator = find_package_json_1.default(directory || process.cwd()).next();
log("Using package.json at \"" + finderIterator.filename + "\"");
packageJsonConfig = (_c = (_b = (_a = finderIterator.value) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.mongodbMemoryServer) !== null && _c !== void 0 ? _c : {};
}
exports.reInitializePackageJson = reInitializePackageJson;
reInitializePackageJson();
exports.findPackageJson = findPackageJson;
exports.reInitializePackageJson = findPackageJson; // TODO: remove this line on next minor version
findPackageJson();
/**

@@ -34,4 +44,4 @@ * Resolve "variableName" with a prefix of "ENV_CONFIG_PREFIX"

function resolveConfig(variableName) {
var _a, _b, _c, _d;
return ((_d = (_a = process.env["" + ENV_CONFIG_PREFIX + variableName]) !== null && _a !== void 0 ? _a : (_c = (_b = packageJson === null || packageJson === void 0 ? void 0 : packageJson.config) === null || _b === void 0 ? void 0 : _b.mongodbMemoryServer) === null || _c === void 0 ? void 0 : _c[camelcase_1.default(variableName)]) !== null && _d !== void 0 ? _d : defaultValues.get(variableName));
var _a, _b;
return ((_b = (_a = process.env["" + ENV_CONFIG_PREFIX + variableName]) !== null && _a !== void 0 ? _a : packageJsonConfig === null || packageJsonConfig === void 0 ? void 0 : packageJsonConfig[camelcase_1.default(variableName)]) !== null && _b !== void 0 ? _b : defaultValues.get(variableName));
}

@@ -44,9 +54,10 @@ exports.default = resolveConfig;

function envToBool(env) {
if (env === void 0) { env = ''; }
return ['1', 'on', 'yes', 'true'].indexOf(env.toLowerCase()) !== -1;
}
exports.envToBool = envToBool;
// enable debug "MONGOMS_DEBUG" is true
if (envToBool((_a = resolveConfig('DEBUG')) !== null && _a !== void 0 ? _a : '')) {
// enable debug if "MONGOMS_DEBUG" is true
if (envToBool(resolveConfig('DEBUG'))) {
debug_1.default.enable('MongoMS:*');
}
//# sourceMappingURL=resolve-config.js.map
{
"name": "mongodb-memory-server-core",
"version": "6.7.5",
"version": "6.7.6",
"description": "MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.",

@@ -39,3 +39,2 @@ "main": "lib/index",

"@types/find-package-json": "^1.1.1",
"@types/jest": "26.0.13",
"@types/lockfile": "^1.0.1",

@@ -45,18 +44,6 @@ "@types/md5-file": "^4.0.2",

"@types/mongodb": "3.5.27",
"@types/semver": "^7.3.3",
"@types/semver": "7.3.4",
"@types/tar-stream": "^2.1.0",
"@types/uuid": "^8.0.0",
"@types/yauzl": "^2.9.1",
"@typescript-eslint/eslint-plugin": "4.1.0",
"@typescript-eslint/parser": "4.1.0",
"cross-env": "^7.0.2",
"eslint": "7.8.1",
"eslint-config-prettier": "6.11.0",
"flowgen": "^1.10.0",
"jest": "26.4.2",
"lerna": "3.22.1",
"mongodb": "3.5.4",
"rimraf": "^3.0.2",
"ts-jest": "26.3.0",
"typescript": "4.0.2"
"@types/yauzl": "^2.9.1"
},

@@ -63,0 +50,0 @@ "dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc