justrun-ws 0.1.2 → 0.2.0

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