Skip to content

Commit 8c779cc

Browse files
committed
feat: typescript types
1 parent 6756497 commit 8c779cc

File tree

4 files changed

+87
-11
lines changed

4 files changed

+87
-11
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.d.ts

package.json

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "errsole-mysql",
3-
"version": "1.0.3",
3+
"version": "1.0.0",
44
"description": "MySQL storage plugin for Errsole",
55
"main": "lib/index.js",
6+
"types": "types/index.d.ts",
67
"scripts": {
7-
"test": "jest --coverage",
8-
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls"
8+
"test": "echo \"Error: no test specified\" && exit 1"
99
},
1010
"keywords": [
1111
"errsole",
@@ -18,15 +18,11 @@
1818
"license": "MIT",
1919
"dependencies": {
2020
"bcryptjs": "^2.4.3",
21-
"mysql2": "^3.10.1",
21+
"mysql2": "^2.3.3",
2222
"node-cron": "^3.0.3"
2323
},
2424
"files": [
25-
"lib/index.js"
26-
],
27-
"devDependencies": {
28-
"@jest/globals": "^29.7.0",
29-
"coveralls": "^3.1.1",
30-
"jest": "^29.7.0"
31-
}
25+
"lib",
26+
"types"
27+
]
3228
}

tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "commonjs",
5+
"strict": true,
6+
"esModuleInterop": true,
7+
"skipLibCheck": true,
8+
"forceConsistentCasingInFileNames": true
9+
},
10+
"include": [
11+
"lib/**/*",
12+
"types/**/*"
13+
]
14+
}

types/index.d.ts

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
declare module 'errsole-mysql' {
2+
import { PoolOptions } from 'mysql2';
3+
4+
interface Log {
5+
id?: number;
6+
hostname: string;
7+
pid: number;
8+
source: string;
9+
timestamp: Date;
10+
level: string;
11+
message: string;
12+
meta?: string;
13+
}
14+
15+
interface LogFilter {
16+
hostname?: string;
17+
pid?: number;
18+
level_json?: { source: string; level: string }[];
19+
sources?: string[];
20+
levels?: string[];
21+
lt_id?: number;
22+
gt_id?: number;
23+
lte_timestamp?: Date;
24+
gte_timestamp?: Date;
25+
limit?: number;
26+
}
27+
28+
interface Config {
29+
id: number;
30+
key: string;
31+
value: string;
32+
}
33+
34+
interface User {
35+
id: number;
36+
name: string;
37+
email: string;
38+
role: string;
39+
}
40+
41+
class ErrsoleMySQL {
42+
constructor(options: PoolOptions);
43+
44+
getConfig(key: string): Promise<{ item: Config }>;
45+
setConfig(key: string, value: string): Promise<{ item: Config }>;
46+
deleteConfig(key: string): Promise<{}>;
47+
48+
postLogs(logEntries: Log[]): Promise<{}>;
49+
getLogs(filters?: LogFilter): Promise<{ items: Log[] }>;
50+
searchLogs(searchTerms: string[], filters?: LogFilter): Promise<{ items: Log[], filters: LogFilter[] }>;
51+
52+
getMeta(id: number): Promise<{ item: { id: number; meta: string } }>;
53+
54+
createUser(user: { name: string; email: string; password: string; role: string }): Promise<{ item: User }>;
55+
verifyUser(email: string, password: string): Promise<{ item: User }>;
56+
getUserCount(): Promise<{ count: number }>;
57+
getAllUsers(): Promise<{ items: User[] }>;
58+
getUserByEmail(email: string): Promise<{ item: User }>;
59+
updateUserByEmail(email: string, updates: Partial<User>): Promise<{ item: User }>;
60+
updatePassword(email: string, currentPassword: string, newPassword: string): Promise<{ item: User }>;
61+
deleteUser(userId: number): Promise<{}>;
62+
}
63+
64+
export default ErrsoleMySQL;
65+
}

0 commit comments

Comments
 (0)