-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic-types.ts
67 lines (59 loc) · 1.74 KB
/
public-types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Pool } from "pg"
import { JsonObject } from "type-fest"
import { BindMode, ExecResult } from "testcontainers/dist/docker/types"
import { StartedNetwork } from "testcontainers"
export interface ConnectionDetails {
connectionString: string
connectionStringDocker: string
networkDocker: StartedNetwork
host: string
port: number
username: string
password: string
database: string
pool: Pool
}
export interface GetTestPostgresDatabaseFactoryOptions<
Params extends JsonObject
> {
/**
* Any tag of the official `postgres` image.
*/
postgresVersion?: string
container?: {
bindMounts?: {
source: string
target: string
mode?: BindMode
}[]
}
/**
* Test workers will be de-duped by this key. You probably don't need to set this.
*/
key?: string
beforeTemplateIsBaked?: (options: {
connection: ConnectionDetails
params: Params
containerExec: (command: string[]) => Promise<ExecResult>
}) => Promise<any>
}
export interface GetTestPostgresDatabaseResult extends ConnectionDetails {
beforeTemplateIsBakedResult: any
}
export type GetTestPostgresDatabaseOptions = {
/**
* If `getTestPostgresDatabase()` is called multiple times with the same `key` and `params`, the same database is guaranteed to be returned.
*/
key?: string
}
// https://github.com/microsoft/TypeScript/issues/23182#issuecomment-379091887
type IsNeverType<T> = [T] extends [never] ? true : false
export type GetTestPostgresDatabase<Params> = IsNeverType<Params> extends true
? (
args?: null,
options?: GetTestPostgresDatabaseOptions
) => Promise<GetTestPostgresDatabaseResult>
: (
args: Params,
options?: GetTestPostgresDatabaseOptions
) => Promise<GetTestPostgresDatabaseResult>