@vlasky/zongji 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +35 -5
- package/example.js +5 -0
- package/index.d.ts +84 -2
- package/index.js +167 -59
- package/lib/binlog_event.js +39 -0
- package/lib/code_map.js +9 -1
- package/lib/common.js +71 -43
- package/lib/json_decode.js +61 -18
- package/lib/packet/binlog.js +7 -0
- package/lib/reader.js +4 -143
- package/lib/sequence/binlog.js +29 -7
- package/package.json +9 -6
- package/.claude/settings.local.json +0 -16
- package/.mcp.json +0 -17
- package/.tap/processinfo/84de694d-068b-4ac7-b4d8-f835c2122b2d.json +0 -892
- package/.tap/processinfo/a1e9627e-66eb-412c-aaa5-079a2eb9f385.json +0 -891
- package/.tap/processinfo/abc34c6f-f4aa-4405-8f9a-947048be1df2.json +0 -892
- package/.tap/processinfo/affe6c5b-a34d-41b9-bb73-4b14d35138de.json +0 -891
- package/.tap/processinfo/bf82449d-cdeb-478b-9506-b939a9506bf2.json +0 -883
- package/.tap/processinfo/dd98c508-7067-4342-bdf5-63664b630701.json +0 -892
- package/.tap/test-results/test_await_end.js.tap +0 -19
- package/.tap/test-results/test_await_end2.js.tap +0 -27
- package/.tap/test-results/test_debug_init.js.tap +0 -23
- package/.tap/test-results/test_debug_init2.js.tap +0 -35
- package/.tap/test-results/test_invalid_host.js.tap +0 -34
- package/.tap/test-results/test_minimal.js.tap +0 -26
- package/.tap/test-results/test_queryseq.js.tap +0 -14
- package/.tap/test-results/test_timing.js.tap +0 -17
- package/.tap/test-results/test_unref.js.tap +0 -15
- package/.travis.yml +0 -15
- package/CLAUDE.md +0 -99
- package/GTID.md +0 -54
- package/TODO.md +0 -43
- package/docker-compose.yml +0 -33
- package/docker-test.sh +0 -11
- package/eslint.config.js +0 -35
- package/jsconfig.json +0 -15
- package/lib/packet/combinlog.js +0 -27
- package/lib/packet/index.js +0 -66
- package/notes.md +0 -77
- package/scripts/start-mysql.sh +0 -28
- package/workerthreads.md +0 -173
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to @vlasky/zongji since forking from nevill/zongji.
|
|
4
4
|
|
|
5
|
+
## [0.7.0] - 2026-07-04
|
|
6
|
+
|
|
7
|
+
### Breaking changes
|
|
8
|
+
|
|
9
|
+
- DECIMAL columns now emit exact string values (e.g. `'-123.4500'`) instead of lossy floats, matching mysql2 query results. Migration: set `decimalNumbers: true` on the connection options passed to ZongJi to restore Numbers.
|
|
10
|
+
- JSON columns now emit parsed JavaScript values instead of JSON strings, matching mysql2 query results. Migration: set `jsonStrings: true` on the connection options passed to ZongJi to restore strings. In string mode, output now uses MySQL's own formatting (spaces after `:` and `,`) and 64-bit integers appear as exact raw numerals rather than lossy doubles.
|
|
11
|
+
- Event and schema filters are snapshotted when `start()` is called; mutating the arrays or objects you passed in no longer changes filtering afterwards. Migration: call `start()` again with the new filters (the documented way to update them).
|
|
12
|
+
|
|
13
|
+
### Other changes
|
|
14
|
+
|
|
15
|
+
- Fix SQL injection in the table metadata query: schema and table names from TableMap events are now bound via a cached prepared statement (`execute()`) instead of being spliced into SQL text
|
|
16
|
+
- Replace the big-integer dependency with native BigInt (one fewer dependency); also fixes silent corruption of 64-bit integers inside JSON columns beyond 2^53, which now follow the same exact Number-or-string rule as BIGINT columns
|
|
17
|
+
- Emit an error (once per instance per type) when the server sends undecodable TRANSACTION_PAYLOAD_EVENT (`binlog_transaction_compression=ON`) or PARTIAL_UPDATE_ROWS_EVENT (`binlog_row_value_options=PARTIAL_JSON`) events, instead of silently dropping the row changes; remaining MySQL 8 event codes (TRANSACTION_CONTEXT, VIEW_CHANGE, XA_PREPARE, HEARTBEAT_V2) are now named in the code map
|
|
18
|
+
- Lifecycle hardening: emit an explicit error instead of hanging silently when the control connection dies during a metadata fetch; a duplicate `start()` while one is still initialising is ignored, while stop-then-restart during initialisation now works (exactly one binlog dump command is ever enqueued); errors from connections deliberately destroyed by `stop()` are no longer forwarded as teardown noise; errors buffered before an `error` listener attaches are thrown if no listener ever appears, restoring Node's default unhandled `'error'` behaviour
|
|
19
|
+
- DECIMAL parsing no longer mutates the shared network packet buffer when flipping the sign bit
|
|
20
|
+
- Fix `stop()` destroying the control connection of a subsequent `start()`: the asynchronous KILL cleanup now only touches the connections that particular `stop()` owned, so immediate stop-then-restart no longer wedges the new stream on its first metadata fetch
|
|
21
|
+
- The `nonBlock` option declared in the TypeScript definitions is now actually passed through by `start()`; previously it was dropped and the dump command always ran in blocking mode
|
|
22
|
+
- Remove dead code left over from the mysql.js protocol layer (ComBinlog, EofPacket/ErrorPacket, BufferReader)
|
|
23
|
+
- Compile event and schema filters into Sets and Maps for O(1) per-event filtering; only own keys of schema filter objects are considered
|
|
24
|
+
- Add a package.json `exports` map with `types` and `default` conditions
|
|
25
|
+
- All emitted events carry an `event.gtid` property (`'uuid:sequence'`) identifying their transaction when the server runs with `gtid_mode=ON`, tracked at the packet layer so it works even when `gtid` events are excluded by `includeEvents`; `undefined` for anonymous transactions
|
|
26
|
+
- Update mysql2 to ^3.22.5; the internal APIs zongji relies on (addCommand, handlePacket, packet sequence validation) were verified unchanged, and a new regression test covers the binlog stream over a compressed connection
|
|
27
|
+
- Continuous integration now tests Node.js 22, 24 and 26 against MySQL 5.7, 8.0 and 8.4. Node.js 18 and 20 are end-of-life: they remain allowed by `engines` (nothing in the code requires anything newer) and 0.7.0 passed the full test suite on both at release time, but they are no longer tested and future releases may break on them
|
|
28
|
+
|
|
29
|
+
## [0.6.1] - 2026-02-13
|
|
30
|
+
|
|
31
|
+
- Updated .gitignore and .npmignore to exclude AI tool and build/test files
|
|
32
|
+
- Added npm version, downloads, node version, and licence badges to README
|
|
33
|
+
|
|
5
34
|
## [0.6.0] - 2026-02-13
|
|
6
35
|
|
|
7
36
|
- Migrate from @vlasky/mysql to mysql2
|
package/README.md
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@vlasky/zongji)
|
|
2
|
+
[](https://www.npmjs.com/package/@vlasky/zongji)
|
|
3
|
+
[](https://www.npmjs.com/package/@vlasky/zongji)
|
|
4
|
+
[](https://github.com/vlasky/zongji/blob/master/LICENSE)
|
|
5
|
+
|
|
1
6
|
MySQL binlog-based change data capture (CDC) for Node.js, [originally created by Nevill Dutt](https://github.com/nevill/zongji).
|
|
2
7
|
|
|
3
8
|
[@vlasky/zongji](https://github.com/vlasky/zongji) has been tested working with MySQL 5.7, 8.0 and 8.4.
|
|
4
9
|
|
|
5
10
|
It leverages [`mysql2`](https://github.com/sidorares/node-mysql2) for connections and authentication, while using zongji's binlog parsing and event pipeline.
|
|
6
11
|
|
|
7
|
-
#
|
|
12
|
+
# Release Notes
|
|
13
|
+
|
|
14
|
+
See the [CHANGELOG](CHANGELOG.md) for the full release history.
|
|
8
15
|
|
|
9
|
-
Version 0.6.0
|
|
16
|
+
Version 0.6.0 was a major modernisation that rewrote the codebase to use the mysql2 module, ES6 syntax and ESM exports, added TypeScript definitions, and added official support for MySQL 8.4.
|
|
10
17
|
|
|
11
18
|
Version 0.5.9 is the last release that supports Node.js versions below 18 and CommonJS.
|
|
12
19
|
|
|
@@ -49,9 +56,17 @@ import ZongJi from '@vlasky/zongji';
|
|
|
49
56
|
|
|
50
57
|
For a complete implementation see [`example.js`](example.js)...
|
|
51
58
|
|
|
59
|
+
## Module format
|
|
60
|
+
|
|
61
|
+
Since v0.6.0 this package is ESM-only. CommonJS projects can load it on Node.js >= 20.17 or >= 22.12, where `require()` of ES modules is supported, or on any supported version via dynamic `import()`:
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
const { default: ZongJi } = await import('@vlasky/zongji');
|
|
65
|
+
```
|
|
66
|
+
|
|
52
67
|
## Installation
|
|
53
68
|
|
|
54
|
-
* Requires Node.js v18
|
|
69
|
+
* Requires Node.js v18+. Actively supported and tested on Node.js 22, 24 and 26; version 0.7.0 was also verified on Node.js 18 and 20 at release, but those lines are end-of-life and no longer tested.
|
|
55
70
|
|
|
56
71
|
```bash
|
|
57
72
|
$ npm install @vlasky/zongji
|
|
@@ -88,7 +103,14 @@ The `ZongJi` constructor accepts one argument of either:
|
|
|
88
103
|
|
|
89
104
|
If a `Connection` or `Pool` object is passed to the constructor, it will not be destroyed/ended by Zongji's `stop()` method.
|
|
90
105
|
|
|
91
|
-
|
|
106
|
+
Binlog row values follow the same [mysql2 connection options](https://sidorares.github.io/node-mysql2/docs/api-and-configurations) as query results, so CDC events and queries on the same connection agree:
|
|
107
|
+
|
|
108
|
+
Option | Effect on row values
|
|
109
|
+
-------|---------------------
|
|
110
|
+
`dateStrings` | `DATE`, `DATETIME` and `TIMESTAMP` columns are returned as strings instead of `Date` objects.
|
|
111
|
+
`timezone` | Applied when converting `DATETIME` and `TIMESTAMP` values to `Date` objects.
|
|
112
|
+
`decimalNumbers` | `DECIMAL` columns are returned as exact strings by default (e.g. `'-123.4500'`); set `decimalNumbers: true` to receive Numbers (may lose precision beyond 15 significant digits).
|
|
113
|
+
`jsonStrings` | `JSON` columns are returned as parsed JavaScript values by default; set `jsonStrings: true` to receive JSON strings.
|
|
92
114
|
|
|
93
115
|
Each instance includes the following methods:
|
|
94
116
|
|
|
@@ -107,6 +129,8 @@ Event Name | Description
|
|
|
107
129
|
`error` | Every error will be caught by this event.
|
|
108
130
|
`stopped` | Emitted when ZongJi connection is stopped (ZongJi#stop is called).
|
|
109
131
|
|
|
132
|
+
Always attach an `error` listener. Errors that occur before a listener attaches (for example, a connection failure in the same tick as construction) are buffered and re-delivered to the first `error` listener. If no listener is ever attached, the buffered errors are thrown, following Node's default behaviour for unhandled `'error'` events.
|
|
133
|
+
|
|
110
134
|
**Options available:**
|
|
111
135
|
|
|
112
136
|
Option Name | Type | Description
|
|
@@ -122,6 +146,8 @@ Option Name | Type | Description
|
|
|
122
146
|
|
|
123
147
|
* By default, all events and schema are emitted.
|
|
124
148
|
* `excludeSchema` and `excludeEvents` take precedence over `includeSchema` and `includeEvents`, respectively.
|
|
149
|
+
* Calling `start()` while a previous `start()` is still initialising is ignored and the first call completes. The exception is after an intervening `stop()`: the new `start()` then restarts cleanly, and exactly one binlog stream is opened.
|
|
150
|
+
* Calling `start()` while ZongJi is already running does not reconnect; it only updates the event and schema filters from the given options.
|
|
125
151
|
|
|
126
152
|
**Supported Binlog Events:**
|
|
127
153
|
|
|
@@ -140,6 +166,10 @@ Event name | Description
|
|
|
140
166
|
`writerows` | Rows inserted, row data array available as `rows` property on event object
|
|
141
167
|
`updaterows` | Rows changed, row data array available as `rows` property on event object
|
|
142
168
|
`deleterows` | Rows deleted, row data array available as `rows` property on event object
|
|
169
|
+
`transactionpayload` | Compressed transaction from MySQL 8.0.20+ servers with `binlog_transaction_compression=ON`. ZongJi cannot decode the row events inside it, so it emits an `error` (once per instance) naming the server setting responsible.
|
|
170
|
+
`partialupdaterows` | Partial JSON update from MySQL 8.0+ servers with `binlog_row_value_options=PARTIAL_JSON`. ZongJi cannot decode the JSON diff format, so it emits an `error` (once per instance) naming the server setting responsible.
|
|
171
|
+
|
|
172
|
+
When the server runs with `gtid_mode=ON`, every emitted event carries a `gtid` property (`'uuid:sequence'`) identifying the transaction it belongs to, tracked internally even if `gtid` events are excluded by `includeEvents`. It is `undefined` for anonymous transactions and for events seen before the stream's first GTID event. Use it for checkpointing and deduplication.
|
|
143
173
|
|
|
144
174
|
**Event Methods**
|
|
145
175
|
|
|
@@ -153,7 +183,7 @@ Name | Description
|
|
|
153
183
|
## Important Notes
|
|
154
184
|
|
|
155
185
|
* :star2: All MySQL column types are supported, with type casting similar to [mysql2](https://github.com/sidorares/node-mysql2).
|
|
156
|
-
* :speak_no_evil: 64-bit
|
|
186
|
+
* :speak_no_evil: 64-bit integers are decoded exactly using native BigInt (see #108). If an integer is within the safe range of JS numbers (-2^53, 2^53), a Number is returned, otherwise an exact String. This also applies to 64-bit integers inside JSON columns.
|
|
157
187
|
* :point_right: `TRUNCATE` statement does not cause corresponding `DeleteRows` event. Use unqualified `DELETE FROM` for same effect.
|
|
158
188
|
* When using fractional seconds with `DATETIME` and `TIMESTAMP` data types, only millisecond precision is available due to the limit of Javascript's `Date` object.
|
|
159
189
|
* Binlog checksums (e.g. `CRC32`) are supported; zongji will detect and ignore the checksum bytes at the end of row events.
|
package/example.js
CHANGED
|
@@ -12,6 +12,11 @@ zongji.on('binlog', function(evt) {
|
|
|
12
12
|
evt.dump();
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
+
// Always attach an error listener; without one, errors are thrown
|
|
16
|
+
zongji.on('error', function(err) {
|
|
17
|
+
console.error('zongji error:', err);
|
|
18
|
+
});
|
|
19
|
+
|
|
15
20
|
zongji.start({
|
|
16
21
|
includeEvents: ['tablemap', 'writerows', 'updaterows', 'deleterows']
|
|
17
22
|
});
|
package/index.d.ts
CHANGED
|
@@ -56,6 +56,13 @@ export interface BinlogEvent {
|
|
|
56
56
|
nextPosition: number;
|
|
57
57
|
/** Size of the event in bytes */
|
|
58
58
|
size: number;
|
|
59
|
+
/**
|
|
60
|
+
* GTID of the transaction this event belongs to ('uuid:sequence'),
|
|
61
|
+
* when the server runs with gtid_mode=ON. Undefined for anonymous
|
|
62
|
+
* transactions and for events seen before the first GTID event of the
|
|
63
|
+
* stream. On Gtid/AnonymousGtid events this is their own parsed value.
|
|
64
|
+
*/
|
|
65
|
+
gtid?: string;
|
|
59
66
|
/** Get the lowercase event name */
|
|
60
67
|
getEventName(): string;
|
|
61
68
|
/** Get the event class name */
|
|
@@ -66,6 +73,8 @@ export interface BinlogEvent {
|
|
|
66
73
|
|
|
67
74
|
// Rotate event - indicates binlog file change
|
|
68
75
|
export interface RotateEvent extends BinlogEvent {
|
|
76
|
+
getTypeName(): 'Rotate';
|
|
77
|
+
getEventName(): 'rotate';
|
|
69
78
|
/** Position in the new binlog file */
|
|
70
79
|
position: number;
|
|
71
80
|
/** Name of the new binlog file */
|
|
@@ -73,10 +82,15 @@ export interface RotateEvent extends BinlogEvent {
|
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
// Format Description event
|
|
76
|
-
export interface FormatEvent extends BinlogEvent {
|
|
85
|
+
export interface FormatEvent extends BinlogEvent {
|
|
86
|
+
getTypeName(): 'Format';
|
|
87
|
+
getEventName(): 'format';
|
|
88
|
+
}
|
|
77
89
|
|
|
78
90
|
// GTID event
|
|
79
91
|
export interface GtidEvent extends BinlogEvent {
|
|
92
|
+
getTypeName(): 'Gtid';
|
|
93
|
+
getEventName(): 'gtid';
|
|
80
94
|
/** GTID flags */
|
|
81
95
|
flags: number;
|
|
82
96
|
/** Source UUID */
|
|
@@ -89,6 +103,8 @@ export interface GtidEvent extends BinlogEvent {
|
|
|
89
103
|
|
|
90
104
|
// Anonymous GTID event
|
|
91
105
|
export interface AnonymousGtidEvent extends BinlogEvent {
|
|
106
|
+
getTypeName(): 'AnonymousGtid';
|
|
107
|
+
getEventName(): 'anonymousgtid';
|
|
92
108
|
/** GTID flags */
|
|
93
109
|
flags: number;
|
|
94
110
|
/** Source UUID */
|
|
@@ -111,6 +127,8 @@ export interface GtidSidEntry {
|
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
export interface PreviousGtidsEvent extends BinlogEvent {
|
|
130
|
+
getTypeName(): 'PreviousGtids';
|
|
131
|
+
getEventName(): 'previousgtids';
|
|
114
132
|
/** Array of SID entries with their intervals */
|
|
115
133
|
sids: GtidSidEntry[];
|
|
116
134
|
/** GTID set as a formatted string */
|
|
@@ -119,12 +137,16 @@ export interface PreviousGtidsEvent extends BinlogEvent {
|
|
|
119
137
|
|
|
120
138
|
// XID (commit) event
|
|
121
139
|
export interface XidEvent extends BinlogEvent {
|
|
140
|
+
getTypeName(): 'Xid';
|
|
141
|
+
getEventName(): 'xid';
|
|
122
142
|
/** Transaction ID for 2PC */
|
|
123
143
|
xid: number | string;
|
|
124
144
|
}
|
|
125
145
|
|
|
126
146
|
// Query event
|
|
127
147
|
export interface QueryEvent extends BinlogEvent {
|
|
148
|
+
getTypeName(): 'Query';
|
|
149
|
+
getEventName(): 'query';
|
|
128
150
|
/** Slave proxy ID */
|
|
129
151
|
slaveProxyId: number;
|
|
130
152
|
/** Time in seconds the query took to execute */
|
|
@@ -145,6 +167,8 @@ export interface QueryEvent extends BinlogEvent {
|
|
|
145
167
|
|
|
146
168
|
// IntVar event (for statement-based replication)
|
|
147
169
|
export interface IntVarEvent extends BinlogEvent {
|
|
170
|
+
getTypeName(): 'IntVar';
|
|
171
|
+
getEventName(): 'intvar';
|
|
148
172
|
/** Variable type: 1=LAST_INSERT_ID, 2=INSERT_ID */
|
|
149
173
|
type: number;
|
|
150
174
|
/** The integer value */
|
|
@@ -155,6 +179,8 @@ export interface IntVarEvent extends BinlogEvent {
|
|
|
155
179
|
|
|
156
180
|
// TableMap event
|
|
157
181
|
export interface TableMapEvent extends BinlogEvent {
|
|
182
|
+
getTypeName(): 'TableMap';
|
|
183
|
+
getEventName(): 'tablemap';
|
|
158
184
|
/** Internal table ID */
|
|
159
185
|
tableId: number;
|
|
160
186
|
/** Table flags */
|
|
@@ -200,24 +226,47 @@ export interface RowsEvent extends BinlogEvent {
|
|
|
200
226
|
|
|
201
227
|
// WriteRows event (INSERT)
|
|
202
228
|
export interface WriteRowsEvent extends RowsEvent {
|
|
229
|
+
getTypeName(): 'WriteRows';
|
|
230
|
+
getEventName(): 'writerows';
|
|
203
231
|
/** Array of inserted rows */
|
|
204
232
|
rows: RowData[];
|
|
205
233
|
}
|
|
206
234
|
|
|
207
235
|
// DeleteRows event (DELETE)
|
|
208
236
|
export interface DeleteRowsEvent extends RowsEvent {
|
|
237
|
+
getTypeName(): 'DeleteRows';
|
|
238
|
+
getEventName(): 'deleterows';
|
|
209
239
|
/** Array of deleted rows */
|
|
210
240
|
rows: RowData[];
|
|
211
241
|
}
|
|
212
242
|
|
|
213
243
|
// UpdateRows event (UPDATE)
|
|
214
244
|
export interface UpdateRowsEvent extends RowsEvent {
|
|
245
|
+
getTypeName(): 'UpdateRows';
|
|
246
|
+
getEventName(): 'updaterows';
|
|
215
247
|
/** Array of updated rows with before/after values */
|
|
216
248
|
rows: UpdateRowData[];
|
|
217
249
|
}
|
|
218
250
|
|
|
251
|
+
// Transaction Payload event (MySQL 8.0.20+, binlog_transaction_compression=ON)
|
|
252
|
+
// The compressed transaction body cannot be decoded and is skipped.
|
|
253
|
+
export interface TransactionPayloadEvent extends BinlogEvent {
|
|
254
|
+
getTypeName(): 'TransactionPayload';
|
|
255
|
+
getEventName(): 'transactionpayload';
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Partial Update Rows event (MySQL 8.0+, binlog_row_value_options=PARTIAL_JSON)
|
|
259
|
+
// The partial JSON diff body cannot be decoded and is skipped.
|
|
260
|
+
export interface PartialUpdateRowsEvent extends BinlogEvent {
|
|
261
|
+
getTypeName(): 'PartialUpdateRows';
|
|
262
|
+
getEventName(): 'partialupdaterows';
|
|
263
|
+
}
|
|
264
|
+
|
|
219
265
|
// Unknown event type
|
|
220
|
-
export interface UnknownEvent extends BinlogEvent {
|
|
266
|
+
export interface UnknownEvent extends BinlogEvent {
|
|
267
|
+
getTypeName(): 'Unknown';
|
|
268
|
+
getEventName(): 'unknown';
|
|
269
|
+
}
|
|
221
270
|
|
|
222
271
|
// Union type of all event types
|
|
223
272
|
export type AnyBinlogEvent =
|
|
@@ -233,8 +282,40 @@ export type AnyBinlogEvent =
|
|
|
233
282
|
| WriteRowsEvent
|
|
234
283
|
| DeleteRowsEvent
|
|
235
284
|
| UpdateRowsEvent
|
|
285
|
+
| TransactionPayloadEvent
|
|
286
|
+
| PartialUpdateRowsEvent
|
|
236
287
|
| UnknownEvent;
|
|
237
288
|
|
|
289
|
+
/** Union of all possible getTypeName() return values (e.g. 'Rotate', 'WriteRows') */
|
|
290
|
+
export type BinlogEventTypeName = ReturnType<AnyBinlogEvent['getTypeName']>;
|
|
291
|
+
|
|
292
|
+
/** Union of all possible getEventName() return values (e.g. 'rotate', 'writerows') */
|
|
293
|
+
export type BinlogEventName = ReturnType<AnyBinlogEvent['getEventName']>;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Look up the concrete event type for a getTypeName() value.
|
|
297
|
+
* Enables narrowing AnyBinlogEvent via getTypeName(), e.g.:
|
|
298
|
+
*
|
|
299
|
+
* function isEventType<N extends BinlogEventTypeName>(
|
|
300
|
+
* event: AnyBinlogEvent, name: N
|
|
301
|
+
* ): event is BinlogEventByTypeName<N> {
|
|
302
|
+
* return event.getTypeName() === name;
|
|
303
|
+
* }
|
|
304
|
+
*
|
|
305
|
+
* (A plain `switch (event.getTypeName())` cannot narrow `event` because
|
|
306
|
+
* TypeScript does not narrow unions on method-call discriminants.)
|
|
307
|
+
*/
|
|
308
|
+
export type BinlogEventByTypeName<N extends BinlogEventTypeName> = Extract<
|
|
309
|
+
AnyBinlogEvent,
|
|
310
|
+
{ getTypeName(): N }
|
|
311
|
+
>;
|
|
312
|
+
|
|
313
|
+
/** Look up the concrete event type for a getEventName() value */
|
|
314
|
+
export type BinlogEventByName<N extends BinlogEventName> = Extract<
|
|
315
|
+
AnyBinlogEvent,
|
|
316
|
+
{ getEventName(): N }
|
|
317
|
+
>;
|
|
318
|
+
|
|
238
319
|
// Connection options - can be mysql2 options, Connection, or Pool
|
|
239
320
|
export type ZongJiDsn = string | ConnectionOptions | PoolOptions | Connection | Pool;
|
|
240
321
|
|
|
@@ -254,6 +335,7 @@ declare class ZongJi extends EventEmitter {
|
|
|
254
335
|
filename?: string;
|
|
255
336
|
position?: number;
|
|
256
337
|
startAtEnd?: boolean;
|
|
338
|
+
nonBlock?: boolean;
|
|
257
339
|
};
|
|
258
340
|
/** Current filter settings */
|
|
259
341
|
filters: {
|