itty-sockets 0.7.1 → 0.8.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.
- package/connect.d.ts +42 -32
- package/package.json +2 -2
package/connect.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
type IttySocketEvent<BaseFormat> = BaseFormat extends UseItty ? 'open' | 'close' | 'message' | 'join' | 'leave' : 'open' | 'close' | 'message';
|
|
2
1
|
type Timestamp = {
|
|
3
2
|
date: number;
|
|
4
3
|
};
|
|
@@ -6,24 +5,22 @@ type UserDetails = {
|
|
|
6
5
|
uid: string;
|
|
7
6
|
alias?: string;
|
|
8
7
|
};
|
|
9
|
-
type
|
|
8
|
+
type EventBase = Timestamp & {
|
|
10
9
|
uid?: string;
|
|
11
10
|
alias?: string;
|
|
12
11
|
};
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
message: MessageType;
|
|
18
|
-
} & Timestamp & OptionalUserDetails;
|
|
12
|
+
export type IttyProtocol = UserDetails & Timestamp;
|
|
13
|
+
export type MessageEvent<T = any> = {
|
|
14
|
+
message: T;
|
|
15
|
+
} & EventBase;
|
|
19
16
|
export type JoinEvent = {
|
|
20
17
|
type: 'join';
|
|
21
18
|
users: number;
|
|
22
|
-
} &
|
|
19
|
+
} & EventBase;
|
|
23
20
|
export type LeaveEvent = {
|
|
24
21
|
type: 'leave';
|
|
25
22
|
users: number;
|
|
26
|
-
} &
|
|
23
|
+
} & EventBase;
|
|
27
24
|
export type ErrorEvent = {
|
|
28
25
|
type: 'error';
|
|
29
26
|
message: string;
|
|
@@ -34,31 +31,44 @@ export type IttySocketOptions = {
|
|
|
34
31
|
echo?: true;
|
|
35
32
|
announce?: true;
|
|
36
33
|
};
|
|
34
|
+
type EventUnion<Events> = {
|
|
35
|
+
[K in Exclude<keyof Events & string, 'message'>]: {
|
|
36
|
+
type: K;
|
|
37
|
+
} & Events[K];
|
|
38
|
+
}[Exclude<keyof Events & string, 'message'>] | (Events extends {
|
|
39
|
+
message: infer M;
|
|
40
|
+
} ? M : never);
|
|
41
|
+
type SendFn<Base, Events extends Record<string, any>> = keyof Events extends never ? <T = any>(message: T, ...args: Base extends IttyProtocol ? [uid?: string] : []) => IttySocket<Base, Events> : (message: EventUnion<Events>, ...args: Base extends IttyProtocol ? [uid?: string] : []) => IttySocket<Base, Events>;
|
|
37
42
|
export interface IttySocketConnect {
|
|
38
|
-
<
|
|
43
|
+
<Events extends Record<string, any> = Record<string, never>>(url: `ws://${string}` | `wss://${string}`, queryParams?: any): IttySocket<object, Events>;
|
|
44
|
+
<Events extends Record<string, any> = Record<string, never>>(channelID: string, options?: IttySocketOptions): IttySocket<IttyProtocol, Events>;
|
|
39
45
|
}
|
|
40
|
-
type
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
type
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
on
|
|
46
|
+
export type IttySocket<Base = object, Events extends Record<string, any> = Record<string, never>> = {
|
|
47
|
+
open: () => IttySocket<Base, Events>;
|
|
48
|
+
close: () => IttySocket<Base, Events>;
|
|
49
|
+
send: SendFn<Base, Events>;
|
|
50
|
+
push: SendFn<Base, Events>;
|
|
51
|
+
remove(type: string, listener: () => any): IttySocket<Base, Events>;
|
|
52
|
+
on(type: 'open', listener: () => any): IttySocket<Base, Events>;
|
|
53
|
+
on(type: 'close', listener: () => any): IttySocket<Base, Events>;
|
|
54
|
+
on<K extends keyof Events & string>(type: K, listener: (event: Base & Events[K] & {
|
|
55
|
+
type: K;
|
|
56
|
+
message: Events[K];
|
|
57
|
+
}) => any): IttySocket<Base, Events>;
|
|
58
|
+
on<T = any>(type: 'message', listener: (event: Base & {
|
|
59
|
+
message: T;
|
|
60
|
+
}) => any): IttySocket<Base, Events>;
|
|
61
|
+
} & (Base extends IttyProtocol ? {
|
|
62
|
+
on(type: 'join', listener: (event: JoinEvent) => any): IttySocket<Base, Events>;
|
|
63
|
+
on(type: 'leave', listener: (event: LeaveEvent) => any): IttySocket<Base, Events>;
|
|
64
|
+
on(type: 'error', listener: (event: ErrorEvent) => any): IttySocket<Base, Events>;
|
|
65
|
+
} : object) & {
|
|
66
|
+
on<T = Record<string, any>>(type: string, listener: (event: Base & T & {
|
|
57
67
|
type: string;
|
|
58
|
-
}) => any): IttySocket<
|
|
59
|
-
on<
|
|
68
|
+
}) => any): IttySocket<Base, Events>;
|
|
69
|
+
on<T = Record<string, any>>(type: (event?: any) => any, listener: (event: Base & T & {
|
|
60
70
|
type: string;
|
|
61
|
-
}) => any): IttySocket<
|
|
62
|
-
}
|
|
71
|
+
}) => any): IttySocket<Base, Events>;
|
|
72
|
+
};
|
|
63
73
|
export declare let connect: IttySocketConnect;
|
|
64
74
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itty-sockets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "WebSockets : simplified and minified.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/bun": "^1.2.3",
|
|
37
|
-
"itty-packager": "^1.
|
|
37
|
+
"itty-packager": "^1.8.1"
|
|
38
38
|
}
|
|
39
39
|
}
|