Skip to content

Commit 848b9cd

Browse files
committed
Merge branch 'main' into catch-schema-mismatch-errors
2 parents 349dc99 + 52b43f3 commit 848b9cd

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

.github/workflows/dev-packages.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ name: Create Dev Release
44

55
on:
66
push:
7+
branches:
8+
- '**'
9+
- '!main' # excludes main, this is handled by changesets
10+
tags-ignore:
11+
- '**'
712

813
jobs:
914
publish:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @powersync/mysql-zongji
22

3+
## 0.3.0
4+
5+
### Minor Changes
6+
7+
- 65ca2b2: - Added type definitions for binlog query event
8+
- Added the ability to provide a table filter function for including/excluding binlog events
9+
- Updated Zongji class type definition
10+
311
## 0.2.0
412

513
### Minor Changes

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,14 @@ ZongJi.prototype._skipSchema = function (database, table) {
335335
let included =
336336
includes === undefined ||
337337
(database in includes &&
338-
(includes[database] === true || (Array.isArray(includes[database]) && includes[database].indexOf(table) > -1)));
338+
(includes[database] === true ||
339+
(Array.isArray(includes[database]) && includes[database].indexOf(table) > -1) ||
340+
(typeof includes[database] === 'function' && includes[database](table))));
339341
let excluded =
340342
database in excludes &&
341-
(excludes[database] === true || (Array.isArray(excludes[database]) && excludes[database].indexOf(table) > -1));
343+
(excludes[database] === true ||
344+
(Array.isArray(excludes[database]) && excludes[database].indexOf(table) > -1) ||
345+
(typeof excludes[database] === 'function' && excludes[database](table)));
342346

343347
return excluded || !included;
344348
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@powersync/mysql-zongji",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "A MySQL 8.0 >= compatible fork of ZongJi - a MySQL binlog listener for Node.js.",
55
"main": "index.js",
66
"types": "types/index.d.ts",

test/filtering.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ tap.test('Unit test', (test) => {
4545
test.end();
4646
});
4747

48+
test.test('FilterFunction includes', (test) => {
49+
zongji._filters({
50+
includeSchema: { db1: (table) => table === 'just_me' }
51+
});
52+
test.ok(!zongji._skipSchema('db1', 'just_me'));
53+
test.ok(zongji._skipSchema('db2', 'anything_else'));
54+
test.ok(zongji._skipSchema('db1', 'not_me'));
55+
56+
test.end();
57+
});
58+
4859
test.test((test) => {
4960
zongji._filters({
5061
excludeSchema: { db1: ['not_me'] }
@@ -57,6 +68,18 @@ tap.test('Unit test', (test) => {
5768
test.end();
5869
});
5970

71+
test.test('FilterFunction excludes', (test) => {
72+
zongji._filters({
73+
excludeSchema: { db1: (table) => table === 'not_me' }
74+
});
75+
76+
test.ok(!zongji._skipSchema('db1', 'anything_else'));
77+
test.ok(!zongji._skipSchema('db2', 'anything_else'));
78+
test.ok(zongji._skipSchema('db1', 'not_me'));
79+
80+
test.end();
81+
});
82+
6083
test.test((test) => {
6184
zongji._filters({
6285
excludeEvents: ['rotate']
@@ -79,7 +102,7 @@ tap.test('Unit test', (test) => {
79102
test.end();
80103
});
81104

82-
tap.test('Exclue all the schema', (test) => {
105+
tap.test('Exclude all the schema', (test) => {
83106
const zongji = new ZongJi(settings.connection);
84107

85108
const eventLog = [];

types/index.d.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Socket } from 'net';
2+
import { EventEmitter } from 'events';
23

34
/**
45
* The types described here were added on an adhoc basis based on requirements in the Powersync Service.
@@ -20,10 +21,11 @@ export type ZongjiOptions = {
2021

2122
/**
2223
* Record specifying a database and specific tables. ie. ['MyDatabase']: ['table1', 'table2']
23-
* Alternatively specifying true will include all tables in the database.
24+
* OR a filter function that returns true for tables that should be included
25+
* OR specifying true will include all tables in the database.
2426
*/
2527
interface DatabaseFilter {
26-
[databaseName: string]: string[] | true;
28+
[databaseName: string]: string[] | true | ((table: string) => boolean);
2729
}
2830

2931
export type StartOptions = {
@@ -153,13 +155,22 @@ export type BinLogTableMapEvent = BaseBinLogEvent & {
153155
columnTypes: number[];
154156
};
155157

158+
export type BinLogQueryEvent = BaseBinLogEvent & {
159+
query: string;
160+
executionTime: number;
161+
errorCode: number;
162+
schema: string;
163+
statusVars: string;
164+
};
165+
156166
export type BinLogEvent =
157167
| BinLogRotationEvent
158168
| BinLogGTIDLogEvent
159169
| BinLogXidEvent
160170
| BinLogRowEvent
161171
| BinLogRowUpdateEvent
162-
| BinLogTableMapEvent;
172+
| BinLogTableMapEvent
173+
| BinLogQueryEvent;
163174

164175
// @vlasky/mysql Connection
165176
export interface MySQLConnection {
@@ -168,7 +179,7 @@ export interface MySQLConnection {
168179
query(sql: string, callback: (error: any, results: any, fields: any) => void): void;
169180
}
170181

171-
export declare class ZongJi {
182+
export declare class ZongJi extends EventEmitter {
172183
stopped: boolean;
173184
connection: MySQLConnection;
174185
constructor(options: ZongjiOptions);
@@ -177,6 +188,4 @@ export declare class ZongJi {
177188
stop(): void;
178189
pause(): void;
179190
resume(): void;
180-
181-
on(type: 'binlog' | string, callback: (event: BinLogEvent) => void): void;
182191
}

0 commit comments

Comments
 (0)