@eleven-am/pondsocket 0.1.129 → 0.1.131
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/package.json +1 -1
- package/types.d.ts +30 -50
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { Server as HTTPServer, IncomingHttpHeaders } from 'http';
|
|
|
2
2
|
|
|
3
3
|
import { WebSocketServer } from 'ws';
|
|
4
4
|
|
|
5
|
-
type Unsubscribe = () => void;
|
|
6
|
-
|
|
7
5
|
export type default_t<T = any> = Record<string, T>;
|
|
8
6
|
type IsParam<Path> = Path extends `:${infer Param}` ? Param : never;
|
|
9
7
|
|
|
@@ -11,16 +9,6 @@ type FilteredParams<Path> = Path extends `${infer First}/${infer Second}`
|
|
|
11
9
|
? IsParam<First> | FilteredParams<Second>
|
|
12
10
|
: IsParam<Path>
|
|
13
11
|
|
|
14
|
-
/**
|
|
15
|
-
* @desc The type for the params in a request
|
|
16
|
-
* @typeParam Path - The path to get the params from
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* const params: Params<'/api/:id'> = {
|
|
20
|
-
* id: '123',
|
|
21
|
-
* foo: 'bar', // Error: Type 'string' is not assignable to type 'undefined'
|
|
22
|
-
* }
|
|
23
|
-
*/
|
|
24
12
|
type Params<Path> = {
|
|
25
13
|
[Key in FilteredParams<Path>]: string
|
|
26
14
|
}
|
|
@@ -38,14 +26,6 @@ type PondMessage = PondObject;
|
|
|
38
26
|
type PondAssigns = PondObject;
|
|
39
27
|
type JoinParams = PondObject;
|
|
40
28
|
|
|
41
|
-
interface UserPresences {
|
|
42
|
-
[userId: string]: PondPresence;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface UserAssigns {
|
|
46
|
-
[userId: string]: PondAssigns;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
29
|
type PondEvent<Path> = EventParams<Path> & {
|
|
50
30
|
payload: PondMessage;
|
|
51
31
|
event: string;
|
|
@@ -68,29 +48,29 @@ type LeaveCallback = (event: LeaveEvent) => void;
|
|
|
68
48
|
|
|
69
49
|
type PondEvenType = { [key: string]: PondMessage };
|
|
70
50
|
|
|
71
|
-
interface UserData {
|
|
72
|
-
assigns:
|
|
73
|
-
presence:
|
|
51
|
+
interface UserData<PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
|
|
52
|
+
assigns: AssignType;
|
|
53
|
+
presence: PresenceType;
|
|
74
54
|
id: string;
|
|
75
55
|
}
|
|
76
56
|
|
|
77
|
-
declare class AbstractRequest<Path extends string> {
|
|
57
|
+
declare class AbstractRequest<Path extends string, PresenceType extends PondPresence, AssignType extends PondAssigns> {
|
|
78
58
|
event: PondEvent<Path>;
|
|
79
59
|
|
|
80
60
|
channelName: string;
|
|
81
61
|
|
|
82
|
-
assigns:
|
|
62
|
+
assigns: Record<string, AssignType>;
|
|
83
63
|
|
|
84
|
-
presence:
|
|
64
|
+
presence: Record<string, PresenceType>;
|
|
85
65
|
}
|
|
86
66
|
|
|
87
|
-
declare class EventRequest<Path extends string> extends AbstractRequest<Path> {
|
|
88
|
-
user: UserData
|
|
67
|
+
declare class EventRequest<Path extends string, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> extends AbstractRequest<Path, PresenceType, AssignType> {
|
|
68
|
+
user: UserData<PresenceType, AssignType>;
|
|
89
69
|
|
|
90
70
|
channel: Channel;
|
|
91
71
|
}
|
|
92
72
|
|
|
93
|
-
declare class EventResponse<EventType extends PondEvenType = PondEvenType> {
|
|
73
|
+
declare class EventResponse<EventType extends PondEvenType = PondEvenType, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
|
|
94
74
|
/**
|
|
95
75
|
* @desc Whether the server has responded to the request
|
|
96
76
|
*/
|
|
@@ -100,7 +80,7 @@ declare class EventResponse<EventType extends PondEvenType = PondEvenType> {
|
|
|
100
80
|
* @desc Accepts the request and optionally assigns data to the client
|
|
101
81
|
* @param assigns - the data to assign to the client
|
|
102
82
|
*/
|
|
103
|
-
accept (assigns?:
|
|
83
|
+
accept (assigns?: AssignType): EventResponse;
|
|
104
84
|
|
|
105
85
|
/**
|
|
106
86
|
* @desc Rejects the request and optionally assigns data to the client
|
|
@@ -108,7 +88,7 @@ declare class EventResponse<EventType extends PondEvenType = PondEvenType> {
|
|
|
108
88
|
* @param errorCode - the error code
|
|
109
89
|
* @param assigns - the data to assign to the client
|
|
110
90
|
*/
|
|
111
|
-
reject (message?: string, errorCode?: number, assigns?:
|
|
91
|
+
reject (message?: string, errorCode?: number, assigns?: AssignType): EventResponse;
|
|
112
92
|
|
|
113
93
|
/**
|
|
114
94
|
* @desc Emits a direct message to the client, accepting the request
|
|
@@ -116,7 +96,7 @@ declare class EventResponse<EventType extends PondEvenType = PondEvenType> {
|
|
|
116
96
|
* @param payload - the payload to send
|
|
117
97
|
* @param assigns - the data to assign to the client
|
|
118
98
|
*/
|
|
119
|
-
send (event: string, payload: PondMessage, assigns?:
|
|
99
|
+
send (event: string, payload: PondMessage, assigns?: AssignType): void;
|
|
120
100
|
|
|
121
101
|
/**
|
|
122
102
|
* @desc Emits a direct message to the client without accepting the request
|
|
@@ -124,7 +104,7 @@ declare class EventResponse<EventType extends PondEvenType = PondEvenType> {
|
|
|
124
104
|
* @param payload - the payload to send
|
|
125
105
|
* @param assigns - the data to assign to the client
|
|
126
106
|
*/
|
|
127
|
-
sendOnly <Key extends keyof EventType> (event: Key, payload: EventType[Key], assigns?:
|
|
107
|
+
sendOnly <Key extends keyof EventType> (event: Key, payload: EventType[Key], assigns?: AssignType): void;
|
|
128
108
|
|
|
129
109
|
/**
|
|
130
110
|
* @desc Sends a message to all clients in the channel
|
|
@@ -153,14 +133,14 @@ declare class EventResponse<EventType extends PondEvenType = PondEvenType> {
|
|
|
153
133
|
* @param presence - the initial presence data
|
|
154
134
|
* @param userId - the id of the user to track
|
|
155
135
|
*/
|
|
156
|
-
trackPresence (presence:
|
|
136
|
+
trackPresence (presence: PresenceType, userId?: string): EventResponse;
|
|
157
137
|
|
|
158
138
|
/**
|
|
159
139
|
* @desc Updates a user's presence in the channel
|
|
160
140
|
* @param presence - the updated presence data
|
|
161
141
|
* @param userId - the id of the user to update
|
|
162
142
|
*/
|
|
163
|
-
updatePresence (presence:
|
|
143
|
+
updatePresence (presence: PresenceType, userId?: string): EventResponse;
|
|
164
144
|
|
|
165
145
|
/**
|
|
166
146
|
* @desc Removes a user's presence from the channel
|
|
@@ -197,7 +177,7 @@ declare class Endpoint {
|
|
|
197
177
|
* response.reject('You are not an admin', 403);
|
|
198
178
|
* });
|
|
199
179
|
*/
|
|
200
|
-
createChannel<Path extends string> (path: PondPath<Path>, handler: (request: JoinRequest<Path>, response: JoinResponse) => void | Promise<void>): PondChannel
|
|
180
|
+
createChannel<Path extends string, EventType extends PondEvenType = PondEvenType, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> (path: PondPath<Path>, handler: (request: JoinRequest<Path, PresenceType, AssignType>, response: JoinResponse<EventType, PresenceType, AssignType>) => void | Promise<void>): PondChannel<EventType, PresenceType, AssignType>;
|
|
201
181
|
|
|
202
182
|
/**
|
|
203
183
|
* @desc Broadcasts a message to all clients connected to this endpoint
|
|
@@ -213,7 +193,7 @@ declare class Endpoint {
|
|
|
213
193
|
closeConnection (clientIds: string | string[]): void;
|
|
214
194
|
}
|
|
215
195
|
|
|
216
|
-
export declare class Channel<EventType extends PondEvenType = PondEvenType> {
|
|
196
|
+
export declare class Channel<EventType extends PondEvenType = PondEvenType, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
|
|
217
197
|
/**
|
|
218
198
|
* The name of the channel.
|
|
219
199
|
*/
|
|
@@ -222,13 +202,13 @@ export declare class Channel<EventType extends PondEvenType = PondEvenType> {
|
|
|
222
202
|
/**
|
|
223
203
|
* @desc Gets the current assign data for the channel.
|
|
224
204
|
*/
|
|
225
|
-
getAssigns ():
|
|
205
|
+
getAssigns (): Record<string, AssignType>;
|
|
226
206
|
|
|
227
207
|
/**
|
|
228
208
|
* @desc Gets the assign date for a specific user.
|
|
229
209
|
* @param userId - The id of the user to get the assign data for.
|
|
230
210
|
*/
|
|
231
|
-
getUserData (userId: string):
|
|
211
|
+
getUserData (userId: string): AssignType | null;
|
|
232
212
|
|
|
233
213
|
/**
|
|
234
214
|
* @desc Broadcasts a message to every client in the channel,
|
|
@@ -273,7 +253,7 @@ export declare class Channel<EventType extends PondEvenType = PondEvenType> {
|
|
|
273
253
|
* @param userId - the id of the user to track
|
|
274
254
|
* @param presence - the presence of the user
|
|
275
255
|
*/
|
|
276
|
-
trackPresence (userId: string, presence:
|
|
256
|
+
trackPresence (userId: string, presence: PresenceType): void;
|
|
277
257
|
|
|
278
258
|
/**
|
|
279
259
|
* @desc removes a user's presence from the channel
|
|
@@ -286,18 +266,18 @@ export declare class Channel<EventType extends PondEvenType = PondEvenType> {
|
|
|
286
266
|
* @param userId - the id of the user to update
|
|
287
267
|
* @param presence - the new presence of the user
|
|
288
268
|
*/
|
|
289
|
-
updatePresence (userId: string, presence:
|
|
269
|
+
updatePresence (userId: string, presence: PresenceType): void;
|
|
290
270
|
}
|
|
291
271
|
|
|
292
|
-
declare class JoinRequest<Path extends string> extends AbstractRequest<Path> {
|
|
272
|
+
declare class JoinRequest<Path extends string, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> extends AbstractRequest<Path, PresenceType, AssignType> {
|
|
293
273
|
joinParams: JoinParams;
|
|
294
274
|
|
|
295
|
-
user: UserData
|
|
275
|
+
user: UserData<PresenceType, AssignType>;
|
|
296
276
|
|
|
297
277
|
channel: Channel;
|
|
298
278
|
}
|
|
299
279
|
|
|
300
|
-
declare class JoinResponse<EventType extends PondEvenType = PondEvenType> {
|
|
280
|
+
declare class JoinResponse<EventType extends PondEvenType = PondEvenType, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
|
|
301
281
|
/**
|
|
302
282
|
* @desc Whether the server has responded to the request
|
|
303
283
|
*/
|
|
@@ -307,7 +287,7 @@ declare class JoinResponse<EventType extends PondEvenType = PondEvenType> {
|
|
|
307
287
|
* @desc Accepts the request and optionally assigns data to the client
|
|
308
288
|
* @param assigns - the data to assign to the client
|
|
309
289
|
*/
|
|
310
|
-
accept (assigns?:
|
|
290
|
+
accept (assigns?: AssignType): JoinResponse;
|
|
311
291
|
|
|
312
292
|
/**
|
|
313
293
|
* @desc Rejects the request and optionally assigns data to the client
|
|
@@ -322,7 +302,7 @@ declare class JoinResponse<EventType extends PondEvenType = PondEvenType> {
|
|
|
322
302
|
* @param payload - the payload to send
|
|
323
303
|
* @param assigns - the data to assign to the client
|
|
324
304
|
*/
|
|
325
|
-
send <Key extends keyof EventType> (event: Key, payload: EventType[Key], assigns?:
|
|
305
|
+
send <Key extends keyof EventType> (event: Key, payload: EventType[Key], assigns?: AssignType): JoinResponse;
|
|
326
306
|
|
|
327
307
|
/**
|
|
328
308
|
* @desc Emits a message to all clients in the channel
|
|
@@ -350,7 +330,7 @@ declare class JoinResponse<EventType extends PondEvenType = PondEvenType> {
|
|
|
350
330
|
* @desc tracks the presence of a client
|
|
351
331
|
* @param presence - the presence data to track
|
|
352
332
|
*/
|
|
353
|
-
trackPresence (presence:
|
|
333
|
+
trackPresence (presence: PresenceType): JoinResponse;
|
|
354
334
|
}
|
|
355
335
|
|
|
356
336
|
declare class ConnectionResponse {
|
|
@@ -381,7 +361,7 @@ declare class ConnectionResponse {
|
|
|
381
361
|
send (event: string, payload: PondMessage, assigns?: PondAssigns): void;
|
|
382
362
|
}
|
|
383
363
|
|
|
384
|
-
export declare class PondChannel <EventType extends PondEvenType = PondEvenType> {
|
|
364
|
+
export declare class PondChannel <EventType extends PondEvenType = PondEvenType, PresenceType extends PondPresence = PondPresence, AssignType extends PondAssigns = PondAssigns> {
|
|
385
365
|
/**
|
|
386
366
|
* @desc Handles an event request made by a user
|
|
387
367
|
* @param event - The event to listen for
|
|
@@ -393,7 +373,7 @@ export declare class PondChannel <EventType extends PondEvenType = PondEvenType>
|
|
|
393
373
|
* });
|
|
394
374
|
* });
|
|
395
375
|
*/
|
|
396
|
-
onEvent<Event extends string> (event: PondPath<Event>, handler: (request: EventRequest<Event>, response: EventResponse<EventType>) => void | Promise<void>): void;
|
|
376
|
+
onEvent<Event extends string> (event: PondPath<Event>, handler: (request: EventRequest<Event, PresenceType, AssignType>, response: EventResponse<EventType, PresenceType, AssignType>) => void | Promise<void>): void;
|
|
397
377
|
|
|
398
378
|
/**
|
|
399
379
|
* @desc Broadcasts a message to all users in a channel
|
|
@@ -419,7 +399,7 @@ export declare class PondChannel <EventType extends PondEvenType = PondEvenType>
|
|
|
419
399
|
* @desc Gets a channel by name
|
|
420
400
|
* @param channelName - The name of the channel to get
|
|
421
401
|
*/
|
|
422
|
-
public getChannel (channelName: string): Channel<EventType
|
|
402
|
+
public getChannel (channelName: string): Channel<EventType, PresenceType, AssignType>;
|
|
423
403
|
}
|
|
424
404
|
|
|
425
405
|
declare class PondSocket {
|