UNPKG

mongodb-memory-server-core

Version:

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.

136 lines 5.2 kB
/// <reference types="node" /> import { ChildProcess } from 'child_process'; import { AutomaticAuth } from '../MongoMemoryServer'; import { Stats } from 'fs'; import { LinuxOS } from './getos'; /** * This is here, because NodeJS does not have a FSError type */ interface ErrorWithCode extends Error { code: string; } /** * This is here, because NodeJS does not have a FSError type * @param err Value to check agains * @returns `true` if it is a error with code, `false` if not */ export declare function errorWithCode(err: unknown): err is ErrorWithCode; /** * Return input or default database * @param {string} dbName */ export declare function generateDbName(dbName?: string): string; /** * Extracts the host and port information from a mongodb URI string. * @param {string} uri mongodb URI */ export declare function getHost(uri: string): string; /** * Basic MongoDB Connection string * @param host the host ip or an list of hosts * @param port the host port or undefined if "host" is an list of hosts * @param dbName the database to add to the uri (in mongodb its the auth database, in mongoose its the default database for models) * @param query extra uri-query options (joined with "&") */ export declare function uriTemplate(host: string, port: number | undefined, dbName: string, query?: string[]): string; /** * Because since node 4.0.0 the internal util.is* functions got deprecated * @param val Any value to test if null or undefined */ export declare function isNullOrUndefined(val: unknown): val is null | undefined; /** * Assert an condition, if "false" throw error * Note: it is not named "assert" to differentiate between node and jest types * @param cond The Condition to throw * @param error An Custom Error to throw */ export declare function assertion(cond: unknown, error?: Error): asserts cond; /** * Kill an ChildProcess * @param childprocess The Process to kill * @param name the name used in the logs * @param mongodPort the port for the mongod process (for easier logging) */ export declare function killProcess(childprocess: ChildProcess, name: string, mongodPort?: number): Promise<void>; /** * Check if the given Process is still alive * @param {number} pid The Process PID */ export declare function isAlive(pid?: number): boolean; /** * Call "process.nextTick" to ensure an function is exectued directly after all code surrounding it * look at the following link to get to know on why this needed: https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#process-nexttick (read full documentation) */ export declare function ensureAsync(): Promise<void>; /** * Convert Partitial input into full-defaulted output * @param opts Partitial input options */ export declare function authDefault(opts: AutomaticAuth): Required<AutomaticAuth>; /** * Run "fs.promises.stat", but return "undefined" if error is "ENOENT" or "EACCES" * follows symlinks * @param path The Path to Stat * @throws if the error is not "ENOENT" or "EACCES" */ export declare function statPath(path: string): Promise<Stats | undefined>; /** * Like "fs.existsSync" but async * uses "utils.statPath" * follows symlinks * @param path The Path to check for */ export declare function pathExists(path: string): Promise<boolean>; /** * Try to read an release file path and apply an parser to the output * @param path The Path to read for an release file * @param parser An function to parse the output of the file */ export declare function tryReleaseFile(path: string, parser: (output: string) => LinuxOS | undefined): Promise<LinuxOS | undefined>; /** * Cleanup interface to provide easy to understand arguments for clean-up */ export interface Cleanup { /** * Setting this to `true` will activate cleanup * @default true */ doCleanup?: boolean; /** * Setting this to `true` will cleanup the directory even if it is *not* a temporary directory * @default false */ force?: boolean; } /** * This Class is used to have unified types for base-manager functions */ export declare abstract class ManagerBase { abstract start(forceSamePort: boolean): Promise<void>; abstract start(): Promise<void>; /** @deprecated replace argument with `Cleanup` interface object */ abstract stop(cleanup: boolean): Promise<boolean>; abstract stop(cleanup: Cleanup): Promise<boolean>; } /** * This Class is used to have unified types for advanced-manager functions */ export declare abstract class ManagerAdvanced extends ManagerBase { abstract getUri(otherDB?: string | boolean): string; /** @deprecated replace argument with `Cleanup` interface object */ abstract cleanup(force: boolean): Promise<void>; abstract cleanup(cleanup: Cleanup): Promise<void>; } /** * Check that the Binary has sufficient Permissions to be executed * @param path The Path to check */ export declare function checkBinaryPermissions(path: string): Promise<void>; /** * Make Directory, wrapper for native mkdir with recursive true * @param path The Path to create * @returns Nothing */ export declare function mkdir(path: string): Promise<void>; export {}; //# sourceMappingURL=utils.d.ts.map