@eleven-am/pondsocket 0.1.7 → 0.1.9
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/README.md +3 -5
- package/package.json +1 -2
- package/pondBase/baseClass.d.ts +3 -1
- package/pondBase/baseClass.js +51 -32
- package/pondBase/baseClass.test.js +34 -34
- package/pondBase/pondBase.js +95 -34
- package/pondBase/pondBase.test.js +67 -39
- package/pondBase/pubSub.d.ts +10 -5
- package/pondBase/pubSub.js +127 -57
- package/pondBase/pubSub.test.js +120 -106
- package/pondBase/simpleBase.d.ts +0 -5
- package/pondBase/simpleBase.js +166 -92
- package/pondBase/simpleBase.test.js +124 -66
- package/pondClient/channel.d.ts +19 -19
- package/pondClient/channel.js +79 -100
- package/pondClient/socket.d.ts +13 -14
- package/pondClient/socket.js +58 -89
- package/pondSocket/channel.d.ts +2 -7
- package/pondSocket/channel.js +174 -121
- package/pondSocket/channel.test.js +89 -78
- package/pondSocket/channelMiddleWare.d.ts +2 -0
- package/pondSocket/channelMiddleWare.js +43 -16
- package/pondSocket/endpoint.d.ts +2 -2
- package/pondSocket/endpoint.js +188 -96
- package/pondSocket/endpoint.test.js +641 -479
- package/pondSocket/pondChannel.d.ts +2 -2
- package/pondSocket/pondChannel.js +142 -89
- package/pondSocket/pondChannel.test.js +40 -40
- package/pondSocket/pondResponse.js +87 -52
- package/pondSocket/pondSocket.d.ts +2 -2
- package/pondSocket/pondSocket.js +55 -35
- package/pondSocket/server.test.js +151 -88
- package/pondSocket/socketMiddleWare.js +16 -14
package/pondBase/pubSub.d.ts
CHANGED
|
@@ -5,21 +5,26 @@ export declare class Subscription {
|
|
|
5
5
|
export declare class Broadcast<T, A> {
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @desc
|
|
9
|
-
* @param handler - The handler to call when the broadcast is published
|
|
8
|
+
* @desc Gets the number of subscribers
|
|
10
9
|
*/
|
|
11
|
-
|
|
10
|
+
get subscriberCount(): number;
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
|
-
* @desc
|
|
13
|
+
* @desc Subscribe to the broadcast
|
|
14
|
+
* @param handler - The handler to call when the broadcast is published
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
subscribe(handler: (data: T) => A): Subscription;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @desc Publish to the broadcast
|
|
20
20
|
* @param data - The data to publish
|
|
21
21
|
*/
|
|
22
22
|
publish(data: T): A | undefined;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @dec clears all subscribers
|
|
26
|
+
*/
|
|
27
|
+
clear(): void;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
export declare class Subject<T, A> extends Broadcast<T, A> {
|
package/pondBase/pubSub.js
CHANGED
|
@@ -1,79 +1,135 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __values = (this && this.__values) || function(o) {
|
|
18
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
+
if (m) return m.call(o);
|
|
20
|
+
if (o && typeof o.length === "number") return {
|
|
21
|
+
next: function () {
|
|
22
|
+
if (o && i >= o.length) o = void 0;
|
|
23
|
+
return { value: o && o[i++], done: !o };
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.EventPubSub = exports.Subject = exports.Broadcast = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
30
|
+
var Broadcast = /** @class */ (function () {
|
|
31
|
+
function Broadcast() {
|
|
6
32
|
this._subscribers = new Set();
|
|
7
33
|
}
|
|
8
34
|
/**
|
|
9
35
|
* @desc Subscribe to the broadcast
|
|
10
36
|
* @param handler - The handler to call when the broadcast is published
|
|
11
37
|
*/
|
|
12
|
-
subscribe(handler) {
|
|
38
|
+
Broadcast.prototype.subscribe = function (handler) {
|
|
39
|
+
var _this = this;
|
|
13
40
|
this._subscribers.add(handler);
|
|
14
41
|
return {
|
|
15
42
|
/**
|
|
16
43
|
* @desc Unsubscribe from the broadcast
|
|
17
44
|
*/
|
|
18
|
-
unsubscribe: ()
|
|
19
|
-
|
|
45
|
+
unsubscribe: function () {
|
|
46
|
+
_this._subscribers.delete(handler);
|
|
20
47
|
}
|
|
21
48
|
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(Broadcast.prototype, "subscriberCount", {
|
|
51
|
+
/**
|
|
52
|
+
* @desc Gets the number of subscribers
|
|
53
|
+
*/
|
|
54
|
+
get: function () {
|
|
55
|
+
return this._subscribers.size;
|
|
56
|
+
},
|
|
57
|
+
enumerable: false,
|
|
58
|
+
configurable: true
|
|
59
|
+
});
|
|
29
60
|
/**
|
|
30
61
|
* @desc Publish to the broadcast
|
|
31
62
|
* @param data - The data to publish
|
|
32
63
|
*/
|
|
33
|
-
publish(data) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
64
|
+
Broadcast.prototype.publish = function (data) {
|
|
65
|
+
var e_1, _a;
|
|
66
|
+
var result;
|
|
67
|
+
try {
|
|
68
|
+
for (var _b = __values(this._subscribers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
69
|
+
var subscriber = _c.value;
|
|
70
|
+
result = subscriber(data);
|
|
71
|
+
if (result)
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
76
|
+
finally {
|
|
77
|
+
try {
|
|
78
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
79
|
+
}
|
|
80
|
+
finally { if (e_1) throw e_1.error; }
|
|
39
81
|
}
|
|
40
82
|
return result;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.Broadcast = Broadcast;
|
|
44
|
-
class Subject extends Broadcast {
|
|
45
|
-
constructor(value) {
|
|
46
|
-
super();
|
|
47
|
-
this._value = value;
|
|
48
|
-
}
|
|
83
|
+
};
|
|
49
84
|
/**
|
|
50
|
-
* @
|
|
85
|
+
* @dec clears all subscribers
|
|
51
86
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
87
|
+
Broadcast.prototype.clear = function () {
|
|
88
|
+
this._subscribers.clear();
|
|
89
|
+
};
|
|
90
|
+
return Broadcast;
|
|
91
|
+
}());
|
|
92
|
+
exports.Broadcast = Broadcast;
|
|
93
|
+
var Subject = /** @class */ (function (_super) {
|
|
94
|
+
__extends(Subject, _super);
|
|
95
|
+
function Subject(value) {
|
|
96
|
+
var _this = _super.call(this) || this;
|
|
97
|
+
_this._value = value;
|
|
98
|
+
return _this;
|
|
54
99
|
}
|
|
100
|
+
Object.defineProperty(Subject.prototype, "value", {
|
|
101
|
+
/**
|
|
102
|
+
* @desc Get the current value of the subject
|
|
103
|
+
*/
|
|
104
|
+
get: function () {
|
|
105
|
+
return this._value;
|
|
106
|
+
},
|
|
107
|
+
enumerable: false,
|
|
108
|
+
configurable: true
|
|
109
|
+
});
|
|
55
110
|
/**
|
|
56
111
|
* @desc Subscribe to the subject
|
|
57
112
|
* @param handler - The handler to call when the subject is published
|
|
58
113
|
*/
|
|
59
|
-
subscribe(handler) {
|
|
114
|
+
Subject.prototype.subscribe = function (handler) {
|
|
60
115
|
void handler(this._value);
|
|
61
|
-
return
|
|
62
|
-
}
|
|
116
|
+
return _super.prototype.subscribe.call(this, handler);
|
|
117
|
+
};
|
|
63
118
|
/**
|
|
64
119
|
* @desc Publish to the subject
|
|
65
120
|
* @param data - The data to publish
|
|
66
121
|
*/
|
|
67
|
-
publish(data) {
|
|
122
|
+
Subject.prototype.publish = function (data) {
|
|
68
123
|
if (this._value !== data) {
|
|
69
124
|
this._value = data;
|
|
70
|
-
return
|
|
125
|
+
return _super.prototype.publish.call(this, data);
|
|
71
126
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
127
|
+
};
|
|
128
|
+
return Subject;
|
|
129
|
+
}(Broadcast));
|
|
74
130
|
exports.Subject = Subject;
|
|
75
|
-
|
|
76
|
-
|
|
131
|
+
var EventPubSub = /** @class */ (function () {
|
|
132
|
+
function EventPubSub() {
|
|
77
133
|
this._subscribers = new Set();
|
|
78
134
|
}
|
|
79
135
|
/**
|
|
@@ -81,8 +137,9 @@ class EventPubSub {
|
|
|
81
137
|
* @param event - The event to subscribe to
|
|
82
138
|
* @param handler - The handler to call when the event subject is published
|
|
83
139
|
*/
|
|
84
|
-
subscribe(event, handler) {
|
|
85
|
-
|
|
140
|
+
EventPubSub.prototype.subscribe = function (event, handler) {
|
|
141
|
+
var _this = this;
|
|
142
|
+
var subscriber = function (eventData) {
|
|
86
143
|
if (eventData.type === event)
|
|
87
144
|
return handler(eventData.data);
|
|
88
145
|
return undefined;
|
|
@@ -92,27 +149,39 @@ class EventPubSub {
|
|
|
92
149
|
/**
|
|
93
150
|
* @desc Unsubscribe from the event subject
|
|
94
151
|
*/
|
|
95
|
-
unsubscribe: ()
|
|
96
|
-
|
|
152
|
+
unsubscribe: function () {
|
|
153
|
+
_this._subscribers.delete(subscriber);
|
|
97
154
|
}
|
|
98
155
|
};
|
|
99
|
-
}
|
|
156
|
+
};
|
|
100
157
|
/**
|
|
101
158
|
* @desc Publish to the event subject
|
|
102
159
|
* @param event - The event to publish
|
|
103
160
|
* @param data - The data to publish
|
|
104
161
|
*/
|
|
105
|
-
publish(event, data) {
|
|
106
|
-
|
|
107
|
-
|
|
162
|
+
EventPubSub.prototype.publish = function (event, data) {
|
|
163
|
+
var e_2, _a;
|
|
164
|
+
try {
|
|
165
|
+
for (var _b = __values(this._subscribers), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
166
|
+
var subscriber = _c.value;
|
|
167
|
+
void subscriber({ type: event, data: data });
|
|
168
|
+
}
|
|
108
169
|
}
|
|
109
|
-
|
|
170
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
171
|
+
finally {
|
|
172
|
+
try {
|
|
173
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
174
|
+
}
|
|
175
|
+
finally { if (e_2) throw e_2.error; }
|
|
176
|
+
}
|
|
177
|
+
};
|
|
110
178
|
/**
|
|
111
179
|
* @desc Subscribe to all events
|
|
112
180
|
* @param handler - The handler to call when the event subject is published
|
|
113
181
|
*/
|
|
114
|
-
subscribeAll(handler) {
|
|
115
|
-
|
|
182
|
+
EventPubSub.prototype.subscribeAll = function (handler) {
|
|
183
|
+
var _this = this;
|
|
184
|
+
var subscriber = function (eventData) {
|
|
116
185
|
return handler(eventData.data);
|
|
117
186
|
};
|
|
118
187
|
this._subscribers.add(subscriber);
|
|
@@ -120,25 +189,26 @@ class EventPubSub {
|
|
|
120
189
|
/**
|
|
121
190
|
* @desc Unsubscribe from the event subject
|
|
122
191
|
*/
|
|
123
|
-
unsubscribe: ()
|
|
124
|
-
|
|
192
|
+
unsubscribe: function () {
|
|
193
|
+
_this._subscribers.delete(subscriber);
|
|
125
194
|
}
|
|
126
195
|
};
|
|
127
|
-
}
|
|
196
|
+
};
|
|
128
197
|
/**
|
|
129
198
|
* @desc Complete the event subject
|
|
130
199
|
*/
|
|
131
|
-
complete() {
|
|
200
|
+
EventPubSub.prototype.complete = function () {
|
|
132
201
|
this._subscribers.clear();
|
|
133
202
|
if (this._onComplete)
|
|
134
203
|
this._onComplete();
|
|
135
|
-
}
|
|
204
|
+
};
|
|
136
205
|
/**
|
|
137
206
|
* @desc Subscribe to the event subject completion
|
|
138
207
|
* @param handler - The handler to call when the event subject is completed
|
|
139
208
|
*/
|
|
140
|
-
onComplete(handler) {
|
|
209
|
+
EventPubSub.prototype.onComplete = function (handler) {
|
|
141
210
|
this._onComplete = handler;
|
|
142
|
-
}
|
|
143
|
-
|
|
211
|
+
};
|
|
212
|
+
return EventPubSub;
|
|
213
|
+
}());
|
|
144
214
|
exports.EventPubSub = EventPubSub;
|