forked from halvardssm/deno-nessie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
110 lines (98 loc) · 3.34 KB
/
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import type { AbstractClient } from "./clients/AbstractClient.ts";
import { DB_DIALECTS } from "./consts.ts";
/** Supported dialects */
export type DBDialects = DB_DIALECTS | string;
/** Exposed object in migration files. available in `up`/`down` methods.
* queryBuilder is available when passing `exposeQueryBuilder: true` to the config file.
*/
export type Info<T = undefined> = {
dialect: DBDialects;
};
/** Logger function. */
// deno-lint-ignore no-explicit-any
export type LoggerFn = (output?: any, title?: string) => void;
/** Handy type to cover printf. */
export type QueryWithString = (string: string) => string;
/** Amount type for migrations. */
export type AmountMigrateT = number | undefined;
/** Amount type for rollbacks. */
export type AmountRollbackT = AmountMigrateT | "all";
/** Query type. */
export type QueryT = string | string[];
/** Query handler function. */
// deno-lint-ignore no-explicit-any
export type QueryHandler = (query: QueryT) => Promise<any>;
/** Nessie config options. */
export interface NessieConfig {
/** Can be any class which extends `AbstractClient`. */
// deno-lint-ignore no-explicit-any
client: AbstractClient<any>;
/**
* The folders where migration files are located.
* Can be a relative path or an absolute path.
* Defaults to ['./db/migrations/'] if additionalMigrationFiles is not populated
*/
migrationFolders?: string[];
/**
* The folders where seed files are located.
* Can be a relative path or an absolute path.
* Defaults to ['./db/seeds/'] if additionalSeedFiles is not populated
*/
seedFolders?: string[];
/**
* Additional migration files which will be added to the
* list to parse when running the migrate or rollback command.
* Can be any format supported by `import()` e.g. url or path
*/
additionalMigrationFiles?: string[];
/**
* Additional seed files which will be added to the list to
* match against when running the seed command.
* Can be any format supported by `import()` e.g. url or path
*/
additionalSeedFiles?: string[];
/** Custom migration template, can be path or url. When also using the CLI flag `--migrationTemplate`, it will have precidence. */
migrationTemplate?: string;
/** Custom seed template, can be path or url. When also using the CLI flag `--seedTemplate`, it will have precidence. */
seedTemplate?: string;
/** Enables verbose output for debugging */
debug?: boolean;
}
export interface AbstractClientOptions<Client> {
client: Client;
}
export type FileEntryT = {
name: string;
path: string;
};
export type CommandOptions = {
debug: boolean;
config: string;
};
export interface CommandOptionsInit extends CommandOptions {
mode?: "config" | "folders";
dialect?: DB_DIALECTS;
}
export interface CommandOptionsStatus extends CommandOptions {
fileNames?: boolean;
output?: "log" | "json";
}
export interface CommandOptionsMakeSeed extends CommandOptions {
seedTemplate?: string;
}
export interface CommandOptionsMakeMigration extends CommandOptions {
migrationTemplate?: string;
}
export type AllCommandOptions =
& CommandOptionsInit
& CommandOptionsStatus
& CommandOptionsMakeSeed
& CommandOptionsMakeMigration;
export interface StateOptions {
debug: boolean;
config: NessieConfig;
migrationFolders: string[];
seedFolders: string[];
migrationFiles: FileEntryT[];
seedFiles: FileEntryT[];
}