@eleven-am/pondsocket 0.1.92 → 0.1.93
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.d.ts +4 -21
- package/nest.js +341 -365
- package/package.json +1 -1
- package/types.d.ts +44 -7
package/nest.d.ts
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
export {
|
|
2
2
|
OnJoinRequest,
|
|
3
3
|
ChannelInstance,
|
|
4
4
|
DChannel as Channel,
|
|
5
|
-
Channels,
|
|
6
5
|
OnConnectionRequest,
|
|
7
6
|
DEndpoint as Endpoint,
|
|
8
7
|
OnEvent, PondSocketModule,
|
|
9
8
|
GetEventParams, GetEventQuery,
|
|
10
9
|
GetEventRequest, GetEventResponse,
|
|
11
|
-
GetJoinParams, GetJoinRequest,
|
|
12
10
|
GetJoinResponse, GetConnectionParams,
|
|
13
|
-
GetConnectionRequest, GetConnectionResponse,
|
|
14
11
|
GetConnectionQuery, GetConnectionHeaders,
|
|
15
|
-
|
|
12
|
+
GetConnectionRequest, GetConnectionResponse,
|
|
16
13
|
GetUserData, GetUserPresences, GetInternalChannel,
|
|
14
|
+
GetConnectionRequestId, GetEventPayload, PondGuards,
|
|
15
|
+
GetJoinParams, GetJoinRequest, createParamDecorator,
|
|
17
16
|
} from './types';
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
OnJoinRequest,
|
|
21
|
-
ChannelInstance,
|
|
22
|
-
OnConnectionRequest,
|
|
23
|
-
Endpoint, PondSocketModule,
|
|
24
|
-
OnEvent, Channel, Channels,
|
|
25
|
-
GetEventQuery, GetJoinParams,
|
|
26
|
-
GetEventParams, GetJoinResponse,
|
|
27
|
-
GetEventRequest, GetJoinRequest,
|
|
28
|
-
GetEventResponse, GetConnectionQuery,
|
|
29
|
-
GetConnectionRequestId, GetEventPayload,
|
|
30
|
-
GetConnectionParams, GetConnectionRequest,
|
|
31
|
-
GetConnectionResponse, GetConnectionHeaders,
|
|
32
|
-
GetUserData, GetUserPresences, GetInternalChannel,
|
|
33
|
-
}
|
package/nest.js
CHANGED
|
@@ -20,30 +20,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.PondSocketModule = exports.Endpoint = exports.Channel = exports.EndpointInstance = exports.ChannelInstance = exports.OnConnectionRequest = exports.
|
|
23
|
+
exports.PondSocketModule = exports.Endpoint = exports.Channel = exports.EndpointInstance = exports.ChannelInstance = exports.OnEvent = exports.OnLeaveEvent = exports.OnJoinRequest = exports.OnConnectionRequest = exports.GetLeaveEvent = exports.GetEventRequest = exports.GetEventResponse = exports.GetEventQuery = exports.GetEventParams = exports.GetEventPayload = exports.GetJoinParams = exports.GetJoinResponse = exports.GetJoinRequest = exports.GetConnectionQuery = exports.GetConnectionHeaders = exports.GetConnectionParams = exports.GetConnectionRequestId = exports.GetConnectionResponse = exports.GetConnectionRequest = exports.GetUserPresences = exports.GetInternalChannel = exports.GetUserData = exports.createParamDecorator = exports.PondGuards = void 0;
|
|
24
24
|
const http_1 = require("http");
|
|
25
25
|
const common_1 = require("@nestjs/common");
|
|
26
26
|
// eslint-disable-next-line import/no-unresolved
|
|
27
27
|
const core_1 = require("@nestjs/core");
|
|
28
28
|
require("reflect-metadata");
|
|
29
29
|
const pondSocket_1 = require("./server/pondSocket");
|
|
30
|
-
const joinRequestKey = Symbol('joinRequestKey');
|
|
31
|
-
const joinResponseKey = Symbol('joinResponseKey');
|
|
32
|
-
const joinParamsKey = Symbol('joinParamsKey');
|
|
33
|
-
const userDataKey = Symbol('userDataKey');
|
|
34
|
-
const internalChannelKey = Symbol('internalChannelKey');
|
|
35
|
-
const userPresenceKey = Symbol('userPresenceKey');
|
|
36
|
-
const eventRequestKey = Symbol('eventRequestKey');
|
|
37
|
-
const eventPayloadKey = Symbol('eventPayloadKey');
|
|
38
|
-
const eventParamsKey = Symbol('eventParamsKey');
|
|
39
|
-
const eventQueryKey = Symbol('eventQueryKey');
|
|
40
|
-
const eventResponseKey = Symbol('eventResponseKey');
|
|
41
|
-
const connectionRequestKey = Symbol('connectionRequestKey');
|
|
42
|
-
const connectionResponseKey = Symbol('connectionResponseKey');
|
|
43
|
-
const connectionRequestIdKey = Symbol('connectionRequestIdKey');
|
|
44
|
-
const connectionParamsKey = Symbol('connectionParamsKey');
|
|
45
|
-
const connectionQueryKey = Symbol('connectionQueryKey');
|
|
46
|
-
const connectionHeadersKey = Symbol('connectionHeadersKey');
|
|
47
30
|
const onJoinHandlerKey = Symbol('onJoinHandlerKey');
|
|
48
31
|
const onEventHandlerKey = Symbol('onEventHandlerKey');
|
|
49
32
|
const onConnectionHandlerKey = Symbol('onConnectionHandlerKey');
|
|
@@ -52,6 +35,8 @@ const endpointInstanceKey = Symbol('endpointInstanceKey');
|
|
|
52
35
|
const channelClassKey = Symbol('channel');
|
|
53
36
|
const endpointClassKey = Symbol('endpoint');
|
|
54
37
|
const channelsClassKey = Symbol('channels');
|
|
38
|
+
const parametersKey = Symbol('generalParametersKey');
|
|
39
|
+
const pondGuardsKey = Symbol('pondGuardsKey');
|
|
55
40
|
function isNotEmpty(value) {
|
|
56
41
|
return value !== null &&
|
|
57
42
|
value !== undefined &&
|
|
@@ -66,22 +51,6 @@ function getClassMetadata(key, target) {
|
|
|
66
51
|
var _a;
|
|
67
52
|
return (_a = Reflect.getMetadata(key, target)) !== null && _a !== void 0 ? _a : null;
|
|
68
53
|
}
|
|
69
|
-
function createParamDecorator(key, error) {
|
|
70
|
-
return (target, propertyKey, parameterIndex) => {
|
|
71
|
-
const existingParams = Reflect.getMetadata(key, target, propertyKey);
|
|
72
|
-
if (existingParams) {
|
|
73
|
-
throw new Error(error);
|
|
74
|
-
}
|
|
75
|
-
Reflect.defineMetadata(key, parameterIndex, target, propertyKey);
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function resolveParamDecorator(key, target, propertyKey) {
|
|
79
|
-
const index = Reflect.getMetadata(key, target, propertyKey);
|
|
80
|
-
if (typeof index !== 'number') {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
return index;
|
|
84
|
-
}
|
|
85
54
|
function manageClassData(key, target) {
|
|
86
55
|
return {
|
|
87
56
|
get() {
|
|
@@ -92,6 +61,16 @@ function manageClassData(key, target) {
|
|
|
92
61
|
},
|
|
93
62
|
};
|
|
94
63
|
}
|
|
64
|
+
function manageMethodData(key, target, propertyKey) {
|
|
65
|
+
return {
|
|
66
|
+
get() {
|
|
67
|
+
return Reflect.getMetadata(key, target, propertyKey);
|
|
68
|
+
},
|
|
69
|
+
set(value) {
|
|
70
|
+
Reflect.defineMetadata(key, value, target, propertyKey);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
95
74
|
function manageHandlers(key, target) {
|
|
96
75
|
const { get, set } = manageClassData(key, target);
|
|
97
76
|
return {
|
|
@@ -110,6 +89,25 @@ function manageHandlers(key, target) {
|
|
|
110
89
|
},
|
|
111
90
|
};
|
|
112
91
|
}
|
|
92
|
+
function manageParameters(target, propertyKey) {
|
|
93
|
+
function getter() {
|
|
94
|
+
var _a;
|
|
95
|
+
return (_a = Reflect.getMetadata(parametersKey, target, propertyKey)) !== null && _a !== void 0 ? _a : [];
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
get: getter,
|
|
99
|
+
set(index, callback) {
|
|
100
|
+
const handlers = getter();
|
|
101
|
+
Reflect.defineMetadata(parametersKey, [
|
|
102
|
+
...handlers,
|
|
103
|
+
{
|
|
104
|
+
index,
|
|
105
|
+
callback,
|
|
106
|
+
},
|
|
107
|
+
], target, propertyKey);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
113
111
|
function managePropertyData(key, target) {
|
|
114
112
|
function build(propertyKey, callback) {
|
|
115
113
|
Object.defineProperty(target, propertyKey, {
|
|
@@ -135,15 +133,41 @@ function managePropertyData(key, target) {
|
|
|
135
133
|
set,
|
|
136
134
|
};
|
|
137
135
|
}
|
|
136
|
+
function PondGuards(...guards) {
|
|
137
|
+
return (target, propertyKey) => {
|
|
138
|
+
if (propertyKey) {
|
|
139
|
+
const { get, set } = manageMethodData(pondGuardsKey, target, propertyKey);
|
|
140
|
+
set([...get(), ...guards]);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
const { get, set } = manageClassData(pondGuardsKey, target);
|
|
144
|
+
set([...get(), ...guards]);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
exports.PondGuards = PondGuards;
|
|
149
|
+
function resolveGuards(moduleRef, request, target, propertyKey) {
|
|
150
|
+
var _a, _b;
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const { get: getClassGuards } = manageClassData(pondGuardsKey, target);
|
|
153
|
+
const { get: getMethodGuards } = manageMethodData(pondGuardsKey, target, propertyKey.toString());
|
|
154
|
+
const classGuards = (_a = getClassGuards()) !== null && _a !== void 0 ? _a : [];
|
|
155
|
+
const methodGuards = (_b = getMethodGuards()) !== null && _b !== void 0 ? _b : [];
|
|
156
|
+
const instances = [...classGuards, ...methodGuards].map((guard) => moduleRef.get(guard, { strict: false }));
|
|
157
|
+
const promises = instances.map((instance) => instance.canActivate(request));
|
|
158
|
+
const results = yield Promise.all(promises);
|
|
159
|
+
return results.every((result) => result);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function manageConnectionHandlers(target) {
|
|
163
|
+
return manageHandlers(onConnectionHandlerKey, target);
|
|
164
|
+
}
|
|
138
165
|
function manageJoinHandlers(target) {
|
|
139
166
|
return manageHandlers(onJoinHandlerKey, target);
|
|
140
167
|
}
|
|
141
168
|
function manageEventHandlers(target) {
|
|
142
169
|
return manageHandlers(onEventHandlerKey, target);
|
|
143
170
|
}
|
|
144
|
-
function manageConnectionHandlers(target) {
|
|
145
|
-
return manageHandlers(onConnectionHandlerKey, target);
|
|
146
|
-
}
|
|
147
171
|
function manageOnLeaveHandlers(target) {
|
|
148
172
|
return manageHandlers(onConnectionHandlerKey, target);
|
|
149
173
|
}
|
|
@@ -153,326 +177,293 @@ function manageChannelInstance(target) {
|
|
|
153
177
|
function manageEndpointInstance(target) {
|
|
154
178
|
return managePropertyData(endpointInstanceKey, target);
|
|
155
179
|
}
|
|
156
|
-
function
|
|
157
|
-
return
|
|
180
|
+
function createParamDecorator(callback) {
|
|
181
|
+
return (data) => (target, propertyKey, index) => {
|
|
182
|
+
const { set } = manageParameters(target, propertyKey);
|
|
183
|
+
set(index, (request, response) => callback(data, request, response));
|
|
184
|
+
};
|
|
158
185
|
}
|
|
159
|
-
exports.
|
|
160
|
-
function
|
|
161
|
-
|
|
186
|
+
exports.createParamDecorator = createParamDecorator;
|
|
187
|
+
function resolveParameters(request, response, target, propertyKey) {
|
|
188
|
+
const { get } = manageParameters(target, propertyKey);
|
|
189
|
+
const values = get()
|
|
190
|
+
.map(({ callback, index }) => ({
|
|
191
|
+
value: callback(request, response),
|
|
192
|
+
index,
|
|
193
|
+
}));
|
|
194
|
+
return values
|
|
195
|
+
.sort((a, b) => a.index - b.index)
|
|
196
|
+
.map(({ value }) => value);
|
|
162
197
|
}
|
|
163
|
-
exports.GetJoinResponse = GetJoinResponse;
|
|
164
|
-
function GetJoinParams() {
|
|
165
|
-
return createParamDecorator(joinParamsKey, 'JoinParams decorator already applied');
|
|
166
|
-
}
|
|
167
|
-
exports.GetJoinParams = GetJoinParams;
|
|
168
198
|
function GetUserData() {
|
|
169
|
-
return createParamDecorator(
|
|
199
|
+
return createParamDecorator((_, request) => {
|
|
200
|
+
const { joinRequest, eventRequest } = request;
|
|
201
|
+
if (joinRequest) {
|
|
202
|
+
return joinRequest.user;
|
|
203
|
+
}
|
|
204
|
+
else if (eventRequest) {
|
|
205
|
+
return eventRequest.user;
|
|
206
|
+
}
|
|
207
|
+
throw new Error('Invalid decorator usage: GetUserData');
|
|
208
|
+
})(null);
|
|
170
209
|
}
|
|
171
210
|
exports.GetUserData = GetUserData;
|
|
172
211
|
function GetInternalChannel() {
|
|
173
|
-
return createParamDecorator(
|
|
212
|
+
return createParamDecorator((_, request) => {
|
|
213
|
+
const { joinRequest, eventRequest } = request;
|
|
214
|
+
if (joinRequest) {
|
|
215
|
+
return joinRequest.channel;
|
|
216
|
+
}
|
|
217
|
+
else if (eventRequest) {
|
|
218
|
+
return eventRequest.channel;
|
|
219
|
+
}
|
|
220
|
+
throw new Error('Invalid decorator usage: GetInternalChannel');
|
|
221
|
+
})(null);
|
|
174
222
|
}
|
|
175
223
|
exports.GetInternalChannel = GetInternalChannel;
|
|
176
224
|
function GetUserPresences() {
|
|
177
|
-
return createParamDecorator(
|
|
225
|
+
return createParamDecorator((_, request) => {
|
|
226
|
+
const { joinRequest, eventRequest } = request;
|
|
227
|
+
if (joinRequest) {
|
|
228
|
+
return joinRequest.presence;
|
|
229
|
+
}
|
|
230
|
+
else if (eventRequest) {
|
|
231
|
+
return eventRequest.presence;
|
|
232
|
+
}
|
|
233
|
+
throw new Error('Invalid decorator usage: GetUserPresences');
|
|
234
|
+
})(null);
|
|
178
235
|
}
|
|
179
236
|
exports.GetUserPresences = GetUserPresences;
|
|
180
|
-
function GetEventPayload() {
|
|
181
|
-
return createParamDecorator(eventPayloadKey, 'EventPayload decorator already applied');
|
|
182
|
-
}
|
|
183
|
-
exports.GetEventPayload = GetEventPayload;
|
|
184
|
-
function GetEventParams() {
|
|
185
|
-
return createParamDecorator(eventParamsKey, 'EventParams decorator already applied');
|
|
186
|
-
}
|
|
187
|
-
exports.GetEventParams = GetEventParams;
|
|
188
|
-
function GetEventQuery() {
|
|
189
|
-
return createParamDecorator(eventQueryKey, 'EventQuery decorator already applied');
|
|
190
|
-
}
|
|
191
|
-
exports.GetEventQuery = GetEventQuery;
|
|
192
|
-
function GetEventResponse() {
|
|
193
|
-
return createParamDecorator(eventResponseKey, 'EventResponse decorator already applied');
|
|
194
|
-
}
|
|
195
|
-
exports.GetEventResponse = GetEventResponse;
|
|
196
|
-
function GetEventRequest() {
|
|
197
|
-
return createParamDecorator(eventRequestKey, 'EventRequest decorator already applied');
|
|
198
|
-
}
|
|
199
|
-
exports.GetEventRequest = GetEventRequest;
|
|
200
237
|
function GetConnectionRequest() {
|
|
201
|
-
return createParamDecorator(
|
|
238
|
+
return createParamDecorator((_, request) => {
|
|
239
|
+
const { connection } = request;
|
|
240
|
+
if (connection) {
|
|
241
|
+
return connection;
|
|
242
|
+
}
|
|
243
|
+
throw new Error('Invalid decorator usage: GetConnectionRequest');
|
|
244
|
+
})(null);
|
|
202
245
|
}
|
|
203
246
|
exports.GetConnectionRequest = GetConnectionRequest;
|
|
204
247
|
function GetConnectionResponse() {
|
|
205
|
-
return createParamDecorator(
|
|
248
|
+
return createParamDecorator((_, __, response) => {
|
|
249
|
+
const { connection } = response;
|
|
250
|
+
if (connection) {
|
|
251
|
+
return connection;
|
|
252
|
+
}
|
|
253
|
+
throw new Error('Invalid decorator usage: GetConnectionResponse');
|
|
254
|
+
})(null);
|
|
206
255
|
}
|
|
207
256
|
exports.GetConnectionResponse = GetConnectionResponse;
|
|
208
257
|
function GetConnectionRequestId() {
|
|
209
|
-
return createParamDecorator(
|
|
258
|
+
return createParamDecorator((_, request) => {
|
|
259
|
+
const { connection } = request;
|
|
260
|
+
if (connection) {
|
|
261
|
+
return connection.id;
|
|
262
|
+
}
|
|
263
|
+
throw new Error('Invalid decorator usage: GetConnectionRequestId');
|
|
264
|
+
})(null);
|
|
210
265
|
}
|
|
211
266
|
exports.GetConnectionRequestId = GetConnectionRequestId;
|
|
212
267
|
function GetConnectionParams() {
|
|
213
|
-
return createParamDecorator(
|
|
268
|
+
return createParamDecorator((_, request) => {
|
|
269
|
+
const { connection } = request;
|
|
270
|
+
if (connection) {
|
|
271
|
+
return connection.params;
|
|
272
|
+
}
|
|
273
|
+
throw new Error('Invalid decorator usage: GetConnectionParams');
|
|
274
|
+
})(null);
|
|
214
275
|
}
|
|
215
276
|
exports.GetConnectionParams = GetConnectionParams;
|
|
216
277
|
function GetConnectionHeaders() {
|
|
217
|
-
return createParamDecorator(
|
|
278
|
+
return createParamDecorator((_, request) => {
|
|
279
|
+
const { connection } = request;
|
|
280
|
+
if (connection) {
|
|
281
|
+
return connection.headers;
|
|
282
|
+
}
|
|
283
|
+
throw new Error('Invalid decorator usage: GetConnectionHeaders');
|
|
284
|
+
})(null);
|
|
218
285
|
}
|
|
219
286
|
exports.GetConnectionHeaders = GetConnectionHeaders;
|
|
220
287
|
function GetConnectionQuery() {
|
|
221
|
-
return createParamDecorator(
|
|
288
|
+
return createParamDecorator((_, request) => {
|
|
289
|
+
const { connection } = request;
|
|
290
|
+
if (connection) {
|
|
291
|
+
return connection.query;
|
|
292
|
+
}
|
|
293
|
+
throw new Error('Invalid decorator usage: GetConnectionQuery');
|
|
294
|
+
})(null);
|
|
222
295
|
}
|
|
223
296
|
exports.GetConnectionQuery = GetConnectionQuery;
|
|
224
|
-
function
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
case joinResponseKey:
|
|
230
|
-
return 'GetJoinResponse';
|
|
231
|
-
case joinParamsKey:
|
|
232
|
-
return 'GetJoinParams';
|
|
233
|
-
case userDataKey:
|
|
234
|
-
return 'GetUserData';
|
|
235
|
-
case internalChannelKey:
|
|
236
|
-
return 'GetInternalChannel';
|
|
237
|
-
case userPresenceKey:
|
|
238
|
-
return 'GetUserPresences';
|
|
239
|
-
case eventPayloadKey:
|
|
240
|
-
return 'GetEventPayload';
|
|
241
|
-
case eventParamsKey:
|
|
242
|
-
return 'GetEventParams';
|
|
243
|
-
case eventQueryKey:
|
|
244
|
-
return 'GetEventQuery';
|
|
245
|
-
case eventResponseKey:
|
|
246
|
-
return 'GetEventResponse';
|
|
247
|
-
case eventRequestKey:
|
|
248
|
-
return 'GetEventRequest';
|
|
249
|
-
case connectionRequestKey:
|
|
250
|
-
return 'GetConnectionRequest';
|
|
251
|
-
case connectionResponseKey:
|
|
252
|
-
return 'GetConnectionResponse';
|
|
253
|
-
case connectionRequestIdKey:
|
|
254
|
-
return 'GetConnectionRequestId';
|
|
255
|
-
case connectionParamsKey:
|
|
256
|
-
return 'GetConnectionParams';
|
|
257
|
-
case connectionQueryKey:
|
|
258
|
-
return 'GetConnectionQuery';
|
|
259
|
-
case connectionHeadersKey:
|
|
260
|
-
return 'GetConnectionHeaders';
|
|
261
|
-
default:
|
|
262
|
-
throw new Error('Invalid parameter decorator');
|
|
297
|
+
function GetJoinRequest() {
|
|
298
|
+
return createParamDecorator((_, request) => {
|
|
299
|
+
const { joinRequest } = request;
|
|
300
|
+
if (joinRequest) {
|
|
301
|
+
return joinRequest;
|
|
263
302
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
.map((key) => ({
|
|
267
|
-
key,
|
|
268
|
-
name: symbolToString(key),
|
|
269
|
-
}))
|
|
270
|
-
.filter(({ key }) => resolveParamDecorator(key, target, propertyKey) !== null);
|
|
271
|
-
if (rejected.length) {
|
|
272
|
-
throw new Error(`Invalid parameter decorators: ${rejected.map(({ name }) => name).join(', ')}`);
|
|
273
|
-
}
|
|
303
|
+
throw new Error('Invalid decorator usage: GetJoinRequest');
|
|
304
|
+
})(null);
|
|
274
305
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const eventQueryIndex = resolveParamDecorator(eventQueryKey, target, propertyKey);
|
|
282
|
-
const JoinResponseIndex = resolveParamDecorator(joinResponseKey, target, propertyKey);
|
|
283
|
-
const array = [
|
|
284
|
-
joinRequestIndex,
|
|
285
|
-
joinParamsIndex,
|
|
286
|
-
userDataIndex,
|
|
287
|
-
internalChannelIndex,
|
|
288
|
-
eventParamsIndex,
|
|
289
|
-
eventQueryIndex,
|
|
290
|
-
JoinResponseIndex,
|
|
291
|
-
].filter((index) => typeof index === 'number');
|
|
292
|
-
manageRejectedKeys([
|
|
293
|
-
eventPayloadKey,
|
|
294
|
-
eventRequestKey,
|
|
295
|
-
eventResponseKey,
|
|
296
|
-
userPresenceKey,
|
|
297
|
-
connectionRequestKey,
|
|
298
|
-
connectionResponseKey,
|
|
299
|
-
connectionRequestIdKey,
|
|
300
|
-
connectionParamsKey,
|
|
301
|
-
connectionQueryKey,
|
|
302
|
-
], target, propertyKey);
|
|
303
|
-
return array
|
|
304
|
-
.sort((a, b) => a - b)
|
|
305
|
-
.map((index) => {
|
|
306
|
-
switch (index) {
|
|
307
|
-
case joinRequestIndex:
|
|
308
|
-
return request;
|
|
309
|
-
case joinParamsIndex:
|
|
310
|
-
return request.joinParams;
|
|
311
|
-
case userDataIndex:
|
|
312
|
-
return request.user;
|
|
313
|
-
case internalChannelIndex:
|
|
314
|
-
return request.channel;
|
|
315
|
-
case eventParamsIndex:
|
|
316
|
-
return request.event.params;
|
|
317
|
-
case eventQueryIndex:
|
|
318
|
-
return request.event.query;
|
|
319
|
-
case JoinResponseIndex:
|
|
320
|
-
return response;
|
|
321
|
-
default:
|
|
322
|
-
throw new Error('Invalid parameter decorator');
|
|
306
|
+
exports.GetJoinRequest = GetJoinRequest;
|
|
307
|
+
function GetJoinResponse() {
|
|
308
|
+
return createParamDecorator((_, __, response) => {
|
|
309
|
+
const { joinResponse } = response;
|
|
310
|
+
if (joinResponse) {
|
|
311
|
+
return joinResponse;
|
|
323
312
|
}
|
|
324
|
-
|
|
313
|
+
throw new Error('Invalid decorator usage: GetJoinResponse');
|
|
314
|
+
})(null);
|
|
325
315
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const eventPayloadIndex = resolveParamDecorator(eventPayloadKey, target, propertyKey);
|
|
333
|
-
const eventResponseIndex = resolveParamDecorator(eventResponseKey, target, propertyKey);
|
|
334
|
-
const eventRequestIndex = resolveParamDecorator(eventRequestKey, target, propertyKey);
|
|
335
|
-
const array = [
|
|
336
|
-
userDataIndex,
|
|
337
|
-
internalChannelIndex,
|
|
338
|
-
eventParamsIndex,
|
|
339
|
-
eventQueryIndex,
|
|
340
|
-
eventPayloadIndex,
|
|
341
|
-
eventResponseIndex,
|
|
342
|
-
eventRequestIndex,
|
|
343
|
-
userPresenceIndex,
|
|
344
|
-
].filter((index) => typeof index === 'number');
|
|
345
|
-
manageRejectedKeys([
|
|
346
|
-
joinRequestKey,
|
|
347
|
-
joinResponseKey,
|
|
348
|
-
joinParamsKey,
|
|
349
|
-
connectionRequestKey,
|
|
350
|
-
connectionResponseKey,
|
|
351
|
-
connectionRequestIdKey,
|
|
352
|
-
connectionParamsKey,
|
|
353
|
-
connectionQueryKey,
|
|
354
|
-
], target, propertyKey);
|
|
355
|
-
return array
|
|
356
|
-
.sort((a, b) => a - b)
|
|
357
|
-
.map((index) => {
|
|
358
|
-
switch (index) {
|
|
359
|
-
case userDataIndex:
|
|
360
|
-
return request.user;
|
|
361
|
-
case internalChannelIndex:
|
|
362
|
-
return request.channel;
|
|
363
|
-
case eventParamsIndex:
|
|
364
|
-
return request.event.params;
|
|
365
|
-
case eventQueryIndex:
|
|
366
|
-
return request.event.query;
|
|
367
|
-
case eventPayloadIndex:
|
|
368
|
-
return request.event.payload;
|
|
369
|
-
case eventResponseIndex:
|
|
370
|
-
return response;
|
|
371
|
-
case eventRequestIndex:
|
|
372
|
-
return request;
|
|
373
|
-
case userPresenceIndex:
|
|
374
|
-
return request.presence;
|
|
375
|
-
default:
|
|
376
|
-
throw new Error('Invalid parameter decorator');
|
|
316
|
+
exports.GetJoinResponse = GetJoinResponse;
|
|
317
|
+
function GetJoinParams() {
|
|
318
|
+
return createParamDecorator((_, request) => {
|
|
319
|
+
const { joinRequest } = request;
|
|
320
|
+
if (joinRequest) {
|
|
321
|
+
return joinRequest.joinParams;
|
|
377
322
|
}
|
|
378
|
-
|
|
323
|
+
throw new Error('Invalid decorator usage: GetJoinParams');
|
|
324
|
+
})(null);
|
|
379
325
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
connectionRequestKey,
|
|
387
|
-
connectionResponseKey,
|
|
388
|
-
connectionRequestIdKey,
|
|
389
|
-
connectionParamsKey,
|
|
390
|
-
connectionQueryKey,
|
|
391
|
-
eventParamsKey,
|
|
392
|
-
eventQueryKey,
|
|
393
|
-
eventPayloadKey,
|
|
394
|
-
eventResponseKey,
|
|
395
|
-
eventRequestKey,
|
|
396
|
-
userPresenceKey,
|
|
397
|
-
internalChannelKey,
|
|
398
|
-
], target, propertyKey);
|
|
399
|
-
if (userDataIndex === null) {
|
|
400
|
-
return [];
|
|
401
|
-
}
|
|
402
|
-
return [event.assigns];
|
|
403
|
-
}
|
|
404
|
-
function resolveConnectionParameters(request, response, target, propertyKey) {
|
|
405
|
-
const connectionRequestIndex = resolveParamDecorator(connectionRequestKey, target, propertyKey);
|
|
406
|
-
const connectionResponseIndex = resolveParamDecorator(connectionResponseKey, target, propertyKey);
|
|
407
|
-
const connectionRequestIdIndex = resolveParamDecorator(connectionRequestIdKey, target, propertyKey);
|
|
408
|
-
const connectionParamsIndex = resolveParamDecorator(connectionParamsKey, target, propertyKey);
|
|
409
|
-
const connectionQueryIndex = resolveParamDecorator(connectionQueryKey, target, propertyKey);
|
|
410
|
-
const connectionHeadersIndex = resolveParamDecorator(connectionHeadersKey, target, propertyKey);
|
|
411
|
-
const array = [
|
|
412
|
-
connectionRequestIndex,
|
|
413
|
-
connectionResponseIndex,
|
|
414
|
-
connectionRequestIdIndex,
|
|
415
|
-
connectionParamsIndex,
|
|
416
|
-
connectionQueryIndex,
|
|
417
|
-
connectionHeadersIndex,
|
|
418
|
-
].filter((index) => typeof index === 'number');
|
|
419
|
-
manageRejectedKeys([
|
|
420
|
-
joinRequestKey,
|
|
421
|
-
joinResponseKey,
|
|
422
|
-
joinParamsKey,
|
|
423
|
-
userDataKey,
|
|
424
|
-
internalChannelKey,
|
|
425
|
-
eventParamsKey,
|
|
426
|
-
eventQueryKey,
|
|
427
|
-
eventPayloadKey,
|
|
428
|
-
eventResponseKey,
|
|
429
|
-
userPresenceKey,
|
|
430
|
-
eventRequestKey,
|
|
431
|
-
], target, propertyKey);
|
|
432
|
-
return array
|
|
433
|
-
.sort((a, b) => a - b)
|
|
434
|
-
.map((index) => {
|
|
435
|
-
switch (index) {
|
|
436
|
-
case connectionRequestIndex:
|
|
437
|
-
return request;
|
|
438
|
-
case connectionResponseIndex:
|
|
439
|
-
return response;
|
|
440
|
-
case connectionRequestIdIndex:
|
|
441
|
-
return request.id;
|
|
442
|
-
case connectionParamsIndex:
|
|
443
|
-
return request.params;
|
|
444
|
-
case connectionQueryIndex:
|
|
445
|
-
return request.query;
|
|
446
|
-
case connectionHeadersIndex:
|
|
447
|
-
return request.headers;
|
|
448
|
-
default:
|
|
449
|
-
throw new Error('Invalid parameter decorator');
|
|
326
|
+
exports.GetJoinParams = GetJoinParams;
|
|
327
|
+
function GetEventPayload() {
|
|
328
|
+
return createParamDecorator((_, request) => {
|
|
329
|
+
const { eventRequest } = request;
|
|
330
|
+
if (eventRequest) {
|
|
331
|
+
return eventRequest.event.payload;
|
|
450
332
|
}
|
|
451
|
-
|
|
333
|
+
throw new Error('Invalid decorator usage: GetEventPayload');
|
|
334
|
+
})(null);
|
|
335
|
+
}
|
|
336
|
+
exports.GetEventPayload = GetEventPayload;
|
|
337
|
+
function GetEventParams() {
|
|
338
|
+
return createParamDecorator((_, request) => {
|
|
339
|
+
const { eventRequest } = request;
|
|
340
|
+
if (eventRequest) {
|
|
341
|
+
return eventRequest.event.params;
|
|
342
|
+
}
|
|
343
|
+
throw new Error('Invalid decorator usage: GetEventParams');
|
|
344
|
+
})(null);
|
|
345
|
+
}
|
|
346
|
+
exports.GetEventParams = GetEventParams;
|
|
347
|
+
function GetEventQuery() {
|
|
348
|
+
return createParamDecorator((_, request) => {
|
|
349
|
+
const { eventRequest } = request;
|
|
350
|
+
if (eventRequest) {
|
|
351
|
+
return eventRequest.event.query;
|
|
352
|
+
}
|
|
353
|
+
throw new Error('Invalid decorator usage: GetEventQuery');
|
|
354
|
+
})(null);
|
|
355
|
+
}
|
|
356
|
+
exports.GetEventQuery = GetEventQuery;
|
|
357
|
+
function GetEventResponse() {
|
|
358
|
+
return createParamDecorator((_, __, response) => {
|
|
359
|
+
const { eventResponse } = response;
|
|
360
|
+
if (eventResponse) {
|
|
361
|
+
return eventResponse;
|
|
362
|
+
}
|
|
363
|
+
throw new Error('Invalid decorator usage: GetEventResponse');
|
|
364
|
+
})(null);
|
|
365
|
+
}
|
|
366
|
+
exports.GetEventResponse = GetEventResponse;
|
|
367
|
+
function GetEventRequest() {
|
|
368
|
+
return createParamDecorator((_, request) => {
|
|
369
|
+
const { eventRequest } = request;
|
|
370
|
+
if (eventRequest) {
|
|
371
|
+
return eventRequest;
|
|
372
|
+
}
|
|
373
|
+
throw new Error('Invalid decorator usage: GetEventRequest');
|
|
374
|
+
})(null);
|
|
375
|
+
}
|
|
376
|
+
exports.GetEventRequest = GetEventRequest;
|
|
377
|
+
function GetLeaveEvent() {
|
|
378
|
+
return createParamDecorator((_, request) => {
|
|
379
|
+
const { leveeEvent } = request;
|
|
380
|
+
if (leveeEvent) {
|
|
381
|
+
return leveeEvent;
|
|
382
|
+
}
|
|
383
|
+
throw new Error('Invalid decorator usage: GetLeaveEvent');
|
|
384
|
+
})(null);
|
|
385
|
+
}
|
|
386
|
+
exports.GetLeaveEvent = GetLeaveEvent;
|
|
387
|
+
function OnConnectionRequest() {
|
|
388
|
+
return (target, propertyKey, descriptor) => {
|
|
389
|
+
const originalMethod = descriptor.value;
|
|
390
|
+
const { set } = manageConnectionHandlers(target);
|
|
391
|
+
set('', (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
392
|
+
try {
|
|
393
|
+
const req = {
|
|
394
|
+
connection: request,
|
|
395
|
+
};
|
|
396
|
+
const res = {
|
|
397
|
+
connection: response,
|
|
398
|
+
};
|
|
399
|
+
const canProceed = yield resolveGuards(moduleRef, req, target, propertyKey);
|
|
400
|
+
if (canProceed) {
|
|
401
|
+
const data = yield originalMethod.apply(instance, resolveParameters(req, res, target, propertyKey));
|
|
402
|
+
if (!response.hasResponded) {
|
|
403
|
+
if (data) {
|
|
404
|
+
const { event, assigns } = data, rest = __rest(data, ["event", "assigns"]);
|
|
405
|
+
if (typeof event === 'string' && isNotEmpty(rest)) {
|
|
406
|
+
response.send(event, rest, assigns);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
response.accept(typeof assigns === 'object' ? assigns : {});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
response.accept();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
response.reject('Unauthorized', 401);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
if (!response.hasResponded && error instanceof Error) {
|
|
423
|
+
response.reject(error.message);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}));
|
|
427
|
+
};
|
|
452
428
|
}
|
|
429
|
+
exports.OnConnectionRequest = OnConnectionRequest;
|
|
453
430
|
function OnJoinRequest() {
|
|
454
431
|
return (target, propertyKey, descriptor) => {
|
|
455
432
|
const originalMethod = descriptor.value;
|
|
456
433
|
const { set } = manageJoinHandlers(target);
|
|
457
|
-
set('', (instance, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
434
|
+
set('', (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
458
435
|
try {
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
436
|
+
const req = {
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
438
|
+
// @ts-expect-error
|
|
439
|
+
joinRequest: request,
|
|
440
|
+
};
|
|
441
|
+
const res = {
|
|
442
|
+
joinResponse: response,
|
|
443
|
+
};
|
|
444
|
+
const canProceed = yield resolveGuards(moduleRef, req, target, propertyKey);
|
|
445
|
+
if (canProceed) {
|
|
446
|
+
const data = yield originalMethod.apply(instance, resolveParameters(req, res, target, propertyKey));
|
|
447
|
+
if (!response.hasResponded) {
|
|
448
|
+
if (data) {
|
|
449
|
+
const { event, presence, assigns } = data, rest = __rest(data, ["event", "presence", "assigns"]);
|
|
450
|
+
if (typeof event === 'string' && isNotEmpty(rest)) {
|
|
451
|
+
response.send(event, rest, assigns);
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
response.accept(typeof assigns === 'object' ? assigns : {});
|
|
455
|
+
}
|
|
456
|
+
if (presence) {
|
|
457
|
+
response.trackPresence(presence);
|
|
458
|
+
}
|
|
465
459
|
}
|
|
466
460
|
else {
|
|
467
|
-
response.accept(
|
|
468
|
-
}
|
|
469
|
-
if (presence) {
|
|
470
|
-
response.trackPresence(presence);
|
|
461
|
+
response.accept();
|
|
471
462
|
}
|
|
472
463
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
response.reject('Unauthorized', 401);
|
|
476
467
|
}
|
|
477
468
|
}
|
|
478
469
|
catch (error) {
|
|
@@ -488,9 +479,11 @@ function OnLeaveEvent() {
|
|
|
488
479
|
return (target, propertyKey, descriptor) => {
|
|
489
480
|
const originalMethod = descriptor.value;
|
|
490
481
|
const { set } = manageOnLeaveHandlers(target);
|
|
491
|
-
set('', (instance, event) => __awaiter(this, void 0, void 0, function* () {
|
|
482
|
+
set('', (instance, _, event) => __awaiter(this, void 0, void 0, function* () {
|
|
492
483
|
try {
|
|
493
|
-
yield originalMethod.apply(instance,
|
|
484
|
+
yield originalMethod.apply(instance, resolveParameters({
|
|
485
|
+
leveeEvent: event,
|
|
486
|
+
}, {}, target, propertyKey));
|
|
494
487
|
}
|
|
495
488
|
catch (error) {
|
|
496
489
|
if (error instanceof Error) {
|
|
@@ -505,59 +498,42 @@ function OnEvent(event = '*') {
|
|
|
505
498
|
return (target, propertyKey, descriptor) => {
|
|
506
499
|
const originalMethod = descriptor.value;
|
|
507
500
|
const { set } = manageEventHandlers(target);
|
|
508
|
-
set(event, (instance, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
501
|
+
set(event, (instance, moduleRef, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
509
502
|
try {
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
503
|
+
const req = {
|
|
504
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
505
|
+
// @ts-expect-error
|
|
506
|
+
eventRequest: request,
|
|
507
|
+
};
|
|
508
|
+
const res = {
|
|
509
|
+
eventResponse: response,
|
|
510
|
+
};
|
|
511
|
+
const canProceed = yield resolveGuards(moduleRef, req, target, propertyKey);
|
|
512
|
+
if (canProceed) {
|
|
513
|
+
const data = yield originalMethod.apply(instance, resolveParameters(req, res, target, propertyKey));
|
|
514
|
+
if (!response.hasResponded) {
|
|
515
|
+
if (data) {
|
|
516
|
+
const { event, presence, updatePresence, assigns } = data, rest = __rest(data, ["event", "presence", "updatePresence", "assigns"]);
|
|
517
|
+
if (typeof event === 'string' && isNotEmpty(rest)) {
|
|
518
|
+
response.send(event, rest, assigns);
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
response.accept(typeof assigns === 'object' ? assigns : {});
|
|
522
|
+
}
|
|
523
|
+
if (presence) {
|
|
524
|
+
response.trackPresence(presence);
|
|
525
|
+
}
|
|
526
|
+
else if (updatePresence) {
|
|
527
|
+
response.updatePresence(updatePresence);
|
|
528
|
+
}
|
|
516
529
|
}
|
|
517
530
|
else {
|
|
518
|
-
response.accept(
|
|
519
|
-
}
|
|
520
|
-
if (presence) {
|
|
521
|
-
response.trackPresence(presence);
|
|
531
|
+
response.accept();
|
|
522
532
|
}
|
|
523
|
-
else if (updatePresence) {
|
|
524
|
-
response.updatePresence(updatePresence);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
response.accept();
|
|
529
533
|
}
|
|
530
534
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (!response.hasResponded && error instanceof Error) {
|
|
534
|
-
response.reject(error.message);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}));
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
exports.OnEvent = OnEvent;
|
|
541
|
-
function OnConnectionRequest() {
|
|
542
|
-
return (target, propertyKey, descriptor) => {
|
|
543
|
-
const originalMethod = descriptor.value;
|
|
544
|
-
const { set } = manageConnectionHandlers(target);
|
|
545
|
-
set('', (instance, request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
546
|
-
try {
|
|
547
|
-
const data = yield originalMethod.apply(instance, resolveConnectionParameters(request, response, target, propertyKey));
|
|
548
|
-
if (!response.hasResponded) {
|
|
549
|
-
if (data) {
|
|
550
|
-
const { event, assigns } = data, rest = __rest(data, ["event", "assigns"]);
|
|
551
|
-
if (typeof event === 'string' && isNotEmpty(rest)) {
|
|
552
|
-
response.send(event, rest, assigns);
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
response.accept(typeof assigns === 'object' ? assigns : {});
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
else {
|
|
559
|
-
response.accept();
|
|
560
|
-
}
|
|
535
|
+
else {
|
|
536
|
+
response.reject('Unauthorized', 401);
|
|
561
537
|
}
|
|
562
538
|
}
|
|
563
539
|
catch (error) {
|
|
@@ -568,7 +544,7 @@ function OnConnectionRequest() {
|
|
|
568
544
|
}));
|
|
569
545
|
};
|
|
570
546
|
}
|
|
571
|
-
exports.
|
|
547
|
+
exports.OnEvent = OnEvent;
|
|
572
548
|
function ChannelInstance(name) {
|
|
573
549
|
return (target, propertyKey) => {
|
|
574
550
|
const { build } = manageChannelInstance(target);
|
|
@@ -623,7 +599,7 @@ class PondSocketService {
|
|
|
623
599
|
const { get } = manageConnectionHandlers(instance);
|
|
624
600
|
const [handler] = get();
|
|
625
601
|
if (handler) {
|
|
626
|
-
yield handler.value(instance, request, response);
|
|
602
|
+
yield handler.value(instance, this.moduleRef, request, response);
|
|
627
603
|
}
|
|
628
604
|
else {
|
|
629
605
|
response.accept();
|
|
@@ -644,7 +620,7 @@ class PondSocketService {
|
|
|
644
620
|
const { get } = manageJoinHandlers(instance);
|
|
645
621
|
const [handler] = get();
|
|
646
622
|
if (handler) {
|
|
647
|
-
yield handler.value(instance, request, response);
|
|
623
|
+
yield handler.value(instance, this.moduleRef, request, response);
|
|
648
624
|
}
|
|
649
625
|
else {
|
|
650
626
|
response.accept();
|
|
@@ -655,13 +631,13 @@ class PondSocketService {
|
|
|
655
631
|
const { set } = manageChannelInstance(instance);
|
|
656
632
|
getEventHandlers().forEach((handler) => {
|
|
657
633
|
channelInstance.onEvent(handler.path, (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
658
|
-
yield handler.value(instance, request, response);
|
|
634
|
+
yield handler.value(instance, this.moduleRef, request, response);
|
|
659
635
|
}));
|
|
660
636
|
});
|
|
661
637
|
const [leaveHandler] = getLeaveHandlers();
|
|
662
638
|
if (leaveHandler) {
|
|
663
639
|
channelInstance.onLeave((event) => __awaiter(this, void 0, void 0, function* () {
|
|
664
|
-
yield leaveHandler.value(instance, event);
|
|
640
|
+
yield leaveHandler.value(instance, this.moduleRef, event);
|
|
665
641
|
}));
|
|
666
642
|
}
|
|
667
643
|
set(channelInstance);
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server as HTTPServer, IncomingHttpHeaders } from 'http';
|
|
2
2
|
|
|
3
|
-
import { ModuleMetadata, DynamicModule } from '@nestjs/common';
|
|
3
|
+
import type { ModuleMetadata, DynamicModule } from '@nestjs/common';
|
|
4
4
|
import type { Express } from 'express';
|
|
5
5
|
import { WebSocketServer } from 'ws';
|
|
6
6
|
|
|
@@ -87,12 +87,36 @@ interface LeaveEvent {
|
|
|
87
87
|
|
|
88
88
|
type LeaveCallback = (event: LeaveEvent) => void;
|
|
89
89
|
|
|
90
|
+
interface NestRequest {
|
|
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;
|
|
104
|
+
|
|
90
105
|
interface UserData {
|
|
91
106
|
assigns: PondAssigns;
|
|
92
107
|
presence: PondPresence;
|
|
93
108
|
id: string;
|
|
94
109
|
}
|
|
95
110
|
|
|
111
|
+
export interface CanActivate {
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @desc Whether the client can continue with the request
|
|
115
|
+
* @param request - the request to check
|
|
116
|
+
*/
|
|
117
|
+
canActivate(request: NestRequest): boolean | Promise<boolean>;
|
|
118
|
+
}
|
|
119
|
+
|
|
96
120
|
export enum ChannelState {
|
|
97
121
|
IDLE = 'IDLE',
|
|
98
122
|
JOINING = 'JOINING',
|
|
@@ -750,6 +774,19 @@ declare function GetConnectionHeaders(): ParameterDecorator;
|
|
|
750
774
|
*/
|
|
751
775
|
declare function GetConnectionQuery(): ParameterDecorator;
|
|
752
776
|
|
|
777
|
+
/**
|
|
778
|
+
* @desc The Decorator for retrieving the LeaveEvent in a handler
|
|
779
|
+
* @returns {LeaveEvent}
|
|
780
|
+
*/
|
|
781
|
+
declare function GetLeaveEvent(): ParameterDecorator;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* @desc Function to create a param decorator
|
|
785
|
+
* @param callback - The callback to call when the decorator is used
|
|
786
|
+
* @returns {ReturnType<callback>}
|
|
787
|
+
*/
|
|
788
|
+
declare function createParamDecorator<Input> (callback: ParamDecoratorCallback<Input>): ParameterDecorator;
|
|
789
|
+
|
|
753
790
|
/**
|
|
754
791
|
* @desc Marks a method as a handler for JoinRequest events. Throwing an error will reject the request with the error message.
|
|
755
792
|
*/
|
|
@@ -789,18 +826,18 @@ declare function ChannelInstance(name?: string): PropertyDecorator;
|
|
|
789
826
|
*/
|
|
790
827
|
declare function EndpointInstance (): PropertyDecorator;
|
|
791
828
|
|
|
792
|
-
/**
|
|
793
|
-
* Decorator to mark a class as having multiple channels.
|
|
794
|
-
* @param channels - The array of channels.
|
|
795
|
-
*/
|
|
796
|
-
declare function Channels(channels: Constructor<NonNullable<unknown>>[]): ClassDecorator;
|
|
797
|
-
|
|
798
829
|
/**
|
|
799
830
|
* Decorator to mark a class as an endpoint.
|
|
800
831
|
* @param metadata - The metadata for the endpoint.
|
|
801
832
|
*/
|
|
802
833
|
declare function DEndpoint(metadata: EndpointMetadata): ClassDecorator;
|
|
803
834
|
|
|
835
|
+
/**
|
|
836
|
+
* Decorator to add a guard to a class or method.
|
|
837
|
+
* @param guards - The guards to add.
|
|
838
|
+
*/
|
|
839
|
+
declare function PondGuards (...guards: Constructor<CanActivate>[]): ClassDecorator | MethodDecorator;
|
|
840
|
+
|
|
804
841
|
declare class PondSocketModule {
|
|
805
842
|
/**
|
|
806
843
|
* @desc Creates a new PondSocketModule
|