-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: native TypeScript support (#80) thanks @jloveridge
* chore(types): add TypeScript declarations, ported from Flow * chore(tsconfig, tslint): add TypeScript and TSLint, and configure * chore(package): add commands to lint TypeScript files, type-check, and export declaration files to package. * docs(readme): add a badge to signal TypeScript compatibility. * chore(package): reference the declaration files entry point
- Loading branch information
1 parent
2ca96f5
commit edfa536
Showing
11 changed files
with
249 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/// <reference types='node' /> | ||
|
||
import { ChildProcess } from 'child_process'; | ||
import MongoInstance from './util/MongoInstance'; | ||
|
||
export interface MongoMemoryServerOptsT { | ||
instance: { | ||
port?: number; | ||
dbPath?: string; | ||
dbName?: string; | ||
storageEngine?: string; | ||
debug?: boolean | ((...args: any[]) => any); | ||
}; | ||
binary: { | ||
version?: string; | ||
downloadDir?: string; | ||
platform?: string; | ||
arch?: string; | ||
debug?: boolean | ((...args: any[]) => any); | ||
}; | ||
debug?: boolean; | ||
spawn: any; | ||
autoStart?: boolean; | ||
} | ||
|
||
export interface MongoInstanceDataT { | ||
port: number; | ||
dbPath: string; | ||
dbName: string; | ||
uri: string; | ||
storageEngine: string; | ||
instance: MongoInstance; | ||
childProcess: ChildProcess; | ||
tmpDir?: { | ||
name: string; | ||
removeCallback: ((...args: any[]) => any); | ||
}; | ||
} | ||
|
||
export default class MongoMemoryServer { | ||
isRunning: boolean; | ||
runningInstance: Promise<MongoInstanceDataT> | undefined; | ||
opts: MongoMemoryServerOptsT; | ||
debug: ((...args: any[]) => any); | ||
|
||
constructor(opts?: Partial<MongoMemoryServerOptsT>); | ||
|
||
start(): Promise<boolean>; | ||
stop(): Promise<boolean>; | ||
getInstanceData(): Promise<MongoInstanceDataT>; | ||
getUri(otherDbName?: string | boolean): Promise<string>; | ||
getConnectionString(otherDbName?: string | boolean): Promise<string>; | ||
getPort(): Promise<number>; | ||
getDbPath(): Promise<string>; | ||
getDbName(): Promise<string>; | ||
|
||
protected _startUpInstance(): Promise<MongoInstanceDataT>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import MongoBinary from './util/MongoBinary'; | ||
import MongoInstance from './util/MongoInstance'; | ||
import MongoMemoryServer from './MongoMemoryServer'; | ||
|
||
export default MongoMemoryServer; | ||
export { MongoBinary, MongoInstance, MongoMemoryServer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface MongoBinaryCache { | ||
[version: string]: string; | ||
} | ||
|
||
export interface MongoBinaryOpts { | ||
version?: string; | ||
downloadDir?: string; | ||
platform?: string; | ||
arch?: string; | ||
debug?: boolean | ((...args: any[]) => any); | ||
} | ||
|
||
// disable error for a class with all static functions, | ||
// so the TypeScript declaration would map the implementation with flow types for easier support. | ||
// tslint:disable-next-line:no-unnecessary-class | ||
export default class MongoBinary { | ||
static cache: MongoBinaryCache; | ||
|
||
static getPath(opts?: MongoBinaryOpts): Promise<string>; | ||
static hasValidBinPath(files: string[]): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export interface MongoBinaryDownloadOpts { | ||
version: string; | ||
downloadDir: string; | ||
platform: string; | ||
arch: string; | ||
debug?: boolean | Function; | ||
} | ||
|
||
interface dlProgress { // tslint:disable-line | ||
current: number; | ||
length: number; | ||
totalMb: number; | ||
lastPrintedAt: number; | ||
} | ||
|
||
export default class MongoBinaryDownload { | ||
debug: Function; | ||
dlProgress: dlProgress; | ||
|
||
downloadDir: string; | ||
arch: string; | ||
version: string; | ||
platform: string; | ||
|
||
constructor(opts: MongoBinaryDownloadOpts); | ||
getMongodPath(): Promise<string>; | ||
startDownload(): Promise<string>; | ||
checkMd5(mongoDBArchiveMd5: string, mongoDBArchive: string): Promise<void>; | ||
download(downloadUrl: string): Promise<string>; | ||
extract(mongoDBArchive: string): Promise<string>; | ||
httpDownload( | ||
httpOptions: any, // tslint:disable-line:no-any | ||
downloadLocation: string, | ||
tempDownloadLocation: string | ||
): Promise<string>; | ||
printDownloadProgress(chunk: any): void; // tslint:disable-line:no-any | ||
locationExists(location: string): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// <reference types='getos' /> | ||
|
||
import {Os as OS} from 'getos'; | ||
|
||
export interface MongoBinaryDownloadUrlOpts { | ||
version: string; | ||
platform: string; | ||
arch: string; | ||
os?: OS; // getos() result | ||
} | ||
|
||
export default class MongoBinaryDownloadUrl { | ||
constructor(opts: MongoBinaryDownloadUrlOpts); | ||
getDownloadUrl(): Promise<string>; | ||
getArchiveName(): Promise<string>; | ||
getArchiveNameWin(): Promise<string>; | ||
getArchiveNameOsx(): Promise<string>; | ||
getArchiveNameLinux(): Promise<string>; | ||
getos(): Promise<OS>; | ||
getLinuxOSVersionString(os: OS): string; | ||
getDebianVersionString(os: OS): string; | ||
getFedoraVersionString(os: OS): string; | ||
getRhelVersionString(os: OS): string; | ||
getElementaryOSVersionString(os: OS): string; | ||
getLegacyVersionString(os: OS): string; | ||
getSuseVersionString(os: any): string; | ||
getUbuntuVersionString(os: OS): string; | ||
translatePlatform(platform: string): string; | ||
translateArch(arch: string, mongoPlatform: string): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/// <reference types='node' /> | ||
|
||
import { ChildProcess } from 'child_process'; | ||
import { MongoBinaryOpts } from './MongoBinary'; | ||
|
||
export interface MongodOps { | ||
// instance options | ||
instance: { | ||
port: number; | ||
storageEngine?: string; | ||
dbPath: string; | ||
debug?: boolean | ((...args: any[]) => any); | ||
}; | ||
|
||
// mongo binary options | ||
binary?: MongoBinaryOpts; | ||
|
||
// child process spawn options | ||
spawn?: { | ||
cwd?: string; | ||
env?: object; | ||
argv0?: string; | ||
stdio?: string | any[]; | ||
detached?: boolean; | ||
uid?: number; | ||
gid?: number; | ||
shell?: boolean | string; | ||
}; | ||
|
||
debug?: boolean | ((...args: any[]) => any); | ||
} | ||
|
||
export default class MongodbInstance { | ||
static childProcessList: ChildProcess[]; | ||
|
||
opts: MongodOps; | ||
debug: ((...args: any[]) => any); | ||
childProcess: ChildProcess; | ||
killerProcess: ChildProcess; | ||
instanceReady: ((...args: any[]) => any); | ||
instanceFailed: ((...args: any[]) => any); | ||
|
||
constructor(opts: MongodOps); | ||
|
||
static run(opts: MongodOps): Promise<MongodbInstance>; | ||
prepareCommandArgs(): string[]; | ||
run(): Promise<MongodbInstance>; | ||
kill(): Promise<MongodbInstance>; | ||
getPid(): number | undefined; | ||
errorHandler(err: string): void; | ||
closeHandler(code: number): void; | ||
stderrHandler(message: string | Buffer): void; | ||
stdoutHandler(message: string | Buffer): void; | ||
|
||
private _launchMongod(mongoBin: string): ChildProcess; | ||
private _launchKiller(parentPid: number, childPid: number): ChildProcess; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"strict": true, | ||
"rootDir": ".", | ||
"declaration": true, | ||
"lib": ["es2017", "esnext.asynciterable"] | ||
}, | ||
"include": [ "src/**/*.d.ts" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"extends": "tslint:recommended", | ||
"jsRules": {}, | ||
"rules": { | ||
"ban-types": [true, ["Object", "Use {} instead."], ["String"]], | ||
"quotemark": [true, "single"], | ||
"trailing-comma": [false], | ||
"ordered-imports": false, | ||
"member-access": false, | ||
"member-ordering": [true, { "order": "fields-first" }], | ||
"variable-name": false, | ||
"interface-name": false, | ||
"no-reference-import": false | ||
} | ||
} |