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
+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;
}