@eleven-am/pondsocket 0.1.75 → 0.1.76
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 +30 -18
- package/package.json +1 -1
package/nest.js
CHANGED
|
@@ -46,6 +46,7 @@ const onEventHandlerKey = Symbol('onEventHandlerKey');
|
|
|
46
46
|
const onConnectionHandlerKey = Symbol('onConnectionHandlerKey');
|
|
47
47
|
const channelsKey = Symbol('channelsKey');
|
|
48
48
|
const endpointsKey = Symbol('endpointsKey');
|
|
49
|
+
const channelInstanceKey = Symbol('channelInstanceKey');
|
|
49
50
|
function createParamDecorator(key, error) {
|
|
50
51
|
return (target, propertyKey, parameterIndex) => {
|
|
51
52
|
const existingParams = Reflect.getMetadata(key, target, propertyKey);
|
|
@@ -72,20 +73,37 @@ function createClassDecorator(key, target) {
|
|
|
72
73
|
},
|
|
73
74
|
};
|
|
74
75
|
}
|
|
76
|
+
function manageClassData(key, target) {
|
|
77
|
+
return {
|
|
78
|
+
get() {
|
|
79
|
+
return Reflect.getMetadata(key, target);
|
|
80
|
+
},
|
|
81
|
+
set(value) {
|
|
82
|
+
Reflect.defineMetadata(key, value, target);
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
75
86
|
function manageHandlers(key, target) {
|
|
87
|
+
const { get, set } = manageClassData(key, target);
|
|
76
88
|
return {
|
|
77
89
|
get() {
|
|
78
|
-
return (
|
|
90
|
+
return get() || [];
|
|
79
91
|
},
|
|
80
92
|
set(path, value) {
|
|
81
|
-
const handlers =
|
|
82
|
-
|
|
83
|
-
...handlers,
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
const handlers = get() || [];
|
|
94
|
+
set([
|
|
95
|
+
...handlers,
|
|
96
|
+
{
|
|
97
|
+
path,
|
|
98
|
+
value,
|
|
99
|
+
},
|
|
100
|
+
]);
|
|
86
101
|
},
|
|
87
102
|
};
|
|
88
103
|
}
|
|
104
|
+
function manageChannelInstance(target) {
|
|
105
|
+
return manageClassData(channelInstanceKey, target);
|
|
106
|
+
}
|
|
89
107
|
function manageJoinHandlers(target) {
|
|
90
108
|
return manageHandlers(onJoinHandlerKey, target);
|
|
91
109
|
}
|
|
@@ -409,10 +427,6 @@ function OnConnectionRequest() {
|
|
|
409
427
|
exports.OnConnectionRequest = OnConnectionRequest;
|
|
410
428
|
function Channel(path = '*') {
|
|
411
429
|
return (constructor) => class extends constructor {
|
|
412
|
-
constructor() {
|
|
413
|
-
super(...arguments);
|
|
414
|
-
this._channel = null;
|
|
415
|
-
}
|
|
416
430
|
_setEndpoint(endpoint) {
|
|
417
431
|
const channel = endpoint.createChannel(path, (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
418
432
|
const { get } = manageJoinHandlers(this);
|
|
@@ -424,29 +438,27 @@ function Channel(path = '*') {
|
|
|
424
438
|
response.accept();
|
|
425
439
|
}
|
|
426
440
|
}));
|
|
441
|
+
const { set } = manageChannelInstance(this);
|
|
427
442
|
const { get } = manageEventHandlers(this);
|
|
428
|
-
|
|
429
|
-
|
|
443
|
+
set(channel);
|
|
444
|
+
get().forEach((handler) => {
|
|
430
445
|
channel.onEvent(handler.path, (request, response) => __awaiter(this, void 0, void 0, function* () {
|
|
431
446
|
yield handler.value(request, response);
|
|
432
447
|
}));
|
|
433
448
|
});
|
|
434
|
-
this._channel = channel;
|
|
435
449
|
}
|
|
436
450
|
};
|
|
437
451
|
}
|
|
438
452
|
exports.Channel = Channel;
|
|
439
453
|
function ChannelInstance() {
|
|
440
454
|
return (target, propertyKey) => {
|
|
455
|
+
const { get } = manageChannelInstance(target.constructor.prototype);
|
|
441
456
|
Object.defineProperty(target, propertyKey, {
|
|
442
457
|
get() {
|
|
443
|
-
|
|
444
|
-
throw new Error('Channel not initialized');
|
|
445
|
-
}
|
|
446
|
-
return target._channel;
|
|
458
|
+
return get();
|
|
447
459
|
},
|
|
448
460
|
set() {
|
|
449
|
-
throw new Error('
|
|
461
|
+
throw new Error('ChannelInstance is readonly');
|
|
450
462
|
},
|
|
451
463
|
});
|
|
452
464
|
};
|