fix: modified uri parsing for mongodb (#2282)

This commit is contained in:
Wyatt Johnson
2019-04-25 15:16:36 +00:00
committed by GitHub
parent 205e6fcd08
commit a91de05af9
4 changed files with 48 additions and 9 deletions
+14 -3
View File
@@ -18818,6 +18818,17 @@
"safe-buffer": "^5.1.2"
},
"dependencies": {
"mongodb-core": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.1.tgz",
"integrity": "sha512-vvnl5F6QhvFhi28umNx+Ymyb8wVQOhvEjU30JF3TjBBomS2tamJFK4eA0uwOa6FxLi9qCQWejbF66B0rb/UUiw==",
"requires": {
"bson": "^1.1.1",
"require_optional": "^1.0.1",
"safe-buffer": "^5.1.2",
"saslprep": "^1.0.0"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
@@ -18826,9 +18837,9 @@
}
},
"mongodb-core": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.1.tgz",
"integrity": "sha512-vvnl5F6QhvFhi28umNx+Ymyb8wVQOhvEjU30JF3TjBBomS2tamJFK4eA0uwOa6FxLi9qCQWejbF66B0rb/UUiw==",
"version": "3.2.3",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.3.tgz",
"integrity": "sha512-UyI0rmvPPkjOJV8XGWa9VCTq7R4hBVipimhnAXeSXnuAPjuTqbyfA5Ec9RcYJ1Hhu+ISnc8bJ1KfGZd4ZkYARQ==",
"requires": {
"bson": "^1.1.1",
"require_optional": "^1.0.1",
+1
View File
@@ -94,6 +94,7 @@
"metascraper-image": "^3.11.8",
"metascraper-title": "^3.11.8",
"mongodb": "^3.2.1",
"mongodb-core": "^3.2.3",
"ms": "^2.1.1",
"node-fetch": "^2.2.0",
"nodemailer": "^4.6.7",
+8 -6
View File
@@ -1,19 +1,21 @@
import convict from "convict";
import Joi from "joi";
import { parseConnectionString } from "mongodb-core";
import os from "os";
import { LOCALES } from "talk-common/helpers/i18n/locales";
import { InternalError } from "./errors";
// Add custom format for the mongo uri scheme.
convict.addFormat({
name: "mongo-uri",
validate: (url: string) => {
Joi.assert(
url,
Joi.string().uri({
scheme: ["mongodb"],
})
);
parseConnectionString(url, err => {
if (err) {
throw new InternalError(err, "invalid mongo-uri");
}
});
},
});
+25
View File
@@ -0,0 +1,25 @@
declare module "mongodb-core" {
export interface ParsedConnectionString {
hosts: string[];
auth: {};
options: {};
}
export interface ParseConnectionStringOptions {
/**
* Whether the parser should translate options back into camelCase after normalization.
*/
caseTranslate?: boolean;
}
/** https://github.com/mongodb-js/mongodb-core/blob/master/lib/uri_parser.js */
export function parseConnectionString(
uri: string,
options?: ParseConnectionStringOptions,
callback?: (error: Error, result: ParsedConnectionString) => void
): void;
export function parseConnectionString(
uri: string,
callback?: (error: Error, result: ParsedConnectionString) => void
): void;
}