55
66import { BaseListener , BaseObserverInterface } from '../utils/BaseObserver' ;
77
8+ /**
9+ * TODO most of these types could be exported to a common `types` package
10+ * which is used by the DB adapter libraries as well.
11+ */
12+
813/**
914 * Object returned by SQL Query executions {
1015 * insertId: Represent the auto-generated row id if applicable
@@ -54,14 +59,28 @@ export enum RowUpdateType {
5459 SQLITE_DELETE = 9 ,
5560 SQLITE_UPDATE = 23
5661}
57- export interface UpdateNotification {
62+ export interface TableUpdateOperation {
5863 opType : RowUpdateType ;
59- table : string ;
6064 rowId : number ;
6165}
66+ export interface UpdateNotification extends TableUpdateOperation {
67+ table : string ;
68+ }
69+
70+ export interface BatchedUpdateNotification {
71+ rawUpdates : UpdateNotification [ ] ;
72+ tables : string [ ] ;
73+ groupedUpdates : Record < string , TableUpdateOperation [ ] > ;
74+ }
6275
6376export interface DBAdapterListener extends BaseListener {
64- tablesUpdated : ( updateNotification : UpdateNotification ) => void ;
77+ /**
78+ * Listener for table updates.
79+ * Allows for single table updates in order to maintain API compatibility
80+ * without the need for a major version bump
81+ * The DB adapter can also batch update notifications if supported.
82+ */
83+ tablesUpdated : ( updateNotification : BatchedUpdateNotification | UpdateNotification ) => void ;
6584}
6685
6786export interface DBLockOptions {
@@ -77,3 +96,9 @@ export interface DBAdapter extends BaseObserverInterface<DBAdapterListener>, DBG
7796 writeLock : < T > ( fn : ( tx : LockContext ) => Promise < T > , options ?: DBLockOptions ) => Promise < T > ;
7897 writeTransaction : < T > ( fn : ( tx : Transaction ) => Promise < T > , options ?: DBLockOptions ) => Promise < T > ;
7998}
99+
100+ export function isBatchedUpdateNotification (
101+ update : BatchedUpdateNotification | UpdateNotification
102+ ) : update is BatchedUpdateNotification {
103+ return 'tables' in update ;
104+ }
0 commit comments