@eleven-am/pondsocket 0.1.95 → 0.1.96
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/nest.js +180 -126
- package/package.json +1 -1
- package/types.d.ts +85 -16
package/nest.js
CHANGED
|
@@ -37,6 +37,72 @@ const endpointClassKey = Symbol('endpoint');
|
|
|
37
37
|
const channelsClassKey = Symbol('channels');
|
|
38
38
|
const parametersKey = Symbol('generalParametersKey');
|
|
39
39
|
const pondGuardsKey = Symbol('pondGuardsKey');
|
|
40
|
+
class Context {
|
|
41
|
+
constructor(request, response, instance, propertyKey) {
|
|
42
|
+
this.request = request;
|
|
43
|
+
this.response = response;
|
|
44
|
+
this.instance = instance;
|
|
45
|
+
this.propertyKey = propertyKey;
|
|
46
|
+
this.data = {};
|
|
47
|
+
}
|
|
48
|
+
get joinRequest() {
|
|
49
|
+
var _a;
|
|
50
|
+
return (_a = this.request.joinRequest) !== null && _a !== void 0 ? _a : null;
|
|
51
|
+
}
|
|
52
|
+
get eventRequest() {
|
|
53
|
+
var _a;
|
|
54
|
+
return (_a = this.request.eventRequest) !== null && _a !== void 0 ? _a : null;
|
|
55
|
+
}
|
|
56
|
+
get connection() {
|
|
57
|
+
var _a;
|
|
58
|
+
return (_a = this.request.connection) !== null && _a !== void 0 ? _a : null;
|
|
59
|
+
}
|
|
60
|
+
get leveeEvent() {
|
|
61
|
+
var _a;
|
|
62
|
+
return (_a = this.request.leveeEvent) !== null && _a !== void 0 ? _a : null;
|
|
63
|
+
}
|
|
64
|
+
get joinResponse() {
|
|
65
|
+
var _a;
|
|
66
|
+
return (_a = this.response.joinResponse) !== null && _a !== void 0 ? _a : null;
|
|
67
|
+
}
|
|
68
|
+
get eventResponse() {
|
|
69
|
+
var _a;
|
|
70
|
+
return (_a = this.response.eventResponse) !== null && _a !== void 0 ? _a : null;
|
|
71
|
+
}
|
|
72
|
+
get connectionResponse() {
|
|
73
|
+
var _a;
|
|
74
|
+
return (_a = this.response.connection) !== null && _a !== void 0 ? _a : null;
|
|
75
|
+
}
|
|
76
|
+
get user() {
|
|
77
|
+
var _a, _b, _c, _d;
|
|
78
|
+
return (_d = (_b = (_a = this.joinRequest) === null || _a === void 0 ? void 0 : _a.user) !== null && _b !== void 0 ? _b : (_c = this.eventRequest) === null || _c === void 0 ? void 0 : _c.user) !== null && _d !== void 0 ? _d : null;
|
|
79
|
+
}
|
|
80
|
+
get channel() {
|
|
81
|
+
var _a, _b, _c, _d;
|
|
82
|
+
return (_d = (_b = (_a = this.joinRequest) === null || _a === void 0 ? void 0 : _a.channel) !== null && _b !== void 0 ? _b : (_c = this.eventRequest) === null || _c === void 0 ? void 0 : _c.channel) !== null && _d !== void 0 ? _d : null;
|
|
83
|
+
}
|
|
84
|
+
get presence() {
|
|
85
|
+
var _a, _b, _c, _d;
|
|
86
|
+
return (_d = (_b = (_a = this.joinRequest) === null || _a === void 0 ? void 0 : _a.presence) !== null && _b !== void 0 ? _b : (_c = this.eventRequest) === null || _c === void 0 ? void 0 : _c.presence) !== null && _d !== void 0 ? _d : null;
|
|
87
|
+
}
|
|
88
|
+
get event() {
|
|
89
|
+
var _a, _b, _c;
|
|
90
|
+
return (_c = (_b = ((_a = this.joinRequest) !== null && _a !== void 0 ? _a : this.eventRequest)) === null || _b === void 0 ? void 0 : _b.event) !== null && _c !== void 0 ? _c : null;
|
|
91
|
+
}
|
|
92
|
+
retrieveClassData(key) {
|
|
93
|
+
return manageClassData(key, this.instance.constructor).get();
|
|
94
|
+
}
|
|
95
|
+
retrieveMethodData(key) {
|
|
96
|
+
return manageMethodData(key, this.instance, this.propertyKey).get();
|
|
97
|
+
}
|
|
98
|
+
addData(key, value) {
|
|
99
|
+
this.data[key] = value;
|
|
100
|
+
}
|
|
101
|
+
getData(key) {
|
|
102
|
+
var _a;
|
|
103
|
+
return (_a = this.data[key]) !== null && _a !== void 0 ? _a : null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
40
106
|
function isNotEmpty(value) {
|
|
41
107
|
return value !== null &&
|
|
42
108
|
value !== undefined &&
|
|
@@ -145,7 +211,7 @@ function PondGuards(...guards) {
|
|
|
145
211
|
};
|
|
146
212
|
}
|
|
147
213
|
exports.PondGuards = PondGuards;
|
|
148
|
-
function resolveGuards(moduleRef,
|
|
214
|
+
function resolveGuards(moduleRef, context) {
|
|
149
215
|
var _a, _b;
|
|
150
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
217
|
const retrieveGuard = (Guard) => {
|
|
@@ -157,12 +223,11 @@ function resolveGuards(moduleRef, request, target, propertyKey) {
|
|
|
157
223
|
return new Guard();
|
|
158
224
|
}
|
|
159
225
|
};
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const classGuards = (_a = getClassGuards()) !== null && _a !== void 0 ? _a : [];
|
|
163
|
-
const methodGuards = (_b = getMethodGuards()) !== null && _b !== void 0 ? _b : [];
|
|
226
|
+
const classGuards = (_a = context.retrieveClassData(pondGuardsKey)) !== null && _a !== void 0 ? _a : [];
|
|
227
|
+
const methodGuards = (_b = context.retrieveMethodData(pondGuardsKey)) !== null && _b !== void 0 ? _b : [];
|
|
164
228
|
const instances = [...classGuards, ...methodGuards].map((guard) => retrieveGuard(guard));
|
|
165
|
-
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
const promises = instances.map((instance) => instance.canActivate(context));
|
|
166
231
|
const results = yield Promise.all(promises);
|
|
167
232
|
return results.every((result) => result);
|
|
168
233
|
});
|
|
@@ -188,15 +253,17 @@ function manageEndpointInstance(target) {
|
|
|
188
253
|
function createParamDecorator(callback) {
|
|
189
254
|
return (data) => (target, propertyKey, index) => {
|
|
190
255
|
const { set } = manageParameters(target, propertyKey);
|
|
191
|
-
|
|
256
|
+
// @ts-ignore
|
|
257
|
+
set(index, (context) => callback(data, context));
|
|
192
258
|
};
|
|
193
259
|
}
|
|
194
260
|
exports.createParamDecorator = createParamDecorator;
|
|
195
|
-
function resolveParameters(
|
|
196
|
-
|
|
197
|
-
const
|
|
261
|
+
function resolveParameters(context) {
|
|
262
|
+
var _a;
|
|
263
|
+
const gottenValues = (_a = context.retrieveMethodData(parametersKey)) !== null && _a !== void 0 ? _a : [];
|
|
264
|
+
const values = gottenValues
|
|
198
265
|
.map(({ callback, index }) => ({
|
|
199
|
-
value: callback(
|
|
266
|
+
value: callback(context),
|
|
200
267
|
index,
|
|
201
268
|
}));
|
|
202
269
|
return values
|
|
@@ -204,197 +271,184 @@ function resolveParameters(request, response, target, propertyKey) {
|
|
|
204
271
|
.map(({ value }) => value);
|
|
205
272
|
}
|
|
206
273
|
function GetUserData() {
|
|
207
|
-
return createParamDecorator((_,
|
|
208
|
-
const
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
else if (eventRequest) {
|
|
213
|
-
return eventRequest.user;
|
|
274
|
+
return createParamDecorator((_, context) => {
|
|
275
|
+
const userData = context.user;
|
|
276
|
+
if (!userData) {
|
|
277
|
+
throw new Error('Invalid decorator usage: GetUserData');
|
|
214
278
|
}
|
|
215
|
-
|
|
279
|
+
return userData;
|
|
216
280
|
})(null);
|
|
217
281
|
}
|
|
218
282
|
exports.GetUserData = GetUserData;
|
|
219
283
|
function GetInternalChannel() {
|
|
220
|
-
return createParamDecorator((_,
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
|
|
284
|
+
return createParamDecorator((_, context) => {
|
|
285
|
+
const channel = context.channel;
|
|
286
|
+
if (!channel) {
|
|
287
|
+
throw new Error('Invalid decorator usage: GetInternalChannel');
|
|
224
288
|
}
|
|
225
|
-
|
|
226
|
-
return eventRequest.channel;
|
|
227
|
-
}
|
|
228
|
-
throw new Error('Invalid decorator usage: GetInternalChannel');
|
|
289
|
+
return channel;
|
|
229
290
|
})(null);
|
|
230
291
|
}
|
|
231
292
|
exports.GetInternalChannel = GetInternalChannel;
|
|
232
293
|
function GetUserPresences() {
|
|
233
|
-
return createParamDecorator((_,
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
else if (eventRequest) {
|
|
239
|
-
return eventRequest.presence;
|
|
294
|
+
return createParamDecorator((_, context) => {
|
|
295
|
+
const presences = context.presence;
|
|
296
|
+
if (!presences) {
|
|
297
|
+
throw new Error('Invalid decorator usage: GetUserPresences');
|
|
240
298
|
}
|
|
241
|
-
|
|
299
|
+
return presences;
|
|
242
300
|
})(null);
|
|
243
301
|
}
|
|
244
302
|
exports.GetUserPresences = GetUserPresences;
|
|
245
303
|
function GetConnectionRequest() {
|
|
246
|
-
return createParamDecorator((_,
|
|
247
|
-
const
|
|
248
|
-
if (connection) {
|
|
249
|
-
|
|
304
|
+
return createParamDecorator((_, context) => {
|
|
305
|
+
const connection = context.connection;
|
|
306
|
+
if (!connection) {
|
|
307
|
+
throw new Error('Invalid decorator usage: GetConnectionRequest');
|
|
250
308
|
}
|
|
251
|
-
|
|
309
|
+
return connection;
|
|
252
310
|
})(null);
|
|
253
311
|
}
|
|
254
312
|
exports.GetConnectionRequest = GetConnectionRequest;
|
|
255
313
|
function GetConnectionResponse() {
|
|
256
|
-
return createParamDecorator((_,
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
259
|
-
|
|
314
|
+
return createParamDecorator((_, context) => {
|
|
315
|
+
const response = context.connectionResponse;
|
|
316
|
+
if (!response) {
|
|
317
|
+
throw new Error('Invalid decorator usage: GetConnectionResponse');
|
|
260
318
|
}
|
|
261
|
-
|
|
319
|
+
return response;
|
|
262
320
|
})(null);
|
|
263
321
|
}
|
|
264
322
|
exports.GetConnectionResponse = GetConnectionResponse;
|
|
265
323
|
function GetConnectionRequestId() {
|
|
266
|
-
return createParamDecorator((_,
|
|
267
|
-
const
|
|
268
|
-
if (connection) {
|
|
269
|
-
|
|
324
|
+
return createParamDecorator((_, context) => {
|
|
325
|
+
const connection = context.connection;
|
|
326
|
+
if (!connection) {
|
|
327
|
+
throw new Error('Invalid decorator usage: GetConnectionRequestId');
|
|
270
328
|
}
|
|
271
|
-
|
|
329
|
+
return connection.id;
|
|
272
330
|
})(null);
|
|
273
331
|
}
|
|
274
332
|
exports.GetConnectionRequestId = GetConnectionRequestId;
|
|
275
333
|
function GetConnectionParams() {
|
|
276
|
-
return createParamDecorator((_,
|
|
277
|
-
const
|
|
278
|
-
if (connection) {
|
|
279
|
-
|
|
334
|
+
return createParamDecorator((_, context) => {
|
|
335
|
+
const connection = context.connection;
|
|
336
|
+
if (!connection) {
|
|
337
|
+
throw new Error('Invalid decorator usage: GetConnectionParams');
|
|
280
338
|
}
|
|
281
|
-
|
|
339
|
+
return connection.params;
|
|
282
340
|
})(null);
|
|
283
341
|
}
|
|
284
342
|
exports.GetConnectionParams = GetConnectionParams;
|
|
285
343
|
function GetConnectionHeaders() {
|
|
286
|
-
return createParamDecorator((_,
|
|
287
|
-
const
|
|
288
|
-
if (connection) {
|
|
289
|
-
|
|
344
|
+
return createParamDecorator((_, context) => {
|
|
345
|
+
const connection = context.connection;
|
|
346
|
+
if (!connection) {
|
|
347
|
+
throw new Error('Invalid decorator usage: GetConnectionHeaders');
|
|
290
348
|
}
|
|
291
|
-
|
|
349
|
+
return connection.headers;
|
|
292
350
|
})(null);
|
|
293
351
|
}
|
|
294
352
|
exports.GetConnectionHeaders = GetConnectionHeaders;
|
|
295
353
|
function GetConnectionQuery() {
|
|
296
|
-
return createParamDecorator((_,
|
|
297
|
-
const
|
|
298
|
-
if (connection) {
|
|
299
|
-
|
|
354
|
+
return createParamDecorator((_, context) => {
|
|
355
|
+
const connection = context.connection;
|
|
356
|
+
if (!connection) {
|
|
357
|
+
throw new Error('Invalid decorator usage: GetConnectionQuery');
|
|
300
358
|
}
|
|
301
|
-
|
|
359
|
+
return connection.query;
|
|
302
360
|
})(null);
|
|
303
361
|
}
|
|
304
362
|
exports.GetConnectionQuery = GetConnectionQuery;
|
|
305
363
|
function GetJoinRequest() {
|
|
306
|
-
return createParamDecorator((_,
|
|
307
|
-
const
|
|
308
|
-
if (joinRequest) {
|
|
309
|
-
|
|
364
|
+
return createParamDecorator((_, context) => {
|
|
365
|
+
const joinRequest = context.joinRequest;
|
|
366
|
+
if (!joinRequest) {
|
|
367
|
+
throw new Error('Invalid decorator usage: GetJoinRequest');
|
|
310
368
|
}
|
|
311
|
-
|
|
369
|
+
return joinRequest;
|
|
312
370
|
})(null);
|
|
313
371
|
}
|
|
314
372
|
exports.GetJoinRequest = GetJoinRequest;
|
|
315
373
|
function GetJoinResponse() {
|
|
316
|
-
return createParamDecorator((_,
|
|
317
|
-
const
|
|
318
|
-
if (joinResponse) {
|
|
319
|
-
|
|
374
|
+
return createParamDecorator((_, context) => {
|
|
375
|
+
const joinResponse = context.joinResponse;
|
|
376
|
+
if (!joinResponse) {
|
|
377
|
+
throw new Error('Invalid decorator usage: GetJoinResponse');
|
|
320
378
|
}
|
|
321
|
-
|
|
379
|
+
return joinResponse;
|
|
322
380
|
})(null);
|
|
323
381
|
}
|
|
324
382
|
exports.GetJoinResponse = GetJoinResponse;
|
|
325
383
|
function GetJoinParams() {
|
|
326
|
-
return createParamDecorator((_,
|
|
327
|
-
const
|
|
328
|
-
if (joinRequest) {
|
|
329
|
-
|
|
384
|
+
return createParamDecorator((_, context) => {
|
|
385
|
+
const joinRequest = context.joinRequest;
|
|
386
|
+
if (!joinRequest) {
|
|
387
|
+
throw new Error('Invalid decorator usage: GetJoinParams');
|
|
330
388
|
}
|
|
331
|
-
|
|
389
|
+
return joinRequest.joinParams;
|
|
332
390
|
})(null);
|
|
333
391
|
}
|
|
334
392
|
exports.GetJoinParams = GetJoinParams;
|
|
335
393
|
function GetEventPayload() {
|
|
336
394
|
return createParamDecorator((_, request) => {
|
|
337
|
-
const
|
|
338
|
-
if (eventRequest) {
|
|
339
|
-
|
|
395
|
+
const eventRequest = request.eventRequest;
|
|
396
|
+
if (!eventRequest) {
|
|
397
|
+
throw new Error('Invalid decorator usage: GetEventPayload');
|
|
340
398
|
}
|
|
341
|
-
|
|
399
|
+
return eventRequest.event.payload;
|
|
342
400
|
})(null);
|
|
343
401
|
}
|
|
344
402
|
exports.GetEventPayload = GetEventPayload;
|
|
345
403
|
function GetEventParams() {
|
|
346
|
-
return createParamDecorator((_,
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
else if (joinRequest) {
|
|
352
|
-
return joinRequest.event.params;
|
|
404
|
+
return createParamDecorator((_, context) => {
|
|
405
|
+
var _a;
|
|
406
|
+
const params = (_a = context.event) === null || _a === void 0 ? void 0 : _a.params;
|
|
407
|
+
if (!params) {
|
|
408
|
+
throw new Error('Invalid decorator usage: GetEventParams');
|
|
353
409
|
}
|
|
354
|
-
|
|
410
|
+
return params;
|
|
355
411
|
})(null);
|
|
356
412
|
}
|
|
357
413
|
exports.GetEventParams = GetEventParams;
|
|
358
414
|
function GetEventQuery() {
|
|
359
415
|
return createParamDecorator((_, request) => {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
else if (joinRequest) {
|
|
365
|
-
return joinRequest.event.query;
|
|
416
|
+
var _a;
|
|
417
|
+
const query = (_a = request.event) === null || _a === void 0 ? void 0 : _a.query;
|
|
418
|
+
if (!query) {
|
|
419
|
+
throw new Error('Invalid decorator usage: GetEventQuery');
|
|
366
420
|
}
|
|
367
|
-
|
|
421
|
+
return query;
|
|
368
422
|
})(null);
|
|
369
423
|
}
|
|
370
424
|
exports.GetEventQuery = GetEventQuery;
|
|
371
425
|
function GetEventResponse() {
|
|
372
|
-
return createParamDecorator((_,
|
|
373
|
-
const
|
|
374
|
-
if (
|
|
375
|
-
|
|
426
|
+
return createParamDecorator((_, context) => {
|
|
427
|
+
const response = context.eventResponse;
|
|
428
|
+
if (!response) {
|
|
429
|
+
throw new Error('Invalid decorator usage: GetEventResponse');
|
|
376
430
|
}
|
|
377
|
-
|
|
431
|
+
return response;
|
|
378
432
|
})(null);
|
|
379
433
|
}
|
|
380
434
|
exports.GetEventResponse = GetEventResponse;
|
|
381
435
|
function GetEventRequest() {
|
|
382
|
-
return createParamDecorator((_,
|
|
383
|
-
const
|
|
384
|
-
if (
|
|
385
|
-
|
|
436
|
+
return createParamDecorator((_, context) => {
|
|
437
|
+
const request = context.eventRequest;
|
|
438
|
+
if (!request) {
|
|
439
|
+
throw new Error('Invalid decorator usage: GetEventRequest');
|
|
386
440
|
}
|
|
387
|
-
|
|
441
|
+
return request;
|
|
388
442
|
})(null);
|
|
389
443
|
}
|
|
390
444
|
exports.GetEventRequest = GetEventRequest;
|
|
391
445
|
function GetLeaveEvent() {
|
|
392
|
-
return createParamDecorator((_,
|
|
393
|
-
const
|
|
394
|
-
if (
|
|
395
|
-
|
|
446
|
+
return createParamDecorator((_, context) => {
|
|
447
|
+
const event = context.leveeEvent;
|
|
448
|
+
if (!event) {
|
|
449
|
+
throw new Error('Invalid decorator usage: GetLeaveEvent');
|
|
396
450
|
}
|
|
397
|
-
|
|
451
|
+
return event;
|
|
398
452
|
})(null);
|
|
399
453
|
}
|
|
400
454
|
exports.GetLeaveEvent = GetLeaveEvent;
|
|
@@ -410,9 +464,10 @@ function OnConnectionRequest() {
|
|
|
410
464
|
const res = {
|
|
411
465
|
connection: response,
|
|
412
466
|
};
|
|
413
|
-
const
|
|
467
|
+
const context = new Context(req, res, instance, propertyKey);
|
|
468
|
+
const canProceed = yield resolveGuards(moduleRef, context);
|
|
414
469
|
if (canProceed) {
|
|
415
|
-
const data = yield originalMethod.apply(instance, resolveParameters(
|
|
470
|
+
const data = yield originalMethod.apply(instance, resolveParameters(context));
|
|
416
471
|
if (!response.hasResponded) {
|
|
417
472
|
if (data) {
|
|
418
473
|
const { event, assigns } = data, rest = __rest(data, ["event", "assigns"]);
|
|
@@ -448,16 +503,15 @@ function OnJoinRequest() {
|
|
|
448
503
|
set('', (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
449
504
|
try {
|
|
450
505
|
const req = {
|
|
451
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
452
|
-
// @ts-expect-error
|
|
453
506
|
joinRequest: request,
|
|
454
507
|
};
|
|
455
508
|
const res = {
|
|
456
509
|
joinResponse: response,
|
|
457
510
|
};
|
|
458
|
-
const
|
|
511
|
+
const context = new Context(req, res, instance, propertyKey);
|
|
512
|
+
const canProceed = yield resolveGuards(moduleRef, context);
|
|
459
513
|
if (canProceed) {
|
|
460
|
-
const data = yield originalMethod.apply(instance, resolveParameters(
|
|
514
|
+
const data = yield originalMethod.apply(instance, resolveParameters(context));
|
|
461
515
|
if (!response.hasResponded) {
|
|
462
516
|
if (data) {
|
|
463
517
|
const { event, presence, assigns } = data, rest = __rest(data, ["event", "presence", "assigns"]);
|
|
@@ -496,16 +550,15 @@ function OnEvent(event = '*') {
|
|
|
496
550
|
set(event, (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
497
551
|
try {
|
|
498
552
|
const req = {
|
|
499
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
500
|
-
// @ts-expect-error
|
|
501
553
|
eventRequest: request,
|
|
502
554
|
};
|
|
503
555
|
const res = {
|
|
504
556
|
eventResponse: response,
|
|
505
557
|
};
|
|
506
|
-
const
|
|
558
|
+
const context = new Context(req, res, instance, propertyKey);
|
|
559
|
+
const canProceed = yield resolveGuards(moduleRef, context);
|
|
507
560
|
if (canProceed) {
|
|
508
|
-
const data = yield originalMethod.apply(instance, resolveParameters(
|
|
561
|
+
const data = yield originalMethod.apply(instance, resolveParameters(context));
|
|
509
562
|
if (!response.hasResponded) {
|
|
510
563
|
if (data) {
|
|
511
564
|
const { event, presence, updatePresence, assigns } = data, rest = __rest(data, ["event", "presence", "updatePresence", "assigns"]);
|
|
@@ -546,9 +599,10 @@ function OnLeaveEvent() {
|
|
|
546
599
|
const { set } = manageOnLeaveHandlers(target);
|
|
547
600
|
set('', (instance, _, event) => __awaiter(this, void 0, void 0, function* () {
|
|
548
601
|
try {
|
|
549
|
-
|
|
602
|
+
const context = new Context({
|
|
550
603
|
leveeEvent: event,
|
|
551
|
-
}, {},
|
|
604
|
+
}, {}, instance, propertyKey);
|
|
605
|
+
yield originalMethod.apply(instance, resolveParameters(context));
|
|
552
606
|
}
|
|
553
607
|
catch (error) {
|
|
554
608
|
if (error instanceof Error) {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -87,20 +87,7 @@ interface LeaveEvent {
|
|
|
87
87
|
|
|
88
88
|
type LeaveCallback = (event: LeaveEvent) => void;
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
connection?: IncomingConnection<string>;
|
|
92
|
-
joinRequest?: JoinRequest<string>;
|
|
93
|
-
eventRequest?: EventRequest<string>;
|
|
94
|
-
leveeEvent?: LeaveEvent;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
interface NestResponse {
|
|
98
|
-
connection?: ConnectionResponse;
|
|
99
|
-
joinResponse?: JoinResponse;
|
|
100
|
-
eventResponse?: EventResponse;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
type ParamDecoratorCallback<Input> = (data: Input, request: NestRequest, response: NestResponse) => unknown;
|
|
90
|
+
type ParamDecoratorCallback<Input> = (data: Input, context: Context) => unknown | Promise<unknown>;
|
|
104
91
|
|
|
105
92
|
interface UserData {
|
|
106
93
|
assigns: PondAssigns;
|
|
@@ -112,9 +99,9 @@ export interface CanActivate {
|
|
|
112
99
|
|
|
113
100
|
/**
|
|
114
101
|
* @desc Whether the client can continue with the request
|
|
115
|
-
* @param
|
|
102
|
+
* @param context - The context of the request
|
|
116
103
|
*/
|
|
117
|
-
canActivate(
|
|
104
|
+
canActivate(context: Context): boolean | Promise<boolean>;
|
|
118
105
|
}
|
|
119
106
|
|
|
120
107
|
export enum ChannelState {
|
|
@@ -125,6 +112,88 @@ export enum ChannelState {
|
|
|
125
112
|
CLOSED = 'CLOSED',
|
|
126
113
|
}
|
|
127
114
|
|
|
115
|
+
declare class Context {
|
|
116
|
+
/**
|
|
117
|
+
* @desc The request object, available in onJoin handlers
|
|
118
|
+
*/
|
|
119
|
+
joinRequest: JoinRequest<string> | null;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @desc The request object, available in onEvent handlers
|
|
123
|
+
*/
|
|
124
|
+
eventRequest: EventRequest<string> | null;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @desc The request object, available in onConnection handlers
|
|
128
|
+
*/
|
|
129
|
+
connection: IncomingConnection<string> | null;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @desc The leave event, available in onLeave handlers
|
|
133
|
+
*/
|
|
134
|
+
leveeEvent: LeaveEvent | null;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @desc The response object, available in onJoin handlers
|
|
138
|
+
*/
|
|
139
|
+
joinResponse: JoinResponse | null;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @desc The response object, available in onEvent handlers
|
|
143
|
+
*/
|
|
144
|
+
eventResponse: EventResponse | null;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @desc The response object, available in onConnection handlers
|
|
148
|
+
*/
|
|
149
|
+
connectionResponse: ConnectionResponse | null;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @desc The user data, available in onJoin, onEvent handlers
|
|
153
|
+
*/
|
|
154
|
+
user: UserData | null;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @desc The channel, available in onJoin, onEvent handlers
|
|
158
|
+
*/
|
|
159
|
+
channel: Channel | null;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @desc The assigns, available in onJoin, onEvent handlers
|
|
163
|
+
*/
|
|
164
|
+
presence: UserPresences | null;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @desc The assigns, available in onJoin, onEvent handlers
|
|
168
|
+
*/
|
|
169
|
+
event: EventParams<string> | null;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @desc Retrieves metadata associated with the class
|
|
173
|
+
* @param key - the key to retrieve
|
|
174
|
+
*/
|
|
175
|
+
public retrieveClassData<A = unknown>(key: symbol): A | null;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @desc Retrieves metadata associated with the method
|
|
179
|
+
* @param key - the key to retrieve
|
|
180
|
+
*/
|
|
181
|
+
public retrieveMethodData<A = unknown>(key: symbol): A | null;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @desc Adds request data to the context
|
|
185
|
+
* @param key - the key to add
|
|
186
|
+
* @param value - the value to add
|
|
187
|
+
*/
|
|
188
|
+
public addData(key: string, value: unknown): void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @desc Retrieves request data from the context
|
|
192
|
+
* @param key - the key to retrieve
|
|
193
|
+
*/
|
|
194
|
+
public getData<A = unknown>(key: string): A | null;
|
|
195
|
+
}
|
|
196
|
+
|
|
128
197
|
declare class AbstractRequest<Path extends string> {
|
|
129
198
|
event: PondEvent<Path>;
|
|
130
199
|
|