@noego/proper 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/index.d.ts ADDED
@@ -0,0 +1,179 @@
1
+ import mysql from 'mysql2/promise';
2
+
3
+ interface MigrationConfig {
4
+ config_file?: string;
5
+ migration_table: string;
6
+ migration_folder: string;
7
+ database: string;
8
+ sql?: {
9
+ host: string;
10
+ user: string;
11
+ database: string;
12
+ password?: string;
13
+ port?: number;
14
+ };
15
+ sqlite?: {
16
+ database: string;
17
+ };
18
+ seeds?: {
19
+ migrationsDir?: string;
20
+ dataDir?: string;
21
+ list?: string[];
22
+ };
23
+ }
24
+
25
+ interface MigrationStatus {
26
+ completed: boolean;
27
+ }
28
+
29
+ interface ISQLRunner {
30
+ query(sql: string, params?: any[]): Promise<any>;
31
+ execute(sql: string, params?: any[]): Promise<any>;
32
+ end(): Promise<void>;
33
+ }
34
+
35
+ declare abstract class MigrationNode {
36
+ name: string;
37
+ constructor(name?: string);
38
+ abstract get_key(): string;
39
+ abstract status(): Promise<MigrationStatus>;
40
+ abstract up(): Promise<void>;
41
+ abstract down(): Promise<void>;
42
+ abstract up_sql(): string;
43
+ abstract down_sql(): string;
44
+ }
45
+ declare class SqlMigrationNode extends MigrationNode {
46
+ private conn;
47
+ private table;
48
+ private key;
49
+ private up_file;
50
+ private sql_up;
51
+ private down_file;
52
+ private sql_down;
53
+ up_sql(): string;
54
+ down_sql(): string;
55
+ get_key(): string;
56
+ constructor(conn: ISQLRunner, table: string, key: string, up_file: string, sql_up: string, down_file: string, sql_down: string);
57
+ status(): Promise<MigrationStatus>;
58
+ up(): Promise<void>;
59
+ down(): Promise<void>;
60
+ }
61
+
62
+ declare class SqlMigrationBuilder {
63
+ private key;
64
+ private up;
65
+ private up_file;
66
+ private down;
67
+ private down_file;
68
+ constructor(key: string);
69
+ set_up(file: string, up: string): void;
70
+ set_down(file: string, down: string): void;
71
+ build(table: string, conn: ISQLRunner): SqlMigrationNode;
72
+ }
73
+
74
+ declare class MigrationDirectoryReader {
75
+ private directory;
76
+ private read_strategy;
77
+ private sqlrunner;
78
+ private dialect;
79
+ constructor(directory: string, read_strategy: any, sqlrunner: ISQLRunner, dialect?: 'sql' | 'sqlite');
80
+ /**
81
+ * Resolves the appropriate file for a migration based on dialect.
82
+ * Priority: dialect-specific file > generic file
83
+ */
84
+ private resolveFile;
85
+ /**
86
+ * Checks if a file path is dialect-specific (contains .mysql. or .sqlite. in the name)
87
+ */
88
+ private isDialectSpecific;
89
+ loadMigrations(table: string, connection: any): MigrationNode[];
90
+ loadMigration(builder: SqlMigrationBuilder, file: string): SqlMigrationBuilder;
91
+ sql_up(file: string): string;
92
+ sql_down(file: string): string;
93
+ }
94
+
95
+ declare class MigrationSetup {
96
+ private sqlrunner;
97
+ private config;
98
+ constructor(sqlrunner: ISQLRunner, config: MigrationConfig);
99
+ setup(): Promise<void>;
100
+ teardown(): Promise<void>;
101
+ }
102
+
103
+ declare function loadMigrationConfig(configFile: string): MigrationConfig;
104
+ declare class MigrationRunnerFactory {
105
+ private static isSQLRunner;
106
+ static create(configFile: string, conn?: any): Promise<MySQLMigrationRunner>;
107
+ static createConnection(config: MigrationConfig): Promise<any>;
108
+ static createEmpty(configFile: string): Promise<MySQLMigrationRunner>;
109
+ create(config: MigrationConfig, conn: any): Promise<MySQLMigrationRunner>;
110
+ createEmpty(config: MigrationConfig): Promise<MySQLMigrationRunner>;
111
+ private getReadStategy;
112
+ }
113
+ interface MigrationHistory {
114
+ name: string;
115
+ up: string;
116
+ down: string;
117
+ }
118
+ interface IMigrationRunner {
119
+ setup(): Promise<void>;
120
+ terminate(): Promise<void>;
121
+ getMigrationsHistory(): Promise<MigrationHistory[]>;
122
+ getMigrations(): Promise<MigrationNode[]>;
123
+ getPendingMigrations(): Promise<MigrationNode[]>;
124
+ getCompletedMigrations(): Promise<MigrationNode[]>;
125
+ migrate(migrationNodes: MigrationNode[], forward: boolean): Promise<void>;
126
+ reset(): Promise<void>;
127
+ createMigration(name: string): void;
128
+ close(): Promise<void>;
129
+ init(config_file: string): Promise<void>;
130
+ query(sql: string, params?: any[]): Promise<any>;
131
+ }
132
+ declare class MySQLMigrationRunner implements IMigrationRunner {
133
+ private config;
134
+ private directory;
135
+ private setupRunner;
136
+ private sqlrunner;
137
+ private connection;
138
+ constructor(config: MigrationConfig, directory: MigrationDirectoryReader, setupRunner: MigrationSetup, sqlrunner: ISQLRunner, connection: mysql.Connection);
139
+ setup(): Promise<void>;
140
+ terminate(): Promise<void>;
141
+ getMigrationsHistory(): Promise<MigrationHistory[]>;
142
+ getMigrations(): Promise<MigrationNode[]>;
143
+ getPendingMigrations(): Promise<MigrationNode[]>;
144
+ getCompletedMigrations(): Promise<MigrationNode[]>;
145
+ migrate(migrationNodes: MigrationNode[], forward: boolean): Promise<void>;
146
+ reset(): Promise<void>;
147
+ createMigration(name: string): void;
148
+ close(): Promise<void>;
149
+ query(sql: string, params?: any[]): Promise<any>;
150
+ init(config_file: string): Promise<void>;
151
+ }
152
+
153
+ type SeedTransactionalMode = 'runner' | 'seed' | 'none';
154
+ type SeedOptions = {
155
+ migrationsDir?: string;
156
+ dataDir?: string;
157
+ validate?: boolean;
158
+ transactional?: SeedTransactionalMode;
159
+ aliasMap?: Record<string, string>;
160
+ preloadedData?: Record<string, unknown>;
161
+ log?: (msg: string) => void;
162
+ names?: string[];
163
+ };
164
+ type SeedContext = {
165
+ data: unknown;
166
+ log?: (msg: string) => void;
167
+ dialect: string;
168
+ };
169
+ declare function runSeedsWithRunner(runner: IMigrationRunner, migrationConfig: MigrationConfig, direction: 'up' | 'down', options: SeedOptions): Promise<void>;
170
+ type SeedFactoryOptions = SeedOptions & {
171
+ configFile?: string;
172
+ };
173
+ type SeedFactory = {
174
+ up(names?: string[]): Promise<void>;
175
+ down(names?: string[]): Promise<void>;
176
+ };
177
+ declare function createSeedFactory(options: SeedFactoryOptions): SeedFactory;
178
+
179
+ export { type MigrationConfig, MySQLMigrationRunner as MigrationRunner, MigrationRunnerFactory, type SeedContext, type SeedFactory, type SeedFactoryOptions, createSeedFactory, loadMigrationConfig, runSeedsWithRunner };