@eleven-am/pondsocket-nest 0.0.4 → 0.0.6
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/index.d.ts +47 -33
- package/index.js +1 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -7,15 +7,15 @@ import type {
|
|
|
7
7
|
LeaveEvent,
|
|
8
8
|
JoinResponse, EventResponse,
|
|
9
9
|
ConnectionResponse, UserPresences,
|
|
10
|
-
PondEvenType, PondEvent,
|
|
10
|
+
PondEvenType, PondEvent, PondMessage,
|
|
11
11
|
} from '@eleven-am/pondsocket/types';
|
|
12
12
|
import type { DynamicModule, ModuleMetadata } from '@nestjs/common';
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
type Constructor<T> = new (...args: any[]) => T;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
type ParamDecoratorCallback<Input> = (data: Input, context: Context) => unknown | Promise<unknown>;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
interface CanActivate {
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @desc Whether the client can continue with the request
|
|
@@ -24,13 +24,27 @@ export interface CanActivate {
|
|
|
24
24
|
canActivate(context: Context): boolean | Promise<boolean>;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
interface Metadata extends Omit<ModuleMetadata, 'controllers'> {
|
|
28
28
|
guards?: Constructor<CanActivate>[];
|
|
29
29
|
appModuleName?: string;
|
|
30
30
|
isGlobal?: boolean;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
type NestFuncType<Event extends string, Payload extends PondMessage> = {
|
|
34
|
+
event?: Event;
|
|
35
|
+
broadcast?: Event;
|
|
36
|
+
assigns?: PondAssigns;
|
|
37
|
+
presence?: PondPresence;
|
|
38
|
+
updatePresence?: PondPresence;
|
|
39
|
+
} & Payload;
|
|
40
|
+
|
|
41
|
+
type NestReturnType<EventType extends PondEvenType, Event extends keyof EventType> = Event extends string ?
|
|
42
|
+
EventType[Event] extends [PondMessage, PondMessage] ? NestFuncType<Event, EventType[Event][1]> :
|
|
43
|
+
EventType[Event] extends PondMessage ? NestFuncType<Event, EventType[Event]> :
|
|
44
|
+
never :
|
|
45
|
+
never;
|
|
46
|
+
|
|
47
|
+
declare class Context<Path extends string = string, Event extends PondEvenType = PondEvenType> {
|
|
34
48
|
/**
|
|
35
49
|
* @desc The request object, available in onJoin handlers
|
|
36
50
|
*/
|
|
@@ -110,154 +124,154 @@ export declare class Context<Path extends string = string, Event extends PondEve
|
|
|
110
124
|
/**
|
|
111
125
|
* @desc Decorator that marks a class as a channel
|
|
112
126
|
*/
|
|
113
|
-
|
|
127
|
+
declare function Channel(path?: string): ClassDecorator
|
|
114
128
|
|
|
115
129
|
/**
|
|
116
130
|
* @desc Decorator that marks a property on a class as the channel instance
|
|
117
131
|
* @returns {Channel | PondChannel}
|
|
118
132
|
*/
|
|
119
|
-
|
|
133
|
+
declare function ChannelInstance(channel?: string): PropertyDecorator;
|
|
120
134
|
|
|
121
135
|
/**
|
|
122
136
|
* @desc Decorator that marks a class as an endpoint
|
|
123
137
|
*/
|
|
124
|
-
|
|
138
|
+
declare function Endpoint(path?: string): ClassDecorator;
|
|
125
139
|
|
|
126
140
|
/**
|
|
127
141
|
* @desc Decorator that marks a property on a class as the endpoint instance
|
|
128
142
|
* @returns {Endpoint}
|
|
129
143
|
*/
|
|
130
|
-
|
|
144
|
+
declare function EndpointInstance(): PropertyDecorator;
|
|
131
145
|
|
|
132
146
|
/**
|
|
133
147
|
* @desc Parameter decorator that retrieves the current channel
|
|
134
148
|
* @returns {Channel}
|
|
135
149
|
*/
|
|
136
|
-
|
|
150
|
+
declare const GetChannel: () => ParameterDecorator;
|
|
137
151
|
|
|
138
152
|
/**
|
|
139
153
|
* @desc Parameter decorator that retrieves the current connection headers
|
|
140
154
|
* @returns {IncomingHttpHeaders}
|
|
141
155
|
*/
|
|
142
|
-
|
|
156
|
+
declare const GetConnectionHeaders: (data: void) => ParameterDecorator;
|
|
143
157
|
|
|
144
158
|
/**
|
|
145
159
|
* @desc Parameter decorator that retrieves the current connection request
|
|
146
160
|
* @returns {IncomingConnection}
|
|
147
161
|
*/
|
|
148
|
-
|
|
162
|
+
declare const GetConnectionRequest: (data: void) => ParameterDecorator;
|
|
149
163
|
|
|
150
164
|
/**
|
|
151
165
|
* @desc Parameter decorator that retrieves the current connection response
|
|
152
166
|
* @returns {ConnectionResponse}
|
|
153
167
|
*/
|
|
154
|
-
|
|
168
|
+
declare const GetConnectionResponse: (data: void) => ParameterDecorator;
|
|
155
169
|
|
|
156
170
|
/**
|
|
157
171
|
* @desc Parameter decorator that retrieves the current context
|
|
158
172
|
* @returns {Context}
|
|
159
173
|
*/
|
|
160
|
-
|
|
174
|
+
declare const GetContext: (data: void) => ParameterDecorator;
|
|
161
175
|
|
|
162
176
|
/**
|
|
163
177
|
* @desc Parameter decorator that retrieves the current event params
|
|
164
178
|
* @returns {Params}
|
|
165
179
|
*/
|
|
166
|
-
|
|
180
|
+
declare const GetEventParams: (data: void) => ParameterDecorator;
|
|
167
181
|
|
|
168
182
|
/**
|
|
169
183
|
* @desc Parameter decorator that retrieves the current event payload
|
|
170
184
|
* @returns {PondMessage}
|
|
171
185
|
*/
|
|
172
|
-
|
|
186
|
+
declare const GetEventPayload: (data: void) => ParameterDecorator;
|
|
173
187
|
|
|
174
188
|
/**
|
|
175
189
|
* @desc Parameter decorator that retrieves the current event query
|
|
176
190
|
* @returns {Record<string, string>}
|
|
177
191
|
*/
|
|
178
|
-
|
|
192
|
+
declare const GetEventQuery: (data: void) => ParameterDecorator;
|
|
179
193
|
|
|
180
194
|
/**
|
|
181
195
|
* @desc Parameter decorator that retrieves the current event request
|
|
182
196
|
* @returns {EventRequest}
|
|
183
197
|
*/
|
|
184
|
-
|
|
198
|
+
declare const GetEventRequest: (data: void) => ParameterDecorator;
|
|
185
199
|
|
|
186
200
|
/**
|
|
187
201
|
* @desc Parameter decorator that retrieves the current event response
|
|
188
202
|
* @returns {EventResponse}
|
|
189
203
|
*/
|
|
190
|
-
|
|
204
|
+
declare const GetEventResponse: (data: void) => ParameterDecorator;
|
|
191
205
|
|
|
192
206
|
/**
|
|
193
207
|
* @desc Parameter decorator that retrieves the current join params
|
|
194
208
|
* @returns {JoinParams}
|
|
195
209
|
*/
|
|
196
|
-
|
|
210
|
+
declare const GetJoinParams: (data: void) => ParameterDecorator;
|
|
197
211
|
|
|
198
212
|
/**
|
|
199
213
|
* @desc Parameter decorator that retrieves the current join request
|
|
200
214
|
* @returns {JoinRequest}
|
|
201
215
|
*/
|
|
202
|
-
|
|
216
|
+
declare const GetJoinRequest: (data: void) => ParameterDecorator;
|
|
203
217
|
|
|
204
218
|
/**
|
|
205
219
|
* @desc Parameter decorator that retrieves the current join response
|
|
206
220
|
* @returns {JoinResponse}
|
|
207
221
|
*/
|
|
208
|
-
|
|
222
|
+
declare const GetJoinResponse: (data: void) => ParameterDecorator;
|
|
209
223
|
|
|
210
224
|
/**
|
|
211
225
|
* @desc Parameter decorator that retrieves the current leave event
|
|
212
226
|
* @returns {LeaveEvent}
|
|
213
227
|
*/
|
|
214
|
-
|
|
228
|
+
declare const GetLeaveEvent: (data: void) => ParameterDecorator;
|
|
215
229
|
|
|
216
230
|
/**
|
|
217
231
|
* @desc Parameter decorator that retrieves the current user
|
|
218
232
|
* @returns {UserData}
|
|
219
233
|
*/
|
|
220
|
-
|
|
234
|
+
declare const GetUserData: (data: void) => ParameterDecorator;
|
|
221
235
|
|
|
222
236
|
/**
|
|
223
237
|
* @desc Parameter decorator that retrieves the current user presences
|
|
224
238
|
* @returns {UserPresences}
|
|
225
239
|
*/
|
|
226
|
-
|
|
240
|
+
declare const GetUserPresences: (data: void) => ParameterDecorator;
|
|
227
241
|
|
|
228
242
|
/**
|
|
229
243
|
* @desc Method decorator that marks a method as an onConnection handler
|
|
230
244
|
*/
|
|
231
|
-
|
|
245
|
+
declare function OnConnectionRequest(): MethodDecorator;
|
|
232
246
|
|
|
233
247
|
/**
|
|
234
248
|
* @desc Method decorator that marks a method as an onEvent handler
|
|
235
249
|
*/
|
|
236
|
-
|
|
250
|
+
declare function OnEvent(path?: string): MethodDecorator;
|
|
237
251
|
|
|
238
252
|
/**
|
|
239
253
|
* @desc Method decorator that marks a method as an onJoin handler
|
|
240
254
|
*/
|
|
241
|
-
|
|
255
|
+
declare function OnJoinRequest(): MethodDecorator;
|
|
242
256
|
|
|
243
257
|
/**
|
|
244
258
|
* @desc Method decorator that marks a method as an onLeave handler
|
|
245
259
|
*/
|
|
246
|
-
|
|
260
|
+
declare function OnLeave(): MethodDecorator;
|
|
247
261
|
|
|
248
262
|
/**
|
|
249
263
|
* @desc Decorator that adds guards to a channel's or endpoint's class or method
|
|
250
264
|
* @param guards - The guards to add. It is important to add the guards to a providers array in any module (only necessary if the guards inject dependencies)
|
|
251
265
|
*/
|
|
252
|
-
|
|
266
|
+
declare function PondGuards (...guards: Constructor<CanActivate>[]): ClassDecorator | MethodDecorator;
|
|
253
267
|
|
|
254
268
|
/**
|
|
255
269
|
* @desc Helper function that creates a parameter decorator
|
|
256
270
|
* @param callback - The callback to run when the parameter is being retrieved
|
|
257
271
|
*/
|
|
258
|
-
|
|
272
|
+
declare function createParamDecorator<Input>(callback: ParamDecoratorCallback<Input>): (data: Input) => ParameterDecorator;
|
|
259
273
|
|
|
260
|
-
|
|
274
|
+
declare class PondSocketModule {
|
|
261
275
|
static forRoot({ guards, providers, imports, exports, isGlobal, appModuleName }: Metadata): DynamicModule;
|
|
262
276
|
}
|
|
263
277
|
|
package/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./decorators"), exports);
|
|
18
18
|
__exportStar(require("./modules/pondSocket"), exports);
|
|
19
|
+
__exportStar(require("./helpers/createParamDecorator"), exports);
|