Skip to content

Commit bcc396b

Browse files
authored
Merge pull request #171 from jesusej/feature/refactor-types
Feature: Refactor and update types
2 parents c065693 + 7c06091 commit bcc396b

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@meteorrn/core",
33
"version": "2.9.0",
44
"description": "Full Meteor Client for React Native",
5+
"types": "src/Meteor.d.ts",
56
"main": "src/index.js",
67
"repository": {
78
"type": "git",

src/Meteor.d.ts

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1+
import { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
2+
13
declare module '@meteorrn/core' {
24
type Callback = (...args: unknown[]) => void;
35

4-
function connect(endpoint: string, options?: any): void;
5-
function disconnect(): void;
6-
function reconnect(): void;
76
type Status =
87
| 'change'
98
| 'connected'
109
| 'disconnected'
1110
| 'loggingIn'
1211
| 'loggingOut';
1312

14-
function call(...args: any[]): void;
15-
function status(): {
16-
connected: boolean;
17-
status: Status;
18-
};
19-
20-
function logout(cb: Callback): void;
21-
function loggingOut(): boolean;
22-
function loggingIn(): boolean;
13+
type useTracker<T> = (cb: () => T) => T;
2314

2415
interface Data {
2516
getUrl(): string;
@@ -35,7 +26,12 @@ declare module '@meteorrn/core' {
3526
socket: unknown;
3627
};
3728
}
38-
function getData(): Data;
29+
30+
interface MeteorError {
31+
error: string;
32+
reason?: string;
33+
details?: string;
34+
}
3935

4036
interface User {
4137
_id: string;
@@ -45,15 +41,53 @@ declare module '@meteorrn/core' {
4541
settings: {};
4642
};
4743
}
48-
function user(): User | undefined;
44+
45+
interface ConnectOptions {
46+
suppressUrlErrors: boolean;
47+
AsyncStorage: AsyncStorageStatic;
48+
reachabilityUrl: string;
49+
}
50+
51+
interface Meteor {
52+
connect(endpoint: string, options?: ConnectOptions): void;
53+
disconnect(): void;
54+
reconnect(): void;
55+
56+
call(...args: any[]): void;
57+
status(): {
58+
connected: boolean;
59+
status: Status;
60+
};
61+
62+
logout(cb: Callback): void;
63+
loggingOut(): boolean;
64+
loggingIn(): boolean;
65+
66+
getData(): Data;
67+
user(): User | undefined;
68+
getAuthToken(): string;
69+
70+
readonly isVerbose: boolean;
71+
enableVerbose(): void;
72+
73+
useTracker<T>(): useTracker<T>;
74+
75+
ddp: Data;
76+
77+
_handleLoginCallback(
78+
err: MeteorError | null | undefined,
79+
res: { token: string; id: string }
80+
): void;
81+
}
82+
4983
interface Accounts {
5084
onLogin(cb: Callback): void;
5185
}
52-
function getAuthToken(): string;
5386

54-
const ddp: Data;
55-
let isVerbose: boolean;
56-
function _handleLoginCallback(err: any, res: any): void;
87+
// Export default Meteor object
88+
const Meteor: Meteor;
89+
export default Meteor;
5790

58-
function useTracker<T>(cb: () => T): T;
91+
// Export other members
92+
export { useTracker, Accounts };
5993
}

0 commit comments

Comments
 (0)