From 209d403a00679705c61cb5062b41b3fa400437fa Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Thu, 5 Jun 2025 14:45:33 +0200 Subject: [PATCH 1/5] Added binlog query event type definition --- types/index.d.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index eb0e4c9..e5d3baa 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -153,13 +153,22 @@ export type BinLogTableMapEvent = BaseBinLogEvent & { columnTypes: number[]; }; +export type BinLogQueryEvent = BaseBinLogEvent & { + query: string; + executionTime: number; + errorCode: number; + schema: string; + statusVars: string; +}; + export type BinLogEvent = | BinLogRotationEvent | BinLogGTIDLogEvent | BinLogXidEvent | BinLogRowEvent | BinLogRowUpdateEvent - | BinLogTableMapEvent; + | BinLogTableMapEvent + | BinLogQueryEvent; // @vlasky/mysql Connection export interface MySQLConnection { From 5edc8a0713d2e0140bcd69f3fc21274a27a5136f Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Thu, 5 Jun 2025 14:46:27 +0200 Subject: [PATCH 2/5] Added changeset --- .changeset/five-otters-attack.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/five-otters-attack.md diff --git a/.changeset/five-otters-attack.md b/.changeset/five-otters-attack.md new file mode 100644 index 0000000..ddb9dfa --- /dev/null +++ b/.changeset/five-otters-attack.md @@ -0,0 +1,5 @@ +--- +'@powersync/mysql-zongji': minor +--- + +Added type definitions for binlog query event From cf720bf86aea0074d9b96e8c8f5d17fd94e3b64e Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Tue, 10 Jun 2025 16:06:28 +0200 Subject: [PATCH 3/5] Try EventEmitter type declaration for Zongji class --- types/index.d.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index e5d3baa..ad32153 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,4 +1,5 @@ import { Socket } from 'net'; +import { EventEmitter } from 'events'; /** * The types described here were added on an adhoc basis based on requirements in the Powersync Service. @@ -177,7 +178,7 @@ export interface MySQLConnection { query(sql: string, callback: (error: any, results: any, fields: any) => void): void; } -export declare class ZongJi { +export declare class ZongJi extends EventEmitter { stopped: boolean; connection: MySQLConnection; constructor(options: ZongjiOptions); @@ -186,6 +187,4 @@ export declare class ZongJi { stop(): void; pause(): void; resume(): void; - - on(type: 'binlog' | string, callback: (event: BinLogEvent) => void): void; } From 137d20de41e4d595214f96313998a7c3bc7a5ba8 Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Fri, 13 Jun 2025 11:00:14 +0200 Subject: [PATCH 4/5] Only emit rotate events when the binlog file has actually changed. --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 318fb97..04d1bfc 100644 --- a/index.js +++ b/index.js @@ -253,8 +253,9 @@ ZongJi.prototype.start = function (options = {}) { case 'Rotate': if (this.options.filename !== event.binlogName) { this.options.filename = event.binlogName; + this.emit('binlog', event); } - break; + return; } this.options.position = event.nextPosition; this.emit('binlog', event); From 20029ceac10aa0f5145ac02cc6dec67a15614368 Mon Sep 17 00:00:00 2001 From: Roland Teichert Date: Fri, 13 Jun 2025 11:27:45 +0200 Subject: [PATCH 5/5] Revert rotate event, change. Rotate events should always be emited on listener startup. --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 04d1bfc..318fb97 100644 --- a/index.js +++ b/index.js @@ -253,9 +253,8 @@ ZongJi.prototype.start = function (options = {}) { case 'Rotate': if (this.options.filename !== event.binlogName) { this.options.filename = event.binlogName; - this.emit('binlog', event); } - return; + break; } this.options.position = event.nextPosition; this.emit('binlog', event);