forked from lukeed/ley
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ley.d.ts
75 lines (64 loc) · 2.02 KB
/
ley.d.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
68
69
70
71
72
73
74
75
declare namespace Options {
declare type Config = Record<string, unknown>;
declare type Resolver = Promise<Config> | (() => Config);
declare interface Base {
cwd?: string;
driver?: string | Driver;
require?: string | string[];
config?: Config | Resolver;
dir?: string;
}
declare interface Up extends Base {
single?: boolean;
}
declare interface Down extends Base {
all?: boolean;
}
declare interface New extends Base {
filename: string;
timestamp?: boolean;
length?: number;
esm?: boolean;
}
}
declare class MigrationError extends Error {
readonly migration: Record<'name'|'abs', string>;
}
declare namespace Migration {
type Method = 'up' | 'down';
type Existing = Pick<File, 'name'>;
interface File {
/** The absolute file path */
abs: string;
/** The relative file path from `opts.dir` */
name: string;
}
}
export declare class Driver<Client = unknown> {
/**
* Create a new Client connection using supplied options/config.
* @important Must return the `Client` for further usage.
*/
connect<Client>(config: Options.Config): Promise<Client> | Client;
/**
* Create `migrations` table and query for existing/applied migrations.
* @note You may `require('ley/lib/text')` for premade SQL-like queries.
* @important Must return the `name` of any existing migrations.
*/
setup(client: Client): Promise<Migration.Existing[]>;
/**
* Loop `files` and apply the target `method` action.
* @note Whenever possible, *all* files should partake in the same transaction.
*/
loop(client: Client, files: Migration.File[], method: Migration.Method): Promise<void>;
/**
* Gracefully terminate your client.
* Runs after *all* migrations have been applied, or after an error is thrown.
*/
end(client: Client): Promise<void> | void;
}
export function up(opts?: Options.Up): Promise<string[]>;
export function down(opts?: Options.Down): Promise<string[]>;
export function status(opts?: Options.Base): Promise<string[]>;
declare function n(opts?: Options.New): Promise<string>;
export { n as new };