@@ -14,11 +14,23 @@ interface SharedTableOptions {
1414 localOnly ?: boolean ;
1515 insertOnly ?: boolean ;
1616 viewName ?: string ;
17- includeOld ?: boolean | 'when-changed' ;
17+ includeOld ?: boolean | IncludeOldOptions ;
1818 includeMetadata ?: boolean ;
1919 ignoreEmptyUpdate ?: boolean ;
2020}
2121
22+ /** Whether to include old columns when PowerSync tracks local changes.
23+ *
24+ * Including old columns may be helpful for some backend connector implementations, which is
25+ * why it can be enabled on per-table or per-columm basis.
26+ */
27+ export interface IncludeOldOptions {
28+ /** When defined, a list of column names for which old values should be tracked. */
29+ columns ?: string [ ] ;
30+ /** When enabled, only include values that have actually been changed by an update. */
31+ onlyWhenChanged ?: boolean ;
32+ }
33+
2234export interface TableOptions extends SharedTableOptions {
2335 /**
2436 * The synced table name, matching sync rules
@@ -329,13 +341,15 @@ export class Table<Columns extends ColumnsType = ColumnsType> {
329341 }
330342
331343 toJSON ( ) {
344+ const includeOld = this . includeOld ;
345+
332346 return {
333347 name : this . name ,
334348 view_name : this . viewName ,
335349 local_only : this . localOnly ,
336350 insert_only : this . insertOnly ,
337- include_old : this . includeOld != false ,
338- include_old_only_when_changed : this . includeOld == 'when-changed' ,
351+ include_old : includeOld && ( ( includeOld as any ) . columns ?? true ) ,
352+ include_old_only_when_changed : typeof includeOld == 'object' && includeOld . onlyWhenChanged == true ,
339353 include_metadata : this . includeMetadata ,
340354 ignore_empty_update : this . ignoreEmptyUpdate ,
341355 columns : this . columns . map ( ( c ) => c . toJSON ( ) ) ,
0 commit comments