sqlmorpheus 1.0.0 → 1.0.1

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/dist/index.d.mts CHANGED
@@ -1,265 +1,280 @@
1
+ import "polyfill-symbol-metadata";
2
+ //#region src/lib/typings/DatabaseAccess.d.ts
1
3
  interface DatabaseAccess {
2
- createBackup?(backupName: string): Promise<any>;
3
- runReadStatement(query: string): Promise<unknown>;
4
- runWriteStatement(query: string): Promise<any>;
5
- runTransaction(query: string): Promise<any>;
4
+ createBackup?(backupName: string): Promise<any>;
5
+ runReadStatement(query: string): Promise<unknown>;
6
+ runWriteStatement(query: string): Promise<any>;
7
+ runTransaction(query: string): Promise<any>;
6
8
  }
7
-
9
+ //#endregion
10
+ //#region src/lib/typings/TableClassInterface.d.ts
8
11
  type Class<T> = new (...args: never[]) => T;
9
12
  /**
10
13
  * This does nothing. It mainly exists in case we want to filter class types in the future
11
14
  */
12
15
  type TableClassInterface = {
13
- [key: string]: any;
16
+ [key: string]: any;
14
17
  };
15
-
18
+ //#endregion
19
+ //#region src/lib/typings/AllowedMigrations.d.ts
16
20
  declare const ALLOWED = "allowed";
17
21
  declare const USED = "allowedAndUsed";
18
22
  type AllowedMigrationState = typeof ALLOWED | typeof USED;
19
23
  interface AllowedMigrations {
20
- recreateTable?: Record<string, AllowedMigrationState>;
21
- dropTable?: Record<string, AllowedMigrationState>;
22
- dropColumn?: Record<string, AllowedMigrationState>;
23
- alterPrimaryKey?: Record<string, AllowedMigrationState>;
24
- removeForeignKey?: Record<string, AllowedMigrationState>;
25
- alterForeignKey?: Record<string, AllowedMigrationState>;
24
+ recreateTable?: Record<string, AllowedMigrationState>;
25
+ dropTable?: Record<string, AllowedMigrationState>;
26
+ dropColumn?: Record<string, AllowedMigrationState>;
27
+ alterPrimaryKey?: Record<string, AllowedMigrationState>;
28
+ removeForeignKey?: Record<string, AllowedMigrationState>;
29
+ alterForeignKey?: Record<string, AllowedMigrationState>;
26
30
  }
27
-
31
+ //#endregion
32
+ //#region src/lib/typings/MigrationInstructions.d.ts
28
33
  interface RenameData {
29
- oldName: string;
30
- newName: string;
34
+ oldName: string;
35
+ newName: string;
31
36
  }
32
37
  interface MigrationInstructions {
33
- tableRenaming?: RenameData;
34
- recreate: boolean;
35
- /**
36
- * Stores changes to column. One entry per column.
37
- */
38
- renamedColumns: RenameData[];
39
- allowedMigrations: AllowedMigrations;
38
+ tableRenaming?: RenameData;
39
+ recreate: boolean;
40
+ /**
41
+ * Stores changes to column. One entry per column.
42
+ */
43
+ renamedColumns: RenameData[];
44
+ allowedMigrations: AllowedMigrations;
40
45
  }
41
-
46
+ //#endregion
47
+ //#region src/lib/typings/ColumnInfo.d.ts
42
48
  interface ColumnInfo {
43
- name: string;
44
- sqlType: string;
45
- maxLength?: number;
46
- defaultValue?: string;
47
- isPrimaryKey: boolean;
49
+ name: string;
50
+ sqlType: string;
51
+ maxLength?: number;
52
+ defaultValue?: string;
53
+ isPrimaryKey: boolean;
48
54
  }
49
-
55
+ //#endregion
56
+ //#region src/lib/typings/ForeignKeyInfo.d.ts
50
57
  type ForeignKeyActions = "SET NULL" | "SET DEFAULT" | "RESTRICT" | "NO ACTION" | "CASCADE";
51
58
  interface ForeignKeyInfo {
52
- fromTable: string;
53
- fromColumn: string;
54
- toTable: string;
55
- toColumn: string;
56
- onUpdate?: ForeignKeyActions;
57
- onDelete?: ForeignKeyActions;
59
+ fromTable: string;
60
+ fromColumn: string;
61
+ toTable: string;
62
+ toColumn: string;
63
+ onUpdate?: ForeignKeyActions;
64
+ onDelete?: ForeignKeyActions;
58
65
  }
59
-
66
+ //#endregion
67
+ //#region src/lib/typings/TableStructure.d.ts
60
68
  interface TableStructure {
61
- table: string;
62
- primaryKey?: string;
63
- columns: Record<string, ColumnInfo>;
64
- foreignKeys?: ForeignKeyInfo[];
69
+ table: string;
70
+ primaryKey?: string;
71
+ columns: Record<string, ColumnInfo>;
72
+ foreignKeys?: ForeignKeyInfo[];
65
73
  }
66
-
74
+ //#endregion
75
+ //#region src/lib/Migrations.d.ts
67
76
  /**
68
77
  * The Migrations class is responsible for managing manual database schema migrations.
69
78
  */
70
79
  declare class Migrations {
71
- private fromVersion;
72
- private toVersion;
73
- private lastUsedVersion;
74
- private migrationData;
75
- private migrationDataForOldTableNames;
76
- private alwaysAllowed;
77
- private notAllowedChanges;
78
- /**
79
- * Resets the migration state to its initial values.
80
- * Only used internally.
81
- *
82
- * @param dbInstructions - The instructions containing database metadata and migration details.
83
- * @param fromVersion - The version of the actual database.
84
- */
85
- reset(dbInstructions: DatabaseInstructions, fromVersion: number): void;
86
- /**
87
- * Retrieves the migration instructions for the specified table.
88
- *
89
- * @param tableName - The name of the table for which the entry is to be retrieved or created.
90
- * @return The migration instructions corresponding to the given table input.
91
- */
92
- private getEntryFromTableName;
93
- /**
94
- * Checks whether a provided version is relevant based on database version ({@link fromVersion}) and target version ({@link toVersion}).
95
- * Also makes sure that version checks happen in order.
96
- *
97
- * @param version - The version to check for relevance.
98
- * @return Returns true if the version is relevant, otherwise false.
99
- * @throws Error if versions are not properly ordered
100
- */
101
- private versionIsRelevant;
102
- /**
103
- * Verifies the renaming tasks specified in {@link DatabaseInstructions.preMigration} that were considered are valid.
104
- * Called after all SQL queries have been generated.
105
- * Only used internally.
106
- *
107
- * @param newTables - The table structures extracted from {@link DatabaseInstructions.tables}.
108
- * @throws Error if a renaming task is invalid.
109
- */
110
- verifyRenamingTasks(newTables: Record<string, TableStructure>): Error | void;
111
- /**
112
- * Making sure all considered calls to {@link allowMigration()} where necessary to prevent input mistakes.
113
- * Called after all SQL queries have been generated.
114
- * Only used internally.
115
- *
116
- * @throws Error if unnecessary calls were discovered. All discovered calls are collected and thrown as one Error.
117
- */
118
- verifyAllowedMigrations(): Error | void;
119
- /**
120
- * Called by {@link MigrationManager} to check if a specific destructive query is allowed.
121
- * Only used internally.
122
- *
123
- * @see allowMigration()
124
- * @param tableName - The name of the table to check the migration against.
125
- * @param type - The type of destructive migration being checked.
126
- * @param column - The column name for which the migration is allowed. Only needed for "dropColumn", "removeForeignKey" and "alterForeignKey".
127
- */
128
- compareWithAllowedMigration(tableName: string, type: keyof AllowedMigrations, column?: string): void;
129
- /**
130
- * Retrieves the migration data containing instructions for data migration.
131
- * Only used internally.
132
- *
133
- * @return An object where each key corresponds to the table name,
134
- * and the value is the associated migration instructions.
135
- */
136
- getMigrationData(): Record<string, MigrationInstructions>;
137
- /**
138
- * Iterates over renamed columns for the specified table and executes a callback for each pair of old and new column names.
139
- * Only used internally.
140
- *
141
- * @param tableName - Name of the table whose renamed columns should be processed.
142
- * @param callback - A function to execute for each renamed column, receiving the old and new column names as arguments.
143
- */
144
- loopRenamedColumns(tableName: string, callback: (oldColumnName: string, newColumnName: string) => void): void;
145
- /**
146
- * Considers the renaming of a table and returns its (newest) name after the migration or
147
- * the original name if no renaming is queued.
148
- * Only used internally.
149
- *
150
- * @see getOldTableName()
151
- * @param tableName - The current table name in the database.
152
- * @return The newest table name if available, otherwise the current table name.
153
- */
154
- getNewestTableName(tableName: string): string;
155
- /**
156
- * Retrieves the current table name in the database.
157
- * Only used internally.
158
- *
159
- * @see getNewestTableName()
160
- * @param tableName - The name of the newest table name.
161
- * @return The current table name in the database.
162
- */
163
- getOldTableName(tableName: string): string;
164
- /**
165
- * Considers the renaming of a column in a table and returns its (newest) name after the migration or
166
- * the original name if no renaming is queued.
167
- * Only used internally.
168
- *
169
- * @param tableName - The name of the table containing the column.
170
- * @param oldColumnName - The current name of the column in the database.
171
- * @return The newest column name if available, otherwise the original column name.
172
- */
173
- getNewestColumnName(tableName: string, oldColumnName: string): string;
174
- /**
175
- * Determines if the specified table is marked to be recreated.
176
- * Only used internally.
177
- *
178
- * @param tableName The name of the table to check.
179
- * @return Returns true if the table will be recreated, false otherwise.
180
- */
181
- willBeRecreated(tableName: string): boolean;
182
- /**
183
- * Marks a table to be recreated and logs the recreation reason for the user.
184
- * Only used internally.
185
- *
186
- * @param tableName - The name of the table to be marked for recreation.
187
- * @param reason - The reason why the table is being marked for recreation.
188
- */
189
- internalRecreate(tableName: string, reason: string): void;
190
- /**
191
- * SqlMorpheus only allows destructive statements if it was specifically allowed in {@link DatabaseInstructions.preMigration()}.
192
- * Use this method to allow a destructive statement for a specific version.
193
- * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
194
- *
195
- * @param version - The target version for which the specific migration is allowed. Must be provided to make sure this method will only have an effect when specified.
196
- * @param tableName - The current table name in the database at the time of the migration version.
197
- * @param allowedMigration - The keys representing the migrations to be allowed.
198
- * @param column - The column name for which the migration is allowed. Only needed for "dropColumn", "removeForeignKey" and "alterForeignKey".
199
- *
200
- * @throws Error if the provided column name is not valid for the specified migration.
201
- */
202
- allowMigration(version: number, tableName: string, allowedMigration: keyof AllowedMigrations, column?: string): void;
203
- /**
204
- * When you change the name of a table, SqlMorpheus will assume the original table was meant to be dropped
205
- * and the new table was meant to be added, which would lead to data loss.
206
- * Use this method to mark a table to be renamed instead.
207
- * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
208
- *
209
- * @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
210
- * @param oldTableName - The current name in the database at the time of the migration version.
211
- * @param newTableName - The new table name at the time of the migration version.
212
- */
213
- renameTable(version: number, oldTableName: string, newTableName: string): void;
214
- /**
215
- * When you change the name of a column, SqlMorpheus will assume the original column was meant to be removed
216
- * and the new column was meant to be added, which would lead to data loss.
217
- * Use this method to mark a column to be renamed instead.
218
- * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
219
- *
220
- * @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
221
- * @param tableName - The current table name in the database at the time of the migration version.
222
- * @param oldColumn The current name in the database at the time of the migration.
223
- * @param newColumn The new name to assign to the column.
224
- */
225
- renameColumn(version: number, tableName: string, oldColumn: string, newColumn: string): void;
226
- /**
227
- * Should not be needed most of the time.
228
- * Marks a table to be recreated
229
- * (a copy of the table will be created, all data will be moved over, the original table will be dropped and the new table will be renamed to the original name).
230
- * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
231
- *
232
- * @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
233
- * @param tableName - The current table name in the database at the time of the migration version.
234
- */
235
- recreateTable(version: number, tableName: string): void;
80
+ private fromVersion;
81
+ private toVersion;
82
+ private lastUsedVersion;
83
+ private migrationData;
84
+ private migrationDataForOldTableNames;
85
+ private alwaysAllowed;
86
+ private notAllowedChanges;
87
+ /**
88
+ * Resets the migration state to its initial values.
89
+ * Only used internally.
90
+ *
91
+ * @param dbInstructions - The instructions containing database metadata and migration details.
92
+ * @param fromVersion - The version of the actual database.
93
+ */
94
+ reset(dbInstructions: DatabaseInstructions, fromVersion: number): void;
95
+ /**
96
+ * Retrieves the migration instructions for the specified table.
97
+ *
98
+ * @param tableName - The name of the table for which the entry is to be retrieved or created.
99
+ * @return The migration instructions corresponding to the given table input.
100
+ */
101
+ private getEntryFromTableName;
102
+ /**
103
+ * Checks whether a provided version is relevant based on database version ({@link fromVersion}) and target version ({@link toVersion}).
104
+ * Also makes sure that version checks happen in order.
105
+ *
106
+ * @param version - The version to check for relevance.
107
+ * @return Returns true if the version is relevant, otherwise false.
108
+ * @throws Error if versions are not properly ordered
109
+ */
110
+ private versionIsRelevant;
111
+ /**
112
+ * Verifies the renaming tasks specified in {@link DatabaseInstructions.preMigration} that were considered are valid.
113
+ * Called after all SQL queries have been generated.
114
+ * Only used internally.
115
+ *
116
+ * @param newTables - The table structures extracted from {@link DatabaseInstructions.tables}.
117
+ * @throws Error if a renaming task is invalid.
118
+ */
119
+ verifyRenamingTasks(newTables: Record<string, TableStructure>): Error | void;
120
+ /**
121
+ * Making sure all considered calls to {@link allowMigration()} where necessary to prevent input mistakes.
122
+ * Called after all SQL queries have been generated.
123
+ * Only used internally.
124
+ *
125
+ * @throws Error if unnecessary calls were discovered. All discovered calls are collected and thrown as one Error.
126
+ */
127
+ verifyAllowedMigrations(): Error | void;
128
+ /**
129
+ * Called by {@link MigrationManager} to check if a specific destructive query is allowed.
130
+ * Only used internally.
131
+ *
132
+ * @see allowMigration()
133
+ * @param tableName - The name of the table to check the migration against.
134
+ * @param type - The type of destructive migration being checked.
135
+ * @param column - The column name for which the migration is allowed. Only needed for "dropColumn", "removeForeignKey" and "alterForeignKey".
136
+ */
137
+ compareWithAllowedMigration(tableName: string, type: keyof AllowedMigrations, column?: string): void;
138
+ /**
139
+ * Retrieves the migration data containing instructions for data migration.
140
+ * Only used internally.
141
+ *
142
+ * @return An object where each key corresponds to the table name,
143
+ * and the value is the associated migration instructions.
144
+ */
145
+ getMigrationData(): Record<string, MigrationInstructions>;
146
+ /**
147
+ * Iterates over renamed columns for the specified table and executes a callback for each pair of old and new column names.
148
+ * Only used internally.
149
+ *
150
+ * @param tableName - Name of the table whose renamed columns should be processed.
151
+ * @param callback - A function to execute for each renamed column, receiving the old and new column names as arguments.
152
+ */
153
+ loopRenamedColumns(tableName: string, callback: (oldColumnName: string, newColumnName: string) => void): void;
154
+ /**
155
+ * Considers the renaming of a table and returns its (newest) name after the migration or
156
+ * the original name if no renaming is queued.
157
+ * Only used internally.
158
+ *
159
+ * @see getOldTableName()
160
+ * @param tableName - The current table name in the database.
161
+ * @return The newest table name if available, otherwise the current table name.
162
+ */
163
+ getNewestTableName(tableName: string): string;
164
+ /**
165
+ * Retrieves the current table name in the database.
166
+ * Only used internally.
167
+ *
168
+ * @see getNewestTableName()
169
+ * @param tableName - The name of the newest table name.
170
+ * @return The current table name in the database.
171
+ */
172
+ getOldTableName(tableName: string): string;
173
+ /**
174
+ * Considers the renaming of a column in a table and returns its (newest) name after the migration or
175
+ * the original name if no renaming is queued.
176
+ * Only used internally.
177
+ *
178
+ * @param tableName - The name of the table containing the column.
179
+ * @param oldColumnName - The current name of the column in the database.
180
+ * @return The newest column name if available, otherwise the original column name.
181
+ */
182
+ getNewestColumnName(tableName: string, oldColumnName: string): string;
183
+ /**
184
+ * Determines if the specified table is marked to be recreated.
185
+ * Only used internally.
186
+ *
187
+ * @param tableName The name of the table to check.
188
+ * @return Returns true if the table will be recreated, false otherwise.
189
+ */
190
+ willBeRecreated(tableName: string): boolean;
191
+ /**
192
+ * Marks a table to be recreated and logs the recreation reason for the user.
193
+ * Only used internally.
194
+ *
195
+ * @param tableName - The name of the table to be marked for recreation.
196
+ * @param reason - The reason why the table is being marked for recreation.
197
+ */
198
+ internalRecreate(tableName: string, reason: string): void;
199
+ /**
200
+ * SqlMorpheus only allows destructive statements if it was specifically allowed in {@link DatabaseInstructions.preMigration()}.
201
+ * Use this method to allow a destructive statement for a specific version.
202
+ * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
203
+ *
204
+ * @param version - The target version for which the specific migration is allowed. Must be provided to make sure this method will only have an effect when specified.
205
+ * @param tableName - The current table name in the database at the time of the migration version.
206
+ * @param allowedMigration - The keys representing the migrations to be allowed.
207
+ * @param column - The column name for which the migration is allowed. Only needed for "dropColumn", "removeForeignKey" and "alterForeignKey".
208
+ *
209
+ * @throws Error if the provided column name is not valid for the specified migration.
210
+ */
211
+ allowMigration(version: number, tableName: string, allowedMigration: keyof AllowedMigrations, column?: string): void;
212
+ /**
213
+ * When you change the name of a table, SqlMorpheus will assume the original table was meant to be dropped
214
+ * and the new table was meant to be added, which would lead to data loss.
215
+ * Use this method to mark a table to be renamed instead.
216
+ * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
217
+ *
218
+ * @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
219
+ * @param oldTableName - The current name in the database at the time of the migration version.
220
+ * @param newTableName - The new table name at the time of the migration version.
221
+ */
222
+ renameTable(version: number, oldTableName: string, newTableName: string): void;
223
+ /**
224
+ * When you change the name of a column, SqlMorpheus will assume the original column was meant to be removed
225
+ * and the new column was meant to be added, which would lead to data loss.
226
+ * Use this method to mark a column to be renamed instead.
227
+ * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
228
+ *
229
+ * @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
230
+ * @param tableName - The current table name in the database at the time of the migration version.
231
+ * @param oldColumn The current name in the database at the time of the migration.
232
+ * @param newColumn The new name to assign to the column.
233
+ */
234
+ renameColumn(version: number, tableName: string, oldColumn: string, newColumn: string): void;
235
+ /**
236
+ * Should not be needed most of the time.
237
+ * Marks a table to be recreated
238
+ * (a copy of the table will be created, all data will be moved over, the original table will be dropped and the new table will be renamed to the original name).
239
+ * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
240
+ *
241
+ * @param version - The target version for which the table should be renamed. Must be provided to make sure this method will only have an effect when specified.
242
+ * @param tableName - The current table name in the database at the time of the migration version.
243
+ */
244
+ recreateTable(version: number, tableName: string): void;
236
245
  }
237
246
  type PublicMigrations = Pick<Migrations, "recreateTable" | "renameTable" | "renameColumn" | "allowMigration">;
238
-
247
+ //#endregion
248
+ //#region src/lib/typings/SqlChanges.d.ts
239
249
  interface SqlChanges {
240
- up: string;
241
- down: string;
250
+ up: string;
251
+ down: string;
242
252
  }
243
-
253
+ //#endregion
254
+ //#region src/lib/tableInfo/DataTypeOptions.d.ts
244
255
  type NativeDataTypeOptions = "boolean" | "number" | "bigint" | "string";
245
256
  type AddedDataTypeOptions = "date" | "time" | "dateTime" | "text";
246
257
  type DataTypeOptions = NativeDataTypeOptions | AddedDataTypeOptions;
247
-
258
+ //#endregion
259
+ //#region src/lib/typings/InputColumnInfo.d.ts
248
260
  interface InputColumnInfo extends ColumnInfo {
249
- inputType?: DataTypeOptions;
250
- inputDefaultValue?: unknown;
261
+ inputType?: DataTypeOptions;
262
+ inputDefaultValue?: unknown;
251
263
  }
252
-
264
+ //#endregion
265
+ //#region src/lib/typings/InputTableStructure.d.ts
253
266
  interface InputTableStructure extends TableStructure {
254
- columns: Record<string, InputColumnInfo>;
267
+ columns: Record<string, InputColumnInfo>;
255
268
  }
256
-
269
+ //#endregion
270
+ //#region src/lib/tableInfo/TableObjHelper.d.ts
257
271
  type AllowedTypes = boolean | number | bigint | string | null | Date;
258
-
272
+ //#endregion
273
+ //#region src/lib/tableInfo/TableObj.d.ts
259
274
  interface ColumnOptions {
260
- primaryKey?: boolean;
261
- dataType?: DataTypeOptions;
262
- maxCharacterLength?: number;
275
+ primaryKey?: boolean;
276
+ dataType?: DataTypeOptions;
277
+ maxCharacterLength?: number;
263
278
  }
264
279
  type DataFormat = Record<string, AllowedTypes | [AllowedTypes, ColumnOptions]>;
265
280
  type GetColumns<T> = T extends PublicTableObj<infer Item> ? Item : never;
@@ -271,73 +286,76 @@ type TableObjInput = PublicTableObj<DataFormat>;
271
286
  *
272
287
  */
273
288
  declare class TableObj<T extends DataFormat> {
274
- readonly IS_TABLE_OBJ = true;
275
- readonly tableName: string;
276
- tableStructure: InputTableStructure;
277
- private constructor();
278
- private applyOptions;
279
- /**
280
- * Creates a foreign key relationship between the current table and a target table.
281
- *
282
- * @param fromColumn - The column in the current table that will serve as the foreign key.
283
- * @param toTable - The target table object that the foreign key will reference.
284
- * @param toColumn - The column in the target table that the foreign key will reference.
285
- * @param options - Optional configurations for the foreign key, specifying actions on update or delete.
286
- */
287
- foreignKey<TOther extends Partial<TableObj<DataFormat>>>(fromColumn: keyof T, toTable: TOther, toColumn: keyof GetColumns<TOther>, options?: {
288
- onUpdate?: ForeignKeyActions;
289
- onDelete?: ForeignKeyActions;
290
- }): PublicTableObj<T>;
291
- /**
292
- * An optional helper function to deal with `TS2589: Type instantiation is excessively deep and possibly infinite. when used as method parameter`
293
- * Does nothing in runtime
294
- */
295
- sealType(): TableObjInput;
296
- static create<T extends DataFormat>(tableName: string, columns: T): PublicTableObj<T>;
289
+ readonly IS_TABLE_OBJ = true;
290
+ readonly tableName: string;
291
+ tableStructure: InputTableStructure;
292
+ private constructor();
293
+ private applyOptions;
294
+ /**
295
+ * Creates a foreign key relationship between the current table and a target table.
296
+ *
297
+ * @param fromColumn - The column in the current table that will serve as the foreign key.
298
+ * @param toTable - The target table object that the foreign key will reference.
299
+ * @param toColumn - The column in the target table that the foreign key will reference.
300
+ * @param options - Optional configurations for the foreign key, specifying actions on update or delete.
301
+ */
302
+ foreignKey<TOther extends Partial<TableObj<DataFormat>>>(fromColumn: keyof T, toTable: TOther, toColumn: keyof GetColumns<TOther>, options?: {
303
+ onUpdate?: ForeignKeyActions;
304
+ onDelete?: ForeignKeyActions;
305
+ }): PublicTableObj<T>;
306
+ /**
307
+ * An optional helper function to deal with `TS2589: Type instantiation is excessively deep and possibly infinite. when used as method parameter`
308
+ * Does nothing in runtime
309
+ */
310
+ sealType(): TableObjInput;
311
+ static create<T extends DataFormat>(tableName: string, columns: T): PublicTableObj<T>;
297
312
  }
298
-
313
+ //#endregion
314
+ //#region src/lib/Logger.d.ts
299
315
  type LoggerMode = "silent" | "error" | "warn" | "log" | "debug";
300
-
316
+ //#endregion
317
+ //#region src/lib/typings/DatabaseInstructions.d.ts
301
318
  type TableInput = TableObjInput | Class<TableClassInterface>;
302
319
  interface DatabaseInstructions {
303
- dialect: "Sqlite" | "MsSql" | "MySql" | "Postgres";
304
- tables: TableInput[];
305
- version: number;
306
- /**
307
- * Usually SqlMorpheus throws an exception if it needs to execute a destructive database change and is not explicitly confirmed in
308
- * (using `allowMigration()` in `preMigration()`).
309
- * If true, no exception will be thrown and an error message will be logged to the console instead.
310
- */
311
- doNotThrowIfNotAllowed?: boolean;
312
- /**
313
- * Defines how much should be logged to the console.
314
- */
315
- loggerMode?: LoggerMode;
316
- /**
317
- * Usually SqlMorpheus throws an exception if it needs to execute a destructive database change and is not explicitly allowed to do so
318
- * (using `allowMigration()` in `preMigration()`).
319
- * if defined, the confirmation will be skipped for each migration type defined in `alwaysAllowedMigrations`.
320
- */
321
- alwaysAllowedMigrations?: (keyof AllowedMigrations)[];
322
- /**
323
- * Custom migrations that will run before any database changes are applied.
324
- * @param migrations - The migration object that will be validated after this.
325
- * @param dbAccess - The database access object to interact with the database.
326
- * @param fromVersion - Version of the current database.
327
- * @param toVersion - Version of the database after update.
328
- * @return custom SQL that should be executed before migrations are executed.
329
- */
330
- preMigration?(migrations: PublicMigrations, dbAccess: DatabaseAccess, fromVersion: number, toVersion: number): SqlChanges | void;
331
- /**
332
- * Custom migrations that will run after database changes have been applied (but before the transaction is finished)
333
- * @param dbAccess - The database access object to interact with the database.
334
- * @param fromVersion - Version of the current database.
335
- * @param toVersion - Version of the database after update.
336
- * @return custom SQL that should be executed after migrations were executed.
337
- */
338
- postMigration?(dbAccess: DatabaseAccess, fromVersion: number, toVersion: number): SqlChanges;
320
+ dialect: "Sqlite" | "MsSql" | "MySql" | "Postgres";
321
+ tables: TableInput[];
322
+ version: number;
323
+ /**
324
+ * Usually SqlMorpheus throws an exception if it needs to execute a destructive database change and is not explicitly confirmed in
325
+ * (using `allowMigration()` in `preMigration()`).
326
+ * If true, no exception will be thrown and an error message will be logged to the console instead.
327
+ */
328
+ doNotThrowIfNotAllowed?: boolean;
329
+ /**
330
+ * Defines how much should be logged to the console.
331
+ */
332
+ loggerMode?: LoggerMode;
333
+ /**
334
+ * Usually SqlMorpheus throws an exception if it needs to execute a destructive database change and is not explicitly allowed to do so
335
+ * (using `allowMigration()` in `preMigration()`).
336
+ * if defined, the confirmation will be skipped for each migration type defined in `alwaysAllowedMigrations`.
337
+ */
338
+ alwaysAllowedMigrations?: (keyof AllowedMigrations)[];
339
+ /**
340
+ * Custom migrations that will run before any database changes are applied.
341
+ * @param migrations - The migration object that will be validated after this.
342
+ * @param dbAccess - The database access object to interact with the database.
343
+ * @param fromVersion - Version of the current database.
344
+ * @param toVersion - Version of the database after update.
345
+ * @return custom SQL that should be executed before migrations are executed.
346
+ */
347
+ preMigration?(migrations: PublicMigrations, dbAccess: DatabaseAccess, fromVersion: number, toVersion: number): SqlChanges | void;
348
+ /**
349
+ * Custom migrations that will run after database changes have been applied (but before the transaction is finished)
350
+ * @param dbAccess - The database access object to interact with the database.
351
+ * @param fromVersion - Version of the current database.
352
+ * @param toVersion - Version of the database after update.
353
+ * @return custom SQL that should be executed after migrations were executed.
354
+ */
355
+ postMigration?(dbAccess: DatabaseAccess, fromVersion: number, toVersion: number): SqlChanges;
339
356
  }
340
-
357
+ //#endregion
358
+ //#region src/lib/tableInfo/decorators/TableClass.d.ts
341
359
  /**
342
360
  * Decorator function to configure a database table with its name and primary key.
343
361
  *
@@ -345,7 +363,8 @@ interface DatabaseInstructions {
345
363
  * @param primaryKey - The property name representing the primary property of the table.
346
364
  */
347
365
  declare function TableClass<T extends TableClassInterface>(tableName: string, primaryKey?: keyof T): (table: Class<T>, context?: any) => void;
348
-
366
+ //#endregion
367
+ //#region src/lib/tableInfo/decorators/DataType.d.ts
349
368
  /**
350
369
  * Decorator function to assign a specific data type to a column.
351
370
  * Should be used if you want to use a data type that does not exist in JavaScript or
@@ -354,7 +373,8 @@ declare function TableClass<T extends TableClassInterface>(tableName: string, pr
354
373
  * @param type - The data type to be assigned.
355
374
  */
356
375
  declare function DataType(type: DataTypeOptions): (table: any, context: any) => void;
357
-
376
+ //#endregion
377
+ //#region src/lib/tableInfo/decorators/ForeignKey.d.ts
358
378
  /**
359
379
  * Decorator function to define a foreign key relationship for a database table.
360
380
  *
@@ -363,11 +383,12 @@ declare function DataType(type: DataTypeOptions): (table: any, context: any) =>
363
383
  * @param options - Additional options.
364
384
  */
365
385
  declare function ForeignKey<TOther extends TableClassInterface>(toTable: Class<TOther>, toColumn: keyof TOther, options?: {
366
- onDelete?: ForeignKeyActions;
367
- onUpdate?: ForeignKeyActions;
386
+ onDelete?: ForeignKeyActions;
387
+ onUpdate?: ForeignKeyActions;
368
388
  }): (table: any, context: any) => void;
369
-
370
- declare function runMigration(db: DatabaseAccess, dbInstructions: DatabaseInstructions): Promise<void>;
389
+ //#endregion
390
+ //#region src/index.d.ts
391
+ export declare function runMigration(db: DatabaseAccess, dbInstructions: DatabaseInstructions): Promise<void>;
371
392
  /**
372
393
  * Rolls back the database to the provided toVersion
373
394
  * @param dbAccess - Access to the database.
@@ -375,6 +396,6 @@ declare function runMigration(db: DatabaseAccess, dbInstructions: DatabaseInstru
375
396
  * @param dialect - the dialect that should be used for the database. Usually is the value defined in DatabaseInstructions
376
397
  * @param loggerMode - defines how much should be logged to the console.
377
398
  */
378
- declare function rollback(dbAccess: DatabaseAccess, toVersion: number, dialect: DatabaseInstructions["dialect"], loggerMode?: DatabaseInstructions["loggerMode"]): Promise<number>;
379
-
380
- export { DataType, type DatabaseAccess, type DatabaseInstructions, ForeignKey, type PublicMigrations, type SqlChanges, TableClass, TableObj, rollback, runMigration };
399
+ export declare function rollback(dbAccess: DatabaseAccess, toVersion: number, dialect: DatabaseInstructions["dialect"], loggerMode?: DatabaseInstructions["loggerMode"]): Promise<number>;
400
+ //#endregion
401
+ export { DataType, type DatabaseAccess, type DatabaseInstructions, ForeignKey, type PublicMigrations, type SqlChanges, TableClass, TableObj };