Skip to content

Commit 32d7bb5

Browse files
committed
Added typescript types declarations
Bumped node version to 22
1 parent f5b4ff6 commit 32d7bb5

File tree

9 files changed

+176
-10
lines changed

9 files changed

+176
-10
lines changed

.github/workflows/dev-packages.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: actions/setup-node@v4
1818
with:
1919
node-version-file: '.nvmrc'
20-
- uses: pnpm/action-setup@v2
20+
- uses: pnpm/action-setup@v4
2121
name: Install pnpm
2222
with:
2323
version: 9

.github/workflows/test.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ jobs:
2626
-e MYSQL_ROOT_PASSWORD=my_password \
2727
-p 3306:3306 \
2828
-d mysql:${{ matrix.mysql-version }} \
29-
--server-id=1 \
30-
--log-bin=/var/lib/mysql/mysql-bin.log \
31-
--binlog-format=row
29+
--log-bin=/var/lib/mysql/mysql-bin.log
3230
3331
- name: Setup NodeJS
3432
uses: actions/setup-node@v4
3533
with:
3634
node-version-file: '.nvmrc'
3735

38-
- uses: pnpm/action-setup@v2
36+
- uses: pnpm/action-setup@v4
3937
name: Install pnpm
4038
with:
4139
version: 9

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20.12.2
1+
v22.14.0

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"scripts": {
1313
"release": "pnpm changeset publish",
14+
"build": "cd types && tsc -b",
1415
"test": "tap run --disable-coverage --allow-incomplete-coverage -- --sequential test/suites.js",
1516
"format": "prettier --write ."
1617
},

pnpm-lock.yaml

+14-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
packages:
2-
- './'
3-
# exclude packages that are inside test directories
4-
- '!test/*'
2+
- 'lib'
3+
- 'types'

types/index.d.ts

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { Socket } from 'net';
2+
3+
export type ZongjiOptions = {
4+
host: string;
5+
user: string;
6+
password: string;
7+
dateStrings?: boolean;
8+
timeZone?: string;
9+
};
10+
11+
interface DatabaseFilter {
12+
[databaseName: string]: string[] | true;
13+
}
14+
15+
export type StartOptions = {
16+
includeEvents?: string[];
17+
excludeEvents?: string[];
18+
/**
19+
* Describe which databases and tables to include (Only for row events). Use database names as the key and pass an array of table names or true (for the entire database).
20+
* Example: { 'my_database': ['allow_table', 'another_table'], 'another_db': true }
21+
*/
22+
includeSchema?: DatabaseFilter;
23+
/**
24+
* Object describing which databases and tables to exclude (Same format as includeSchema)
25+
* Example: { 'other_db': ['disallowed_table'], 'ex_db': true }
26+
*/
27+
excludeSchema?: DatabaseFilter;
28+
/**
29+
* BinLog position filename to start reading events from
30+
*/
31+
filename?: string;
32+
/**
33+
* BinLog position offset to start reading events from in file specified
34+
*/
35+
position?: number;
36+
37+
/**
38+
* Unique server ID for this replication client.
39+
*/
40+
serverId?: number;
41+
};
42+
43+
export type ColumnSchema = {
44+
COLUMN_NAME: string;
45+
COLLATION_NAME: string;
46+
CHARACTER_SET_NAME: string;
47+
COLUMN_COMMENT: string;
48+
COLUMN_TYPE: string;
49+
};
50+
51+
export type ColumnDefinition = {
52+
name: string;
53+
charset: string;
54+
type: number;
55+
metadata: Record<string, any>;
56+
};
57+
58+
export type TableMapEntry = {
59+
columnSchemas: ColumnSchema[];
60+
parentSchema: string;
61+
tableName: string;
62+
columns: ColumnDefinition[];
63+
};
64+
65+
export type BaseBinLogEvent = {
66+
timestamp: number;
67+
getEventName(): string;
68+
69+
/**
70+
* Next position in BinLog file to read from after
71+
* this event.
72+
*/
73+
nextPosition: number;
74+
/**
75+
* Size of this event
76+
*/
77+
size: number;
78+
flags: number;
79+
useChecksum: boolean;
80+
};
81+
82+
export type BinLogRotationEvent = BaseBinLogEvent & {
83+
binlogName: string;
84+
position: number;
85+
};
86+
87+
export type BinLogGTIDLogEvent = BaseBinLogEvent & {
88+
serverId: Buffer;
89+
transactionRange: number;
90+
};
91+
92+
export type BinLogXidEvent = BaseBinLogEvent & {
93+
xid: number;
94+
};
95+
96+
export type BinLogMutationEvent = BaseBinLogEvent & {
97+
tableId: number;
98+
numberOfColumns: number;
99+
tableMap: Record<string, TableMapEntry>;
100+
rows: Record<string, any>[];
101+
};
102+
103+
export type BinLogUpdateEvent = Omit<BinLogMutationEvent, 'rows'> & {
104+
rows: {
105+
before: Record<string, any>;
106+
after: Record<string, any>;
107+
}[];
108+
};
109+
110+
export type BinLogEvent = BinLogRotationEvent | BinLogGTIDLogEvent | BinLogXidEvent | BinLogMutationEvent;
111+
112+
// @vlasky/mysql Connection
113+
export interface MySQLConnection {
114+
_socket?: Socket;
115+
/** There are other forms of this method as well - this is the most basic one. */
116+
query(sql: string, callback: (error: any, results: any, fields: any) => void): void;
117+
}
118+
119+
export default class ZongJi {
120+
connection: MySQLConnection;
121+
constructor(options: ZongjiOptions);
122+
123+
start(options: StartOptions): void;
124+
stop(): void;
125+
pause(): void;
126+
resume(): void;
127+
128+
on(type: 'binlog' | string, callback: (event: BinLogEvent) => void);
129+
}

types/package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "@powersync/types-mysql-zongji",
3+
"version": "0.0.1",
4+
"description": "Types package for Powersync MySQL ZongJi",
5+
"main": "",
6+
"types": "index.d.ts",
7+
"scripts": {
8+
"build": "tsc -b"
9+
},
10+
"devDependencies": {
11+
"typescript": "^5.8.3"
12+
}
13+
}

types/tsconfig.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"strict": true,
7+
"declaration": true,
8+
"emitDeclarationOnly": true,
9+
"skipLibCheck": true,
10+
"esModuleInterop": true
11+
},
12+
"include": ["index.d.ts"]
13+
}

0 commit comments

Comments
 (0)