sqlmorpheus 0.2.1 → 0.2.2

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ Ever wanted to use a migration tool but couldn't because is uses a different stack than your project and would add unnecessary overhead or would simply not work in your setup at all? SQLMorpheus is an automatic migration library that is as unopinionated as it gets:
2
+
3
+ - It does not use its own database framework
package/dist/index.d.mts CHANGED
@@ -40,7 +40,8 @@ interface MigrationInstructions {
40
40
  interface ColumnInfo {
41
41
  name: string;
42
42
  type: string;
43
- defaultValue: string;
43
+ maxLength?: number;
44
+ defaultValue?: string;
44
45
  isPrimaryKey: boolean;
45
46
  }
46
47
 
@@ -57,10 +58,13 @@ interface ForeignKeyInfo {
57
58
  interface TableStructure {
58
59
  table: string;
59
60
  primaryKey?: string;
60
- columns: ColumnInfo[];
61
+ columns: Record<string, ColumnInfo>;
61
62
  foreignKeys?: ForeignKeyInfo[];
62
63
  }
63
64
 
65
+ /**
66
+ * The Migrations class is responsible for managing manual database schema migrations.
67
+ */
64
68
  declare class Migrations {
65
69
  private fromVersion;
66
70
  private toVersion;
@@ -69,24 +73,174 @@ declare class Migrations {
69
73
  private migrationDataForOldTableNames;
70
74
  private alwaysAllowed;
71
75
  private notAllowedChanges;
76
+ /**
77
+ * Resets the migration state to its initial values.
78
+ * Only used internally.
79
+ *
80
+ * @param dbInstructions - The instructions containing database metadata and migration details.
81
+ * @param fromVersion - The version of the actual database.
82
+ */
72
83
  reset(dbInstructions: DatabaseInstructions, fromVersion: number): void;
84
+ /**
85
+ * Retrieves the migration instructions for the specified table.
86
+ * @see getEntryFromTableName
87
+ *
88
+ * @param table - The {@link TableInput} object from which the table name will be retrieved.
89
+ * @return The migration instructions corresponding to the given table input.
90
+ */
73
91
  private getEntry;
92
+ /**
93
+ * Retrieves the migration instructions for the specified table.
94
+ *
95
+ * @param tableName - The name of the table for which the entry is to be retrieved or created.
96
+ * @return The migration instructions corresponding to the given table input.
97
+ */
74
98
  private getEntryFromTableName;
99
+ /**
100
+ * Retrieves the table name from the given table input.
101
+ *
102
+ * @param table - The {@link TableInput} object.
103
+ * @return The name of the table derived from either {@link TableObj} or a class.
104
+ */
75
105
  private getTableName;
106
+ /**
107
+ * Checks whether a provided version is relevant based on database version ({@link fromVersion}) and target version ({@link toVersion}).
108
+ * Also makes sure that version checks happen in order.
109
+ *
110
+ * @param version - The version to check for relevance.
111
+ * @return Returns true if the version is relevant, otherwise false.
112
+ * @throws Error if versions are not properly ordered
113
+ */
76
114
  private versionIsRelevant;
115
+ /**
116
+ * Verifies the renaming tasks specified in {@link DatabaseInstructions.preMigration} that were considered are valid.
117
+ * Called after all SQL queries have been generated.
118
+ * Only used internally.
119
+ *
120
+ * @param newTables - The table structures extracted from {@link DatabaseInstructions.tables}.
121
+ * @throws Error if a renaming task is invalid.
122
+ */
77
123
  verifyRenamingTasks(newTables: Record<string, TableStructure>): Error | void;
124
+ /**
125
+ * Making sure all considered calls to {@link allowMigration()} where necessary to prevent input mistakes.
126
+ * Called after all SQL queries have been generated.
127
+ * Only used internally.
128
+ *
129
+ * @throws Error if unnecessary calls were discovered. All discovered calls are collected and thrown as one Error.
130
+ */
78
131
  verifyAllowedMigrations(): Error | void;
132
+ /**
133
+ * Called by {@link MigrationManager} to check if a specific destructive query is allowed.
134
+ * Only used internally.
135
+ *
136
+ * @see allowMigration()
137
+ * @param tableName - The name of the table to check the migration against.
138
+ * @param type - The type of destructive migration being checked.
139
+ */
79
140
  compareWithAllowedMigration(tableName: string, type: keyof AllowedMigrations): void;
141
+ /**
142
+ * Retrieves the migration data containing instructions for data migration.
143
+ * Only used internally.
144
+ *
145
+ * @return An object where each key corresponds to the table name,
146
+ * and the value is the associated migration instructions.
147
+ */
80
148
  getMigrationData(): Record<string, MigrationInstructions>;
149
+ /**
150
+ * Iterates over renamed columns for the specified table and executes a callback for each pair of old and new column names.
151
+ * Only used internally.
152
+ *
153
+ * @param tableName - Name of the table whose renamed columns should be processed.
154
+ * @param callback - A function to execute for each renamed column, receiving the old and new column names as arguments.
155
+ */
81
156
  loopRenamedColumns(tableName: string, callback: (oldColumnName: string, newColumnName: string) => void): void;
157
+ /**
158
+ * Considers the renaming of a table and returns its (newest) name after the migration or
159
+ * the original name if no renaming is queued.
160
+ * Only used internally.
161
+ *
162
+ * @see getOldTableName()
163
+ * @param tableName - The current table name in the database.
164
+ * @return The newest table name if available, otherwise the current table name.
165
+ */
82
166
  getNewestTableName(tableName: string): string;
167
+ /**
168
+ * Retrieves the current table name in the database.
169
+ * Only used internally.
170
+ *
171
+ * @see getNewestTableName()
172
+ * @param tableName - The name of the newest table name.
173
+ * @return The current table name in the database.
174
+ */
83
175
  getOldTableName(tableName: string): string;
176
+ /**
177
+ * Considers the renaming of a column in a table and returns its (newest) name after the migration or
178
+ * the original name if no renaming is queued.
179
+ * Only used internally.
180
+ *
181
+ * @param tableName - The name of the table containing the column.
182
+ * @param oldColumnName - The current name of the column in the database.
183
+ * @return The newest column name if available, otherwise the original column name.
184
+ */
84
185
  getNewestColumnName(tableName: string, oldColumnName: string): string;
186
+ /**
187
+ * Determines if the specified table is marked to be recreated.
188
+ * Only used internally.
189
+ *
190
+ * @param tableName The name of the table to check.
191
+ * @return Returns true if the table will be recreated, false otherwise.
192
+ */
85
193
  willBeRecreated(tableName: string): boolean;
194
+ /**
195
+ * Marks a table to be recreated and logs the recreation reason for the user.
196
+ * Only used internally.
197
+ *
198
+ * @param tableName - The name of the table to be marked for recreation.
199
+ * @param reason - The reason why the table is being marked for recreation.
200
+ */
86
201
  internalRecreate(tableName: string, reason: string): void;
202
+ /**
203
+ * SqlMorpheus only allows destructive statements if it was specifically allowed in {@link DatabaseInstructions.preMigration()}.
204
+ * Use this method to allow a destructive statement for a specific version.
205
+ * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
206
+ *
207
+ * @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.
208
+ * @param table - Either a {@link TableObj} or a class decorated with @TableClass.
209
+ * @param allowedMigrations - The keys representing the migrations to be allowed. Multiple migrations can be provided
210
+ */
87
211
  allowMigration(version: number, table: TableInput, ...allowedMigrations: (keyof AllowedMigrations)[]): 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.
220
+ * @param newTableName - The new table name or its equivalent input format.
221
+ */
88
222
  renameTable(version: number, oldTableName: string, newTableName: TableInput): 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 table Either a {@link TableObj} or a class decorated with @TableClass containing the column to be renamed.
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
+ */
89
234
  renameColumn(version: number, table: TableInput, 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 table Either a {@link TableObj} or a class decorated with @TableClass.
243
+ */
90
244
  recreateTable(version: number, table: TableInput): void;
91
245
  }
92
246
  type PublicMigrations = Pick<Migrations, "recreateTable" | "renameTable" | "renameColumn" | "allowMigration">;
@@ -100,16 +254,21 @@ type NativeDataTypeOptions = "boolean" | "number" | "bigint" | "string";
100
254
  type AddedDataTypeOptions = "date" | "time" | "dateTime";
101
255
  type DataTypeOptions = NativeDataTypeOptions | AddedDataTypeOptions;
102
256
 
103
- interface TableInfo {
104
- primaryKey?: string;
105
- foreignKeys?: ForeignKeyInfo[];
106
- dataTypes?: Record<string, DataTypeOptions>;
257
+ interface InputColumnInfo extends ColumnInfo {
258
+ inputType?: DataTypeOptions;
259
+ inputDefaultValue?: unknown;
260
+ }
261
+
262
+ interface InputTableStructure extends TableStructure {
263
+ columns: Record<string, InputColumnInfo>;
107
264
  }
108
265
 
109
266
  type DataFormat = Record<string, unknown>;
110
- type GetColumns<T> = T extends TableObjBuilder<infer Item, any> ? Item : never;
111
- type TableObjBuilder<T extends DataFormat, TPick extends keyof TableObj<T>> = Pick<TableObj<T>, TPick>;
112
- type TableObjInput = TableObjBuilder<any, any>;
267
+ type GetColumns<T> = T extends TableObjBuilderDefinition<infer Item, any> ? Item : never;
268
+ type TableObjBuilderDefinition<T extends DataFormat, TPick extends keyof TableObj<T>> = Pick<TableObj<T>, TPick>;
269
+ type NewTableObjBuilder<T extends DataFormat> = TableObjBuilderDefinition<T, "primaryKey" | "foreignKey" | "dataType" | "maxCharacterLength">;
270
+ type TableObjBuilder<T extends DataFormat> = TableObjBuilderDefinition<T, "foreignKey" | "dataType" | "maxCharacterLength">;
271
+ type TableObjInput = TableObjBuilderDefinition<any, any>;
113
272
  /**
114
273
  * Use this class to define tables for DatabaseInstructions
115
274
  * (as an alternative for Class decorators)
@@ -118,17 +277,19 @@ type TableObjInput = TableObjBuilder<any, any>;
118
277
  declare class TableObj<T extends DataFormat> {
119
278
  readonly IS_TABLE_OBJ = true;
120
279
  readonly tableName: string;
121
- readonly columns: T;
122
- tableInfo: TableInfo;
280
+ tableStructure: InputTableStructure;
281
+ static getEmptyColumnEntry(key: string): InputColumnInfo;
282
+ static getColumnEntry(key: string, value: unknown): InputColumnInfo | null;
123
283
  private constructor();
124
- primaryKey(key: keyof T): TableObjBuilder<T, "foreignKey" | "dataType">;
125
- foreignKey<TOther extends TableObjBuilder<DataFormat, any>>(fromColumn: keyof T, toTable: TOther, toColumn: keyof GetColumns<TOther>, options?: {
284
+ primaryKey(key: keyof T): TableObjBuilder<T>;
285
+ foreignKey<TOther extends TableObjBuilderDefinition<DataFormat, any>>(fromColumn: keyof T, toTable: TOther, toColumn: keyof GetColumns<TOther>, options?: {
126
286
  onUpdate?: ForeignKeyActions;
127
287
  onDelete?: ForeignKeyActions;
128
- }): TableObjBuilder<T, "foreignKey" | "dataType">;
129
- dataType(column: keyof T, type: DataTypeOptions): TableObjBuilder<T, "foreignKey" | "dataType">;
130
- static create<T extends Record<string, unknown>>(tableName: string, columns: T): TableObjBuilder<T, "primaryKey" | "foreignKey" | "dataType">;
131
- static isDbTable(obj: unknown): obj is TableObj<any>;
288
+ }): TableObjBuilder<T>;
289
+ dataType(column: keyof T, type: DataTypeOptions): TableObjBuilder<T>;
290
+ maxCharacterLength(column: keyof T, max: number): TableObjBuilder<T>;
291
+ static create<T extends Record<string, unknown>>(tableName: string, columns: T): NewTableObjBuilder<T>;
292
+ static isTableObj(obj: unknown): obj is TableObj<any>;
132
293
  }
133
294
 
134
295
  type TableInput = TableObjInput | Class<TableClassInterface>;
package/dist/index.d.ts CHANGED
@@ -40,7 +40,8 @@ interface MigrationInstructions {
40
40
  interface ColumnInfo {
41
41
  name: string;
42
42
  type: string;
43
- defaultValue: string;
43
+ maxLength?: number;
44
+ defaultValue?: string;
44
45
  isPrimaryKey: boolean;
45
46
  }
46
47
 
@@ -57,10 +58,13 @@ interface ForeignKeyInfo {
57
58
  interface TableStructure {
58
59
  table: string;
59
60
  primaryKey?: string;
60
- columns: ColumnInfo[];
61
+ columns: Record<string, ColumnInfo>;
61
62
  foreignKeys?: ForeignKeyInfo[];
62
63
  }
63
64
 
65
+ /**
66
+ * The Migrations class is responsible for managing manual database schema migrations.
67
+ */
64
68
  declare class Migrations {
65
69
  private fromVersion;
66
70
  private toVersion;
@@ -69,24 +73,174 @@ declare class Migrations {
69
73
  private migrationDataForOldTableNames;
70
74
  private alwaysAllowed;
71
75
  private notAllowedChanges;
76
+ /**
77
+ * Resets the migration state to its initial values.
78
+ * Only used internally.
79
+ *
80
+ * @param dbInstructions - The instructions containing database metadata and migration details.
81
+ * @param fromVersion - The version of the actual database.
82
+ */
72
83
  reset(dbInstructions: DatabaseInstructions, fromVersion: number): void;
84
+ /**
85
+ * Retrieves the migration instructions for the specified table.
86
+ * @see getEntryFromTableName
87
+ *
88
+ * @param table - The {@link TableInput} object from which the table name will be retrieved.
89
+ * @return The migration instructions corresponding to the given table input.
90
+ */
73
91
  private getEntry;
92
+ /**
93
+ * Retrieves the migration instructions for the specified table.
94
+ *
95
+ * @param tableName - The name of the table for which the entry is to be retrieved or created.
96
+ * @return The migration instructions corresponding to the given table input.
97
+ */
74
98
  private getEntryFromTableName;
99
+ /**
100
+ * Retrieves the table name from the given table input.
101
+ *
102
+ * @param table - The {@link TableInput} object.
103
+ * @return The name of the table derived from either {@link TableObj} or a class.
104
+ */
75
105
  private getTableName;
106
+ /**
107
+ * Checks whether a provided version is relevant based on database version ({@link fromVersion}) and target version ({@link toVersion}).
108
+ * Also makes sure that version checks happen in order.
109
+ *
110
+ * @param version - The version to check for relevance.
111
+ * @return Returns true if the version is relevant, otherwise false.
112
+ * @throws Error if versions are not properly ordered
113
+ */
76
114
  private versionIsRelevant;
115
+ /**
116
+ * Verifies the renaming tasks specified in {@link DatabaseInstructions.preMigration} that were considered are valid.
117
+ * Called after all SQL queries have been generated.
118
+ * Only used internally.
119
+ *
120
+ * @param newTables - The table structures extracted from {@link DatabaseInstructions.tables}.
121
+ * @throws Error if a renaming task is invalid.
122
+ */
77
123
  verifyRenamingTasks(newTables: Record<string, TableStructure>): Error | void;
124
+ /**
125
+ * Making sure all considered calls to {@link allowMigration()} where necessary to prevent input mistakes.
126
+ * Called after all SQL queries have been generated.
127
+ * Only used internally.
128
+ *
129
+ * @throws Error if unnecessary calls were discovered. All discovered calls are collected and thrown as one Error.
130
+ */
78
131
  verifyAllowedMigrations(): Error | void;
132
+ /**
133
+ * Called by {@link MigrationManager} to check if a specific destructive query is allowed.
134
+ * Only used internally.
135
+ *
136
+ * @see allowMigration()
137
+ * @param tableName - The name of the table to check the migration against.
138
+ * @param type - The type of destructive migration being checked.
139
+ */
79
140
  compareWithAllowedMigration(tableName: string, type: keyof AllowedMigrations): void;
141
+ /**
142
+ * Retrieves the migration data containing instructions for data migration.
143
+ * Only used internally.
144
+ *
145
+ * @return An object where each key corresponds to the table name,
146
+ * and the value is the associated migration instructions.
147
+ */
80
148
  getMigrationData(): Record<string, MigrationInstructions>;
149
+ /**
150
+ * Iterates over renamed columns for the specified table and executes a callback for each pair of old and new column names.
151
+ * Only used internally.
152
+ *
153
+ * @param tableName - Name of the table whose renamed columns should be processed.
154
+ * @param callback - A function to execute for each renamed column, receiving the old and new column names as arguments.
155
+ */
81
156
  loopRenamedColumns(tableName: string, callback: (oldColumnName: string, newColumnName: string) => void): void;
157
+ /**
158
+ * Considers the renaming of a table and returns its (newest) name after the migration or
159
+ * the original name if no renaming is queued.
160
+ * Only used internally.
161
+ *
162
+ * @see getOldTableName()
163
+ * @param tableName - The current table name in the database.
164
+ * @return The newest table name if available, otherwise the current table name.
165
+ */
82
166
  getNewestTableName(tableName: string): string;
167
+ /**
168
+ * Retrieves the current table name in the database.
169
+ * Only used internally.
170
+ *
171
+ * @see getNewestTableName()
172
+ * @param tableName - The name of the newest table name.
173
+ * @return The current table name in the database.
174
+ */
83
175
  getOldTableName(tableName: string): string;
176
+ /**
177
+ * Considers the renaming of a column in a table and returns its (newest) name after the migration or
178
+ * the original name if no renaming is queued.
179
+ * Only used internally.
180
+ *
181
+ * @param tableName - The name of the table containing the column.
182
+ * @param oldColumnName - The current name of the column in the database.
183
+ * @return The newest column name if available, otherwise the original column name.
184
+ */
84
185
  getNewestColumnName(tableName: string, oldColumnName: string): string;
186
+ /**
187
+ * Determines if the specified table is marked to be recreated.
188
+ * Only used internally.
189
+ *
190
+ * @param tableName The name of the table to check.
191
+ * @return Returns true if the table will be recreated, false otherwise.
192
+ */
85
193
  willBeRecreated(tableName: string): boolean;
194
+ /**
195
+ * Marks a table to be recreated and logs the recreation reason for the user.
196
+ * Only used internally.
197
+ *
198
+ * @param tableName - The name of the table to be marked for recreation.
199
+ * @param reason - The reason why the table is being marked for recreation.
200
+ */
86
201
  internalRecreate(tableName: string, reason: string): void;
202
+ /**
203
+ * SqlMorpheus only allows destructive statements if it was specifically allowed in {@link DatabaseInstructions.preMigration()}.
204
+ * Use this method to allow a destructive statement for a specific version.
205
+ * This method will be ignored if {@link version} is smaller than the current database version or higher than the target version of {@link DatabaseInstructions}.
206
+ *
207
+ * @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.
208
+ * @param table - Either a {@link TableObj} or a class decorated with @TableClass.
209
+ * @param allowedMigrations - The keys representing the migrations to be allowed. Multiple migrations can be provided
210
+ */
87
211
  allowMigration(version: number, table: TableInput, ...allowedMigrations: (keyof AllowedMigrations)[]): 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.
220
+ * @param newTableName - The new table name or its equivalent input format.
221
+ */
88
222
  renameTable(version: number, oldTableName: string, newTableName: TableInput): 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 table Either a {@link TableObj} or a class decorated with @TableClass containing the column to be renamed.
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
+ */
89
234
  renameColumn(version: number, table: TableInput, 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 table Either a {@link TableObj} or a class decorated with @TableClass.
243
+ */
90
244
  recreateTable(version: number, table: TableInput): void;
91
245
  }
92
246
  type PublicMigrations = Pick<Migrations, "recreateTable" | "renameTable" | "renameColumn" | "allowMigration">;
@@ -100,16 +254,21 @@ type NativeDataTypeOptions = "boolean" | "number" | "bigint" | "string";
100
254
  type AddedDataTypeOptions = "date" | "time" | "dateTime";
101
255
  type DataTypeOptions = NativeDataTypeOptions | AddedDataTypeOptions;
102
256
 
103
- interface TableInfo {
104
- primaryKey?: string;
105
- foreignKeys?: ForeignKeyInfo[];
106
- dataTypes?: Record<string, DataTypeOptions>;
257
+ interface InputColumnInfo extends ColumnInfo {
258
+ inputType?: DataTypeOptions;
259
+ inputDefaultValue?: unknown;
260
+ }
261
+
262
+ interface InputTableStructure extends TableStructure {
263
+ columns: Record<string, InputColumnInfo>;
107
264
  }
108
265
 
109
266
  type DataFormat = Record<string, unknown>;
110
- type GetColumns<T> = T extends TableObjBuilder<infer Item, any> ? Item : never;
111
- type TableObjBuilder<T extends DataFormat, TPick extends keyof TableObj<T>> = Pick<TableObj<T>, TPick>;
112
- type TableObjInput = TableObjBuilder<any, any>;
267
+ type GetColumns<T> = T extends TableObjBuilderDefinition<infer Item, any> ? Item : never;
268
+ type TableObjBuilderDefinition<T extends DataFormat, TPick extends keyof TableObj<T>> = Pick<TableObj<T>, TPick>;
269
+ type NewTableObjBuilder<T extends DataFormat> = TableObjBuilderDefinition<T, "primaryKey" | "foreignKey" | "dataType" | "maxCharacterLength">;
270
+ type TableObjBuilder<T extends DataFormat> = TableObjBuilderDefinition<T, "foreignKey" | "dataType" | "maxCharacterLength">;
271
+ type TableObjInput = TableObjBuilderDefinition<any, any>;
113
272
  /**
114
273
  * Use this class to define tables for DatabaseInstructions
115
274
  * (as an alternative for Class decorators)
@@ -118,17 +277,19 @@ type TableObjInput = TableObjBuilder<any, any>;
118
277
  declare class TableObj<T extends DataFormat> {
119
278
  readonly IS_TABLE_OBJ = true;
120
279
  readonly tableName: string;
121
- readonly columns: T;
122
- tableInfo: TableInfo;
280
+ tableStructure: InputTableStructure;
281
+ static getEmptyColumnEntry(key: string): InputColumnInfo;
282
+ static getColumnEntry(key: string, value: unknown): InputColumnInfo | null;
123
283
  private constructor();
124
- primaryKey(key: keyof T): TableObjBuilder<T, "foreignKey" | "dataType">;
125
- foreignKey<TOther extends TableObjBuilder<DataFormat, any>>(fromColumn: keyof T, toTable: TOther, toColumn: keyof GetColumns<TOther>, options?: {
284
+ primaryKey(key: keyof T): TableObjBuilder<T>;
285
+ foreignKey<TOther extends TableObjBuilderDefinition<DataFormat, any>>(fromColumn: keyof T, toTable: TOther, toColumn: keyof GetColumns<TOther>, options?: {
126
286
  onUpdate?: ForeignKeyActions;
127
287
  onDelete?: ForeignKeyActions;
128
- }): TableObjBuilder<T, "foreignKey" | "dataType">;
129
- dataType(column: keyof T, type: DataTypeOptions): TableObjBuilder<T, "foreignKey" | "dataType">;
130
- static create<T extends Record<string, unknown>>(tableName: string, columns: T): TableObjBuilder<T, "primaryKey" | "foreignKey" | "dataType">;
131
- static isDbTable(obj: unknown): obj is TableObj<any>;
288
+ }): TableObjBuilder<T>;
289
+ dataType(column: keyof T, type: DataTypeOptions): TableObjBuilder<T>;
290
+ maxCharacterLength(column: keyof T, max: number): TableObjBuilder<T>;
291
+ static create<T extends Record<string, unknown>>(tableName: string, columns: T): NewTableObjBuilder<T>;
292
+ static isTableObj(obj: unknown): obj is TableObj<any>;
132
293
  }
133
294
 
134
295
  type TableInput = TableObjInput | Class<TableClassInterface>;