@@ -25,8 +25,11 @@ import {
25
25
CompatibilityContext ,
26
26
DatabaseInputRow ,
27
27
SqliteInputRow ,
28
+ SqliteInputValue ,
29
+ SqliteRow ,
28
30
SqlSyncRules ,
29
31
TablePattern ,
32
+ ToastableSqliteRow ,
30
33
toSyncRulesRow
31
34
} from '@powersync/service-sync-rules' ;
32
35
@@ -635,7 +638,8 @@ WHERE oid = $1::regclass`,
635
638
hasRemainingData = true ;
636
639
}
637
640
638
- for ( const record of WalStream . getQueryData ( rows ) ) {
641
+ for ( const inputRecord of WalStream . getQueryData ( rows ) ) {
642
+ const record = this . syncRulesRecord ( inputRecord ) ;
639
643
// This auto-flushes when the batch reaches its size limit
640
644
await batch . save ( {
641
645
tag : storage . SaveOperationTag . INSERT ,
@@ -787,6 +791,20 @@ WHERE oid = $1::regclass`,
787
791
return table ;
788
792
}
789
793
794
+ private syncRulesRecord ( row : SqliteInputRow ) : SqliteRow ;
795
+ private syncRulesRecord ( row : SqliteInputRow | undefined ) : SqliteRow | undefined ;
796
+
797
+ private syncRulesRecord ( row : SqliteInputRow | undefined ) : SqliteRow | undefined {
798
+ if ( row == null ) {
799
+ return undefined ;
800
+ }
801
+ return this . sync_rules . applyRowContext < never > ( row ) ;
802
+ }
803
+
804
+ private toastableSyncRulesRecord ( row : ToastableSqliteRow < SqliteInputValue > ) : ToastableSqliteRow {
805
+ return this . sync_rules . applyRowContext ( row ) ;
806
+ }
807
+
790
808
async writeChange (
791
809
batch : storage . BucketStorageBatch ,
792
810
msg : pgwire . PgoutputMessage
@@ -803,7 +821,7 @@ WHERE oid = $1::regclass`,
803
821
804
822
if ( msg . tag == 'insert' ) {
805
823
this . metrics . getCounter ( ReplicationMetric . ROWS_REPLICATED ) . add ( 1 ) ;
806
- const baseRecord = this . connections . types . constructAfterRecord ( msg ) ;
824
+ const baseRecord = this . syncRulesRecord ( this . connections . types . constructAfterRecord ( msg ) ) ;
807
825
return await batch . save ( {
808
826
tag : storage . SaveOperationTag . INSERT ,
809
827
sourceTable : table ,
@@ -816,8 +834,8 @@ WHERE oid = $1::regclass`,
816
834
this . metrics . getCounter ( ReplicationMetric . ROWS_REPLICATED ) . add ( 1 ) ;
817
835
// "before" may be null if the replica id columns are unchanged
818
836
// It's fine to treat that the same as an insert.
819
- const before = this . connections . types . constructBeforeRecord ( msg ) ;
820
- const after = this . connections . types . constructAfterRecord ( msg ) ;
837
+ const before = this . syncRulesRecord ( this . connections . types . constructBeforeRecord ( msg ) ) ;
838
+ const after = this . toastableSyncRulesRecord ( this . connections . types . constructAfterRecord ( msg ) ) ;
821
839
return await batch . save ( {
822
840
tag : storage . SaveOperationTag . UPDATE ,
823
841
sourceTable : table ,
@@ -828,7 +846,7 @@ WHERE oid = $1::regclass`,
828
846
} ) ;
829
847
} else if ( msg . tag == 'delete' ) {
830
848
this . metrics . getCounter ( ReplicationMetric . ROWS_REPLICATED ) . add ( 1 ) ;
831
- const before = this . connections . types . constructBeforeRecord ( msg ) ! ;
849
+ const before = this . syncRulesRecord ( this . connections . types . constructBeforeRecord ( msg ) ! ) ;
832
850
833
851
return await batch . save ( {
834
852
tag : storage . SaveOperationTag . DELETE ,
0 commit comments