Skip to content

Commit 6e07036

Browse files
committed
feat: supports typescript types
1 parent a0ba08b commit 6e07036

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.d.ts

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.1",
44
"description": "postgreSQL storage plugin for Errsole",
55
"main": "lib/index.js",
6+
"types": "types/index.d.ts",
67
"scripts": {
78
"test": "jest --coverage",
89
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls"
@@ -24,7 +25,8 @@
2425
"pg": "^8.12.0"
2526
},
2627
"files": [
27-
"lib/index.js"
28+
"lib",
29+
"types"
2830
],
2931
"devDependencies": {
3032
"@jest/globals": "^29.7.0",

tsconfig.json

Lines changed: 14 additions & 0 deletions
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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
declare module 'errsole-postgres' {
2+
import { PoolConfig } from 'pg';
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 ErrsolePostgres {
42+
constructor(options: PoolConfig);
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 ErrsolePostgres;
65+
}

0 commit comments

Comments
 (0)