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