mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
Add-Type: mongodb-uri 0.9, https://github.com/mongolab/mongodb-uri-node (#27013)
* chore: initial commit * feat(mongodb-uri): add types for mongodb-uri * refactor(mongodb-uri): adjust to pass lint test * Revert "chore: initial commit" This reverts commit 51dab6d
This commit is contained in:
parent
c24807a001
commit
592acfc14d
101
types/mongodb-uri/index.d.ts
vendored
Normal file
101
types/mongodb-uri/index.d.ts
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
// Type definitions for mongodb-uri 0.9
|
||||
// Project: https://github.com/mongolab/mongodb-uri-node
|
||||
// Definitions by: mernxl <https://github.com/mernxl>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface Host {
|
||||
host: string;
|
||||
port?: number;
|
||||
}
|
||||
|
||||
export interface parserOptions {
|
||||
scheme: string;
|
||||
}
|
||||
|
||||
export interface UriObject {
|
||||
scheme: string;
|
||||
hosts: Host[];
|
||||
|
||||
username?: string;
|
||||
password?: string;
|
||||
database?: string;
|
||||
options?: any;
|
||||
}
|
||||
|
||||
export class MongodbUriParser {
|
||||
constructor(options?: parserOptions);
|
||||
|
||||
/**
|
||||
* Takes a URI of the form:
|
||||
*
|
||||
* mongodb://[username[:password]@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database]][?options]
|
||||
*
|
||||
* scheme and hosts will always be present. Other fields will only be present in the result if they were
|
||||
* present in the input.
|
||||
*/
|
||||
parse(uri: string): UriObject;
|
||||
|
||||
/**
|
||||
* Takes a URI object and returns a URI string of the form:
|
||||
*
|
||||
* mongodb://[username[:password]@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database]][?options]
|
||||
*
|
||||
*/
|
||||
format(uriObject?: UriObject): string;
|
||||
|
||||
/**
|
||||
* Takes either a URI object or string and returns a Mongoose connection string. Specifically, instead of listing all
|
||||
* hosts and ports in a single URI, a Mongoose connection string contains a list of URIs each with a single host and
|
||||
* port pair.
|
||||
*
|
||||
* Useful in environments where a MongoDB URI environment variable is provided, but needs to be programmatically
|
||||
* transformed into a string digestible by mongoose.connect()--for example, when deploying to a PaaS like Heroku
|
||||
* using a MongoDB add-on like MongoLab.
|
||||
*
|
||||
*/
|
||||
formatMongoose(uri: UriObject | string): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a URI of the form:
|
||||
*
|
||||
* mongodb://[username[:password]@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database]][?options]
|
||||
*
|
||||
* and returns an object of the form:
|
||||
*
|
||||
* {
|
||||
* scheme: !String,
|
||||
* username: String=,
|
||||
* password: String=,
|
||||
* hosts: [ { host: !String, port: Number= }, ... ],
|
||||
* database: String=,
|
||||
* options: Object=
|
||||
* }
|
||||
*
|
||||
* scheme and hosts will always be present. Other fields will only be present in the result if they were
|
||||
* present in the input.
|
||||
*
|
||||
*/
|
||||
export function parse(uri: string): UriObject;
|
||||
|
||||
/**
|
||||
* Takes a URI object and returns a URI string of the form:
|
||||
*
|
||||
* mongodb://[username[:password]@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database]][?options]
|
||||
*
|
||||
* @param uriObject
|
||||
*/
|
||||
export function format(uriObject?: UriObject): string;
|
||||
|
||||
/**
|
||||
* Takes either a URI object or string and returns a Mongoose connection string. Specifically, instead of listing all
|
||||
* hosts and ports in a single URI, a Mongoose connection string contains a list of URIs each with a single host and
|
||||
* port pair.
|
||||
*
|
||||
* Useful in environments where a MongoDB URI environment variable is provided, but needs to be programmatically
|
||||
* transformed into a string digestible by mongoose.connect()--for example, when deploying to a PaaS like Heroku
|
||||
* using a MongoDB add-on like MongoLab.
|
||||
*
|
||||
* @param uri
|
||||
*/
|
||||
export function formatMongoose(uri: UriObject | string): string;
|
||||
12
types/mongodb-uri/mongodb-uri-tests.ts
Normal file
12
types/mongodb-uri/mongodb-uri-tests.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { format, formatMongoose, MongodbUriParser, parse } from 'mongodb-uri';
|
||||
|
||||
const urlString = 'mongodb://localhost';
|
||||
const parser = new MongodbUriParser();
|
||||
|
||||
const parsed1 = parser.parse(urlString);
|
||||
const urlString1 = parser.format(parsed1);
|
||||
const formatMongoose1 = parser.formatMongoose(parsed1);
|
||||
|
||||
const parsed2 = parse(urlString);
|
||||
const urlString2 = format(parsed2);
|
||||
const formatMongoose2 = formatMongoose(parsed2);
|
||||
23
types/mongodb-uri/tsconfig.json
Normal file
23
types/mongodb-uri/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"mongodb-uri-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/mongodb-uri/tslint.json
Normal file
1
types/mongodb-uri/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user