justrun-ws 0.3.1 → 0.3.3

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.
@@ -1,70 +0,0 @@
1
- import { ListNode, c } from '../common/List';
2
- import { l } from '../common/utils';
3
- export class MonitorItem extends ListNode {
4
- }
5
- export class TimeoutMonitor {
6
- constructor(f, h, g) {
7
- this.X = f;
8
- this.J = h;
9
- this.F = g;
10
- this.p = 0;
11
- this.G = 0;
12
- this.r = [];
13
- if (f === 0) {
14
- this.insert = l;
15
- this.update = l;
16
- this.remove = l;
17
- return;
18
- }
19
- for (let a = 0; a < g; a++) {
20
- this.r.push(new c());
21
- }
22
- }
23
- insert(item) {
24
- if (!this.G) {
25
- this.Y = setInterval(this.a8, this.X);
26
- }
27
- this.G++;
28
- this.r[this.p].W(item);
29
- }
30
- update(item) {
31
- item.remove();
32
- this.r[this.p].W(item);
33
- }
34
- remove(item) {
35
- item.remove();
36
- this.G--;
37
- if (!this.G) {
38
- clearInterval(this.Y);
39
- }
40
- }
41
- a8 = () => {
42
- const { J, F, r } = this;
43
- this.p++;
44
- if (this.p === F) {
45
- this.p = 0;
46
- }
47
- if (J) {
48
- let d = this.p + J;
49
- if (d >= F) {
50
- d -= F;
51
- }
52
- const b = r[d];
53
- for (let node = b.e; !b.V(node); node = node.getNext()) {
54
- node.warnTimeout();
55
- }
56
- }
57
- const b = r[this.p];
58
- for (let node = b.e; !b.V(node); node = node.getNext()) {
59
- node.onTimeout();
60
- }
61
- };
62
- X;
63
- J;
64
- F;
65
- p;
66
- G;
67
- Y;
68
- r;
69
- }
70
- //# sourceMappingURL=TimeoutMonitor.js.map
@@ -1,307 +0,0 @@
1
- import { y, l } from '../common/utils';
2
- import { NetErrorString } from './NetErrorString';
3
- import { MonitorItem } from './TimeoutMonitor';
4
- export class u {
5
- constructor(C, v) {
6
- const { responsePkgType, timeoutMonitor, makePkgBuff, parsePkgBuff } = v;
7
- this.responsePkgType = responsePkgType;
8
- this.s = 0;
9
- this.t = new Map();
10
- this.h = new Map();
11
- this.R = new Map();
12
- this.Z = makePkgBuff;
13
- this.a0 = parsePkgBuff;
14
- this.A = C;
15
- this.K = timeoutMonitor;
16
- const E = this;
17
- E.x = this.a9;
18
- const r = [];
19
- this.Z(responsePkgType, 0x200000, r);
20
- this.a1 = {
21
- makePkgBuff: makePkgBuff,
22
- responsePkgType: responsePkgType,
23
- r: y(r),
24
- };
25
- this.h.set(responsePkgType, E);
26
- this.A.init((e, p) => {
27
- do {
28
- this.s++;
29
- } while (this.t.has(this.s & 0x1fffff));
30
- const conn = new z(this.a1, e, this.s & 0x1fffff);
31
- this.t.set(conn.id, conn);
32
- this.K?.insert(conn);
33
- const f = {
34
- conn,
35
- _: (buff) => this.aa(conn, buff),
36
- o: (err) => this.ab(conn, err),
37
- };
38
- this.L?.(this, conn, !!p);
39
- return f;
40
- });
41
- }
42
- responsePkgType;
43
- context;
44
- L;
45
- H;
46
- b() {
47
- return this.A.b();
48
- }
49
- P(w) {
50
- return this.t.get(w);
51
- }
52
- g(c) {
53
- return this.A.g(c);
54
- }
55
- async Q() {
56
- do {
57
- this.s++;
58
- } while (this.t.has(this.s & 0x1fffff));
59
- const conn = new V(this.s & 0x1fffff, this);
60
- this.t.set(conn.id, conn);
61
- return conn;
62
- }
63
- async T(c) {
64
- return this.A.I(c);
65
- }
66
- async U() {
67
- return this.A.J();
68
- }
69
- ac(conn, message) {
70
- const pkgType = message.constructor.pkgType;
71
- const handler = this.h.get(pkgType);
72
- if (handler) {
73
- return handler?.q(conn, message);
74
- }
75
- throw new Error(NetErrorString.InvalidPackage);
76
- }
77
- ad(conn, request) {
78
- const pkgType = request.constructor.pkgType;
79
- const handler = this.h.get(pkgType);
80
- if (handler) {
81
- return handler?.q(conn, request);
82
- }
83
- throw new Error(NetErrorString.InvalidPackage);
84
- }
85
- registerError(pkgType, wrapperCtor) {
86
- wrapperCtor.registerPkgType(pkgType);
87
- this.R.set(pkgType, wrapperCtor);
88
- const W = this.h.get(this.responsePkgType);
89
- this.h.set(pkgType, W);
90
- }
91
- registerMessage(pkgType, wrapperCtor) {
92
- wrapperCtor.registerPkgType(pkgType);
93
- }
94
- registerRequest(pkgType, wrapperCtor) {
95
- wrapperCtor.registerPkgType(pkgType);
96
- }
97
- handleMessageWith(handler) {
98
- const pkgType = handler.pkgType;
99
- if (typeof pkgType !== typeof this.responsePkgType) {
100
- throw new Error(`Wrapper ${handler.k} has an incompatible pkgType ${typeof pkgType}`);
101
- }
102
- if (this.h.has(pkgType)) {
103
- throw new Error(`Wrapper ${handler.k} is already handled by another handler`);
104
- }
105
- this.h.set(pkgType, handler);
106
- return handler;
107
- }
108
- handleRequestWith(handler) {
109
- const pkgType = handler.pkgType;
110
- if (typeof pkgType !== typeof this.responsePkgType) {
111
- throw new Error(`Wrapper ${handler.k} has an incompatible pkgType ${typeof pkgType}`);
112
- }
113
- if (this.h.has(pkgType)) {
114
- throw new Error(`Wrapper ${handler.k} is already handled by another handler`);
115
- }
116
- this.h.set(pkgType, handler);
117
- return handler;
118
- }
119
- an(handler) {
120
- const pkgType = handler.pkgType;
121
- const X = this.h.get(pkgType);
122
- if (X === handler) {
123
- this.h.delete(pkgType);
124
- return true;
125
- }
126
- return false;
127
- }
128
- aa(conn, buff) {
129
- this.K?.update(conn);
130
- const a = this.a0(buff);
131
- const handler = this.h.get(a.pkgType);
132
- if (handler) {
133
- handler.x(conn, a);
134
- return;
135
- }
136
- conn.close(new Error(NetErrorString.InvalidPackage));
137
- }
138
- ab(conn, err) {
139
- const w = conn.id;
140
- this.t.delete(w);
141
- this.K?.remove(conn);
142
- conn.o(err);
143
- this.H?.(this, conn, conn.e.G(), err);
144
- }
145
- a9(conn, a) {
146
- try {
147
- const { buff, pkgType, requestId, bodyOffset } = a;
148
- if (pkgType === this.responsePkgType) {
149
- const body = buff.subarray(bodyOffset);
150
- conn.a2(requestId, body);
151
- }
152
- else {
153
- const N = this.R.get(pkgType);
154
- if (N) {
155
- const body = buff.subarray(bodyOffset);
156
- const Y = new N(body, true);
157
- conn.ae(requestId, Y);
158
- }
159
- }
160
- }
161
- catch {
162
- conn.close(new Error(NetErrorString.InvalidPackage));
163
- }
164
- }
165
- a1;
166
- s;
167
- Z;
168
- a0;
169
- A;
170
- t;
171
- h;
172
- R;
173
- K;
174
- }
175
- class z extends MonitorItem {
176
- constructor(v, e, id) {
177
- super();
178
- this.id = id;
179
- this.e = e;
180
- this.B = v;
181
- this.a3 = 0;
182
- }
183
- context;
184
- id;
185
- e;
186
- get socket() {
187
- return this.e.socket;
188
- }
189
- sendMessage(message) {
190
- const pkgType = message.constructor.pkgType;
191
- const encoded = [message.buff];
192
- this.B.makePkgBuff(pkgType, 0, encoded);
193
- return this.e.n(encoded);
194
- }
195
- sendRequest(request) {
196
- this.m = new Map();
197
- this.sendRequest = this.a4;
198
- this.a2 = this.af;
199
- this.o = this.ag;
200
- return this.a4(request);
201
- }
202
- sendErrorResponse(error, requestId) {
203
- const pkgType = error.constructor.pkgType;
204
- const encoded = [error.buff];
205
- this.B.makePkgBuff(pkgType, requestId, encoded);
206
- return this.e.n(encoded);
207
- }
208
- sendResponse(request, requestId) {
209
- const encoded = [request.respBuff];
210
- const { makePkgBuff, responsePkgType } = this.B;
211
- makePkgBuff(responsePkgType, requestId, encoded);
212
- return this.e.n(encoded);
213
- }
214
- async close(err) {
215
- await this.e.close(err);
216
- }
217
- a2(requestId, ai) {
218
- if (requestId === 0x200000 && this.context === undefined) {
219
- this.close(new Error(NetErrorString.AuthTimeout));
220
- }
221
- }
222
- ae(requestId, error) {
223
- const i = this.m.get(requestId);
224
- if (i) {
225
- this.m.delete(requestId);
226
- return i.j(error);
227
- }
228
- }
229
- warnTimeout() {
230
- this.e.F(this.B.r).catch(l);
231
- }
232
- onTimeout() {
233
- this.close(new Error(NetErrorString.Timeout));
234
- }
235
- o(a5) {
236
- }
237
- async a4(request) {
238
- const requestId = (this.a3++) & 0x1fffff;
239
- const pkgType = request.constructor.pkgType;
240
- const encoded = [request.buff];
241
- this.B.makePkgBuff(pkgType, requestId, encoded);
242
- const a6 = new Promise((d, j) => {
243
- const a7 = { d, j };
244
- this.m.set(requestId, a7);
245
- this.e.n(encoded).catch((err) => {
246
- this.m.delete(requestId);
247
- j(err);
248
- });
249
- });
250
- request.respBuff = await a6;
251
- }
252
- af(requestId, body) {
253
- const i = this.m.get(requestId);
254
- if (i) {
255
- this.m.delete(requestId);
256
- i.d(body);
257
- return;
258
- }
259
- if (requestId === 0x200000 && this.context === undefined) {
260
- this.close(new Error(NetErrorString.AuthTimeout));
261
- }
262
- }
263
- ag(err) {
264
- const D = this.m;
265
- if (D.size > 0) {
266
- if (!err) {
267
- err = new Error(NetErrorString.ConnectionClosed);
268
- }
269
- for (const [requestId, i] of D) {
270
- D.delete(requestId);
271
- i.j(err);
272
- }
273
- }
274
- this.m = undefined;
275
- }
276
- B;
277
- m;
278
- a3;
279
- }
280
- class V {
281
- constructor(id, a8) {
282
- this.id = id;
283
- this.S = a8;
284
- }
285
- context;
286
- id;
287
- socket;
288
- get remoteFamily() {
289
- return 'Local';
290
- }
291
- async sendMessage(message) {
292
- return this.S.ac(this, message);
293
- }
294
- async sendRequest(request) {
295
- return this.S.ad(this, request);
296
- }
297
- sendErrorResponse(aj, ah) {
298
- throw null;
299
- }
300
- sendResponse(ak, ah) {
301
- throw null;
302
- }
303
- async close(a5) {
304
- }
305
- S;
306
- }
307
- //# sourceMappingURL=TypedPkgHub.js.map
@@ -1,14 +0,0 @@
1
- import { j, l, m } from '../common/varUintOps';
2
- export const n = (pkgType, requestId, encoded) => {
3
- const i = [requestId, pkgType];
4
- const b = j(i);
5
- const a = new Uint8Array(b);
6
- m(i, a);
7
- encoded.push(a);
8
- };
9
- export const o = (buff) => {
10
- const { h: [requestId, pkgType], k: bodyOffset } = l(2, buff);
11
- const result = { buff, pkgType, requestId, bodyOffset };
12
- return result;
13
- };
14
- //# sourceMappingURL=hubPkgSerializer.js.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=interfaces.js.map