@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.
Files changed (43) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +35 -5
  3. package/example.js +5 -0
  4. package/index.d.ts +84 -2
  5. package/index.js +167 -59
  6. package/lib/binlog_event.js +39 -0
  7. package/lib/code_map.js +9 -1
  8. package/lib/common.js +71 -43
  9. package/lib/json_decode.js +61 -18
  10. package/lib/packet/binlog.js +7 -0
  11. package/lib/reader.js +4 -143
  12. package/lib/sequence/binlog.js +29 -7
  13. package/package.json +9 -6
  14. package/.claude/settings.local.json +0 -16
  15. package/.mcp.json +0 -17
  16. package/.tap/processinfo/84de694d-068b-4ac7-b4d8-f835c2122b2d.json +0 -892
  17. package/.tap/processinfo/a1e9627e-66eb-412c-aaa5-079a2eb9f385.json +0 -891
  18. package/.tap/processinfo/abc34c6f-f4aa-4405-8f9a-947048be1df2.json +0 -892
  19. package/.tap/processinfo/affe6c5b-a34d-41b9-bb73-4b14d35138de.json +0 -891
  20. package/.tap/processinfo/bf82449d-cdeb-478b-9506-b939a9506bf2.json +0 -883
  21. package/.tap/processinfo/dd98c508-7067-4342-bdf5-63664b630701.json +0 -892
  22. package/.tap/test-results/test_await_end.js.tap +0 -19
  23. package/.tap/test-results/test_await_end2.js.tap +0 -27
  24. package/.tap/test-results/test_debug_init.js.tap +0 -23
  25. package/.tap/test-results/test_debug_init2.js.tap +0 -35
  26. package/.tap/test-results/test_invalid_host.js.tap +0 -34
  27. package/.tap/test-results/test_minimal.js.tap +0 -26
  28. package/.tap/test-results/test_queryseq.js.tap +0 -14
  29. package/.tap/test-results/test_timing.js.tap +0 -17
  30. package/.tap/test-results/test_unref.js.tap +0 -15
  31. package/.travis.yml +0 -15
  32. package/CLAUDE.md +0 -99
  33. package/GTID.md +0 -54
  34. package/TODO.md +0 -43
  35. package/docker-compose.yml +0 -33
  36. package/docker-test.sh +0 -11
  37. package/eslint.config.js +0 -35
  38. package/jsconfig.json +0 -15
  39. package/lib/packet/combinlog.js +0 -27
  40. package/lib/packet/index.js +0 -66
  41. package/notes.md +0 -77
  42. package/scripts/start-mysql.sh +0 -28
  43. package/workerthreads.md +0 -173
@@ -1,19 +0,0 @@
1
- Test file starting
2
- TAP version 14
3
- Invalid host test starting
4
- Got error: ENOTFOUND
5
- # Subtest: Connect to an invalid host
6
- ok 1 - should be equal
7
- Invalid host test ending
8
- 1..1
9
- ok 1 - Connect to an invalid host # time=112.602ms
10
-
11
- MySQL test starting
12
- Query callback! err: null
13
- # Subtest: Simple MySQL query
14
- ok 1 - query worked
15
- MySQL test ending
16
- 1..1
17
- ok 2 - Simple MySQL query # time=11.899ms
18
-
19
- 1..2
@@ -1,27 +0,0 @@
1
- TAP version 14
2
- # Subtest: Connect to an invalid host
3
- ok 1 - should be equal
4
- 1..1
5
- ok 1 - Connect to an invalid host # time=11.133ms
6
-
7
- # Subtest: Simple MySQL query
8
- not ok 1 - test unfinished
9
- ---
10
- at:
11
- fileName: test_await_end2.js
12
- lineNumber: 35
13
- columnNumber: 5
14
- isToplevel: true
15
- stack: |
16
- test_await_end2.js:35:5
17
- test: Simple MySQL query
18
- source: |
19
- });
20
-
21
- tap.test('Simple MySQL query', async test => {
22
- ----^
23
- const conn = mysql.createConnection(settings);
24
- ...
25
-
26
- Bail out! test unfinished
27
- Bail out! test unfinished
@@ -1,23 +0,0 @@
1
- Test file starting
2
- TAP version 14
3
- Invalid host test starting
4
- Got error: ENOTFOUND
5
- # Subtest: Connect to an invalid host
6
- ok 1 - should be equal
7
- 1..1
8
- Teardown called
9
- ok 1 - Connect to an invalid host # time=10.054ms
10
-
11
- MySQL connection test starting
12
- Connection object created
13
- Running query...
14
- Query issued, waiting for callback...
15
- Query callback received
16
- Query result: [ { test: 1 } ]
17
- Connection destroyed
18
- # Subtest: Create MySQL connection
19
- ok 1 - connection worked
20
- 1..1
21
- ok 2 - Create MySQL connection # time=11.332ms
22
-
23
- 1..2
@@ -1,35 +0,0 @@
1
- Test file starting
2
- TAP version 14
3
- Invalid host test starting
4
- Got error: ENOTFOUND
5
- # Subtest: Connect to an invalid host
6
- ok 1 - should be equal
7
- 1..1
8
- Teardown called
9
- ok 1 - Connect to an invalid host # time=9.46ms
10
-
11
- Init db test starting
12
- Creating connection...
13
- Connection created, running querySequence...
14
- querySequence called, waiting for callback...
15
- # Subtest: Init db with querySequence
16
- not ok 1 - test unfinished
17
- ---
18
- at:
19
- fileName: test_debug_init2.js
20
- lineNumber: 37
21
- columnNumber: 5
22
- isToplevel: true
23
- stack: |
24
- test_debug_init2.js:37:5
25
- test: Init db with querySequence
26
- source: |
27
- });
28
-
29
- tap.test('Init db with querySequence', async test => {
30
- ----^
31
- console.log('Init db test starting');
32
- ...
33
-
34
- Bail out! test unfinished
35
- Bail out! test unfinished
@@ -1,34 +0,0 @@
1
- Test file starting at: 1769661151919
2
- TAP version 14
3
- Invalid host test starting at: 1769661151922
4
- ZongJi.start() called at: 1769661151927
5
- Got error at: 1769661151930 ENOTFOUND
6
- # Subtest: Connect to an invalid host
7
- ok 1 - should be equal
8
- 1..1
9
- Teardown called at: 1769661151931
10
- ok 1 - Connect to an invalid host # time=10.183ms
11
-
12
- Init db test starting at: 1769661151932
13
- # Subtest: Initialise testing db
14
- not ok 1 - test unfinished
15
- ---
16
- at:
17
- fileName: test_invalid_host.js
18
- lineNumber: 30
19
- columnNumber: 5
20
- isToplevel: true
21
- stack: |
22
- test_invalid_host.js:30:5
23
- test: Initialise testing db
24
- source: |
25
- });
26
-
27
- tap.test('Initialise testing db', async test => {
28
- ----^
29
- console.log('Init db test starting at:', Date.now());
30
- try {
31
- ...
32
-
33
- Bail out! test unfinished
34
- Bail out! test unfinished
@@ -1,26 +0,0 @@
1
- Test file starting
2
- TAP version 14
3
- Invalid host test starting
4
- Calling zongji.start()
5
- zongji.start() returned
6
- Got error: ENOTFOUND
7
- # Subtest: Connect to an invalid host
8
- ok 1 - should be equal
9
- Calling test.end()
10
- 1..1
11
- Teardown starting
12
- Teardown completed
13
- ok 1 - Connect to an invalid host # time=10.599ms
14
-
15
- MySQL test starting
16
- Calling conn.query()
17
- conn.query() returned, waiting...
18
- test.end() returned
19
- Query callback! err: null
20
- # Subtest: Simple MySQL query
21
- ok 1 - query worked
22
- Timeout reached
23
- 1..1
24
- ok 2 - Simple MySQL query # time=5001.569ms
25
-
26
- 1..2
@@ -1,14 +0,0 @@
1
- Test file starting
2
- TAP version 14
3
- Init db test starting
4
- Creating connection...
5
- Connection created, running querySequence...
6
- querySequence called, waiting for callback...
7
- querySequence callback received, error: null
8
- Init complete
9
- # Subtest: Init db with querySequence
10
- ok 1 - init worked
11
- 1..1
12
- ok 1 - Init db with querySequence # time=18.904ms
13
-
14
- 1..1
@@ -1,17 +0,0 @@
1
- Test file starting at: 1769661140028
2
- TAP version 14
3
- Test 1 starting at: 1769661140031
4
- Test 1 ending at: 1769661140132
5
- # Subtest: Test 1
6
- ok 1 - test 1 done
7
- 1..1
8
- ok 1 - Test 1 # time=103.078ms
9
-
10
- Test 2 starting at: 1769661140135
11
- Test 2 init complete at: 1769661140170
12
- # Subtest: Test 2 - init db
13
- ok 1 - database initialized
14
- 1..1
15
- ok 2 - Test 2 - init db # time=35.205ms
16
-
17
- 1..2
@@ -1,15 +0,0 @@
1
- TAP version 14
2
- # Subtest: Connect to an invalid host - with explicit cleanup
3
- ok 1 - should be equal
4
- not ok 2 - getaddrinfo ENOTFOUND wronghost
5
- ---
6
- errno: -3008
7
- code: ENOTFOUND
8
- syscall: getaddrinfo
9
- hostname: wronghost
10
- fatal: true
11
- tapCaught: unhandledRejection
12
- ...
13
-
14
- Bail out! getaddrinfo ENOTFOUND wronghost
15
- Bail out! getaddrinfo ENOTFOUND wronghost
package/.travis.yml DELETED
@@ -1,15 +0,0 @@
1
- language: node_js
2
- sudo: required
3
- dist: trusty
4
- node_js:
5
- - "8"
6
- - "12"
7
- services:
8
- - docker
9
- before_script:
10
- - npm run lint
11
- - docker run -p 3355:3306 --name mysql-55 -e MYSQL_ROOT_PASSWORD=numtel -d mysql:5.5 --server-id=1 --log-bin=/var/lib/mysql/mysql-bin.log --binlog-format=row
12
- - docker run -p 3356:3306 --name mysql-56 -e MYSQL_ROOT_PASSWORD=numtel -d mysql:5.6 --server-id=1 --log-bin=/var/lib/mysql/mysql-bin.log --binlog-format=row
13
- - docker run -p 3357:3306 --name mysql-57 -e MYSQL_ROOT_PASSWORD=numtel -d mysql:5.7 --server-id=1 --log-bin=/var/lib/mysql/mysql-bin.log --binlog-format=row
14
- script:
15
- - ./test/travis/runner.sh
package/CLAUDE.md DELETED
@@ -1,99 +0,0 @@
1
- # CLAUDE.md
2
-
3
- This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
- ## Project Overview
6
-
7
- @vlasky/zongji is a MySQL binlog listener for Node.js that supports MySQL 5.7-8.4. It provides real-time change data capture (CDC) by listening to MySQL binary log events.
8
-
9
- The library uses `mysql2` for connections and authentication while implementing custom binlog protocol parsing.
10
-
11
- ## Development Commands
12
-
13
- ```bash
14
- # Install dependencies
15
- npm install
16
-
17
- # Run zongji tests (requires Docker)
18
- npm test
19
-
20
- # Run linter
21
- npm run lint
22
-
23
- # Check TypeScript definitions and JS type errors
24
- npm run checkjs
25
- ```
26
-
27
- ## Docker MySQL Client Command
28
-
29
- - Use this command to launch the mysql client: docker exec -it docker-mysql mysql -u root -psecret
30
-
31
- ## Architecture Overview
32
-
33
- The codebase follows an event-driven architecture with these key components:
34
-
35
- 1. **Main Entry**: `index.js` - ZongJi class extending EventEmitter
36
- 2. **Dual Connection Pattern**:
37
- - Control connection for queries/metadata
38
- - Binlog connection for streaming events
39
- 3. **Event Processing Pipeline**:
40
- - Custom `Command` class in `lib/sequence/binlog.js` for mysql2 integration
41
- - Binary protocol parsing via `Parser` class in `lib/reader.js`
42
- - Event type definitions in `lib/binlog_event.js`
43
- - Row event handling in `lib/rows_event.js`
44
- - Type-specific decoders (datetime, JSON) in lib/
45
-
46
- ## Key Implementation Details
47
-
48
- - **Module System**: Uses ES modules (ESM) with import/export syntax
49
- - **TypeScript Support**: Includes TypeScript definitions (index.d.ts)
50
- - **MySQL Driver**: Uses `mysql2` for connections, authentication (including caching_sha2_password), and base protocol
51
- - **Custom Binlog Command**: Implements COM_BINLOG_DUMP (0x12) via custom `Command` class compatible with mysql2's command queue
52
- - **Parser Compatibility**: Custom `Parser` class in `lib/reader.js` provides mysql2 packet parsing interface
53
- - **Event Filtering**: Schema and event-type filtering before emission
54
- - **Position Tracking**: Maintains binlog filename and position for resumable processing
55
- - **Table Metadata**: Caches table structures for efficient row decoding
56
- - **Checksum Support**: Automatic detection and handling of binlog checksums (CRC32)
57
- - **Timezone Support**: Datetime decoders respect mysql2's `timezone` connection option
58
- - **GTID Support**: Parses Gtid, AnonymousGtid, and PreviousGtids events
59
-
60
- ## Testing
61
-
62
- Tests use Docker Compose with MySQL containers:
63
- - Configuration in `docker-compose.yml`
64
- - Test database setup in `test/helpers/`
65
- - Event-specific tests in `test/` directory
66
- - Uses `tap` test framework (v21+)
67
-
68
- **Before running tests**, always:
69
- 1. Ensure Docker containers are running: `docker-compose up -d` (or specific services e.g. `docker-compose up -d mysql80 mysql84`)
70
- 2. Note: MySQL 5.7 image does not support ARM64 (Apple Silicon) — skip it on those machines
71
- 3. Wait for MySQL to be ready before running tests (containers need ~10-15 seconds to initialise)
72
-
73
- When modifying binlog parsing or adding event support, ensure tests cover:
74
- - Event parsing correctness
75
- - Position tracking accuracy
76
- - Error handling scenarios
77
- - MySQL version compatibility
78
-
79
- ## Common Development Tasks
80
-
81
- 1. **Adding new event types**: Update `lib/binlog_event.js` and `lib/code_map.js`
82
- 2. **Supporting new MySQL types**: Modify type parsing in `lib/rows_event.js` and `lib/common.js`
83
- 3. **Protocol changes**: Update `lib/sequence/binlog.js` for command handling, `lib/reader.js` for parsing
84
- 4. **Connection handling**: Modify `index.js` for connection lifecycle changes
85
-
86
- ## Requirements
87
-
88
- - Node.js >= 18.0
89
- - MySQL 5.7, 8.0, or 8.4 with binlog enabled
90
-
91
- ## Development Principles
92
-
93
- - **Avoid Duplicate Code**: Avoid creating duplicate code or duplicate functionality
94
-
95
- # important-instruction-reminders
96
- Do what has been asked; nothing more, nothing less.
97
- NEVER create files unless they're absolutely necessary for achieving your goal.
98
- ALWAYS prefer editing an existing file to creating a new one.
99
- NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.
package/GTID.md DELETED
@@ -1,54 +0,0 @@
1
- # GTID discussion
2
-
3
- This file summarizes our discussion about GTID handling in zongji and possible
4
- exposure patterns for application use.
5
-
6
- ## Current behavior
7
-
8
- - GTID-related binlog events are parsed and emitted as their own events:
9
- - `Gtid`
10
- - `AnonymousGtid`
11
- - `PreviousGtids`
12
- - The GTID event objects contain:
13
- - `event.gtid` (string: `uuid:sequence`)
14
- - `event.sid` (UUID string)
15
- - `event.gno` (sequence number)
16
- - For `PreviousGtids`: `event.sids` and `event.gtidSet`
17
- - Row events (`WriteRows`, `UpdateRows`, `DeleteRows`) do not currently include
18
- GTID information.
19
-
20
- ## Practical uses for GTID
21
-
22
- - Checkpointing: store the latest GTID and resume from it after restart/failover.
23
- - Deduplication / exactly-once: use GTID as a unique transaction ID.
24
- - Auditing / debugging: correlate binlog events with replication state.
25
-
26
- ## Transaction boundaries
27
-
28
- - Start of a GTID transaction:
29
- - `Gtid` event (when `gtid_mode=ON`).
30
- - Start of a non-GTID transaction:
31
- - `Query` event with `BEGIN`.
32
- - End (commit) of row-based transactions:
33
- - `Xid` event.
34
- - End (commit/rollback) of statement-based transactions:
35
- - `Query` event with `COMMIT` or `ROLLBACK`.
36
-
37
- ## Open questions / options
38
-
39
- 1) Add `zongji.lastGtid`:
40
- - Updated when a `Gtid` or `AnonymousGtid` event is received.
41
- - Useful for external checkpointing without subscribing to GTID events.
42
-
43
- 2) Attach `event.gtid` to row events:
44
- - Copied from `zongji.lastGtid`.
45
- - Lets users compare row events to see when GTID changes.
46
- - Only reliable when `gtid_mode=ON` (undefined for non-GTID transactions).
47
-
48
- 3) Add high-level transaction boundary events:
49
- - Emit `transactionStart`/`transactionCommit`/`transactionRollback` with
50
- GTID and event metadata.
51
-
52
- Notes:
53
- - Adding `event.gtid` and/or `zongji.lastGtid` is additive and should be
54
- backward-compatible, but it depends on GTID mode being enabled in MySQL.
package/TODO.md DELETED
@@ -1,43 +0,0 @@
1
- # TODO: MySQL 8 binlog events and partial JSON support
2
-
3
- This note summarizes the discussion about additional MySQL 8 binlog events and
4
- partial JSON handling.
5
-
6
- ## Events not currently supported
7
-
8
- - PARTIAL_UPDATE_ROWS_EVENT
9
- - TRANSACTION_PAYLOAD_EVENT
10
- - HEARTBEAT_LOG_EVENT_V2
11
-
12
- Currently these events are not mapped in `lib/code_map.js`, so they arrive as
13
- `Unknown` and are effectively ignored.
14
-
15
- ## Practical impact
16
-
17
- - PARTIAL_UPDATE_ROWS_EVENT:
18
- - Emitted when `binlog_row_value_options=PARTIAL_JSON`.
19
- - Encodes JSON diffs instead of full JSON values.
20
- - Only appears if partial JSON is enabled.
21
- - TRANSACTION_PAYLOAD_EVENT:
22
- - Used with transaction compression (MySQL 8.0.20+).
23
- - Wraps multiple events in a compressed payload.
24
- - Only appears if transaction compression is enabled.
25
- - HEARTBEAT_LOG_EVENT_V2:
26
- - Replication keepalive/monitoring; no data changes.
27
-
28
- ## Possible support approach
29
-
30
- 1) Add event mappings and parsers:
31
- - Update `lib/code_map.js` to map event IDs.
32
- - Implement parser classes in `lib/binlog_event.js` (and any helpers).
33
- 2) Extend tests:
34
- - Add targeted tests that enable the corresponding MySQL settings.
35
- - Assert event emission and basic payload shape.
36
-
37
- ## Partial JSON strategy options
38
-
39
- - Option A: expose raw JSON diff data from PARTIAL_UPDATE_ROWS_EVENT.
40
- - Lowest effort; consumers apply patches.
41
- - Option B: reconstruct full JSON values.
42
- - Requires FULL row image or a row-state cache to apply diffs.
43
- - More complex but produces complete row values.
@@ -1,33 +0,0 @@
1
- ---
2
- services:
3
- mysql57:
4
- image: mysql:5.7
5
- command: [ "--server-id=1", "--log-bin=/var/lib/mysql/mysql-bin.log", "--binlog-format=row"]
6
- networks:
7
- default:
8
- aliases:
9
- - mysql57
10
- environment:
11
- MYSQL_ROOT_PASSWORD: secret
12
-
13
- mysql80:
14
- image: mysql:8.0
15
- command: [ "--server-id=1", "--log-bin=/var/lib/mysql/mysql-bin.log", "--binlog-format=row"]
16
- networks:
17
- default:
18
- aliases:
19
- - mysql80
20
- environment:
21
- MYSQL_ROOT_PASSWORD: secret
22
-
23
- mysql84:
24
- image: mysql:8.4
25
- command: [ "--server-id=1", "--log-bin=/var/lib/mysql/mysql-bin.log", "--binlog-format=row"]
26
- ports:
27
- - "3306:3306"
28
- networks:
29
- default:
30
- aliases:
31
- - mysql84
32
- environment:
33
- MYSQL_ROOT_PASSWORD: secret
package/docker-test.sh DELETED
@@ -1,11 +0,0 @@
1
- #!/bin/bash
2
- MYSQL_HOSTS="mysql57 mysql80 mysql84"
3
-
4
- for hostname in ${MYSQL_HOSTS}; do
5
- echo $hostname + node 18
6
- docker run -it --network=zongji_default -e MYSQL_HOST=$hostname -w /build -v $PWD:/build node:18 npm test
7
- echo $hostname + node 20
8
- docker run -it --network=zongji_default -e MYSQL_HOST=$hostname -w /build -v $PWD:/build node:20 npm test
9
- echo $hostname + node 22
10
- docker run -it --network=zongji_default -e MYSQL_HOST=$hostname -w /build -v $PWD:/build node:22 npm test
11
- done
package/eslint.config.js DELETED
@@ -1,35 +0,0 @@
1
- import js from '@eslint/js';
2
-
3
- export default [
4
- { ignores: ['.tap/'] },
5
- js.configs.recommended,
6
- {
7
- languageOptions: {
8
- ecmaVersion: 2022,
9
- sourceType: 'module',
10
- globals: {
11
- Buffer: 'readonly',
12
- clearImmediate: 'readonly',
13
- clearInterval: 'readonly',
14
- clearTimeout: 'readonly',
15
- console: 'readonly',
16
- process: 'readonly',
17
- setImmediate: 'readonly',
18
- setInterval: 'readonly',
19
- setTimeout: 'readonly',
20
- },
21
- },
22
- rules: {
23
- 'comma-dangle': ['warn', 'only-multiline'],
24
- 'eol-last': ['error'],
25
- 'keyword-spacing': ['error', { before: true }],
26
- 'no-console': 'off',
27
- 'no-trailing-spaces': ['error', { skipBlankLines: true }],
28
- 'no-unused-vars': 'warn',
29
- 'no-var': 'warn',
30
- 'quotes': ['warn', 'single', 'avoid-escape'],
31
- 'semi': ['error', 'always'],
32
- 'space-before-blocks': 'error',
33
- },
34
- },
35
- ];
package/jsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "checkJs": true,
4
- "allowJs": true,
5
- "noEmit": true,
6
- "target": "ES2022",
7
- "module": "NodeNext",
8
- "moduleResolution": "NodeNext",
9
- "skipDefaultLibCheck": true,
10
- "maxNodeModuleJsDepth": 0,
11
- "types": ["node"]
12
- },
13
- "include": ["index.js", "index.d.ts", "lib/**/*.js"],
14
- "exclude": ["node_modules", ".tap"]
15
- }
@@ -1,27 +0,0 @@
1
- class ComBinlog {
2
- constructor({ serverId, nonBlock, filename, position }) {
3
- this.command = 0x12;
4
- this.position = position || 4;
5
-
6
- // will send eof package if there is no more binlog event
7
- // https://dev.mysql.com/doc/internals/en/com-binlog-dump.html#binlog-dump-non-block
8
- this.flags = nonBlock ? 1 : 0;
9
-
10
- this.serverId = serverId || 1;
11
- this.filename = filename || '';
12
- }
13
-
14
- write(writer) {
15
- writer.writeUnsignedNumber(1, this.command);
16
- writer.writeUnsignedNumber(4, this.position);
17
- writer.writeUnsignedNumber(2, this.flags);
18
- writer.writeUnsignedNumber(4, this.serverId);
19
- writer.writeNullTerminatedString(this.filename);
20
- }
21
-
22
- parse() {
23
- throw new Error('should never be called here');
24
- }
25
- }
26
-
27
- export default ComBinlog;
@@ -1,66 +0,0 @@
1
- import ComBinlog from './combinlog.js';
2
- import initBinlogPacketClass from './binlog.js';
3
-
4
- // from npm package mysql
5
- class EofPacket {
6
- constructor(options = {}) {
7
- this.fieldCount = undefined;
8
- this.warningCount = options.warningCount;
9
- this.serverStatus = options.serverStatus;
10
- this.protocol41 = options.protocol41;
11
- }
12
-
13
- parse(parser) {
14
- this.fieldCount = parser.parseUnsignedNumber(1);
15
- if (this.protocol41) {
16
- this.warningCount = parser.parseUnsignedNumber(2);
17
- this.serverStatus = parser.parseUnsignedNumber(2);
18
- }
19
- }
20
-
21
- write(writer) {
22
- writer.writeUnsignedNumber(1, 0xfe);
23
- if (this.protocol41) {
24
- writer.writeUnsignedNumber(2, this.warningCount);
25
- writer.writeUnsignedNumber(2, this.serverStatus);
26
- }
27
- }
28
- }
29
-
30
- // from npm package mysql
31
- class ErrorPacket {
32
- constructor(options = {}) {
33
- this.fieldCount = options.fieldCount;
34
- this.errno = options.errno;
35
- this.sqlStateMarker = options.sqlStateMarker;
36
- this.sqlState = options.sqlState;
37
- this.message = options.message;
38
- }
39
-
40
- parse(parser) {
41
- this.fieldCount = parser.parseUnsignedNumber(1);
42
- this.errno = parser.parseUnsignedNumber(2);
43
-
44
- // sqlStateMarker ('#' = 0x23) indicates error packet format
45
- if (parser.peak() === 0x23) {
46
- this.sqlStateMarker = parser.parseString(1);
47
- this.sqlState = parser.parseString(5);
48
- }
49
-
50
- this.message = parser.parsePacketTerminatedString();
51
- }
52
-
53
- write(writer) {
54
- writer.writeUnsignedNumber(1, 0xff);
55
- writer.writeUnsignedNumber(2, this.errno);
56
-
57
- if (this.sqlStateMarker) {
58
- writer.writeString(this.sqlStateMarker);
59
- writer.writeString(this.sqlState);
60
- }
61
-
62
- writer.writeString(this.message);
63
- }
64
- }
65
-
66
- export { EofPacket, ErrorPacket, ComBinlog, initBinlogPacketClass };