justrun-ws 0.2.2 → 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(z) {
50
- return this.t.get(z);
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.D);
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.D);
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,221 +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.D));
137
- }
138
- a9(conn, err) {
139
- const z = conn.id;
140
- this.t.delete(z);
141
- this.J?.remove(conn);
142
- conn.n(err);
143
- this.B?.(this, conn, conn.b.O(), err);
144
- }
145
- a7(conn, a) {
146
- const { buff, pkgType, requestId, bodyOffset } = a;
147
- if (pkgType === this.responsePkgType) {
148
- const h = buff.subarray(bodyOffset);
149
- conn.X(requestId, h);
150
- }
151
- else {
152
- const Y = this.L.get(pkgType);
153
- if (Y) {
154
- const h = buff.subarray(bodyOffset);
155
- const af = new Y(h, true);
156
- conn.ag(requestId, af);
136
+ conn.close(new Error(NetErrorString.$));
137
+ }
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
+ }
145
+ ac(conn, a) {
146
+ try {
147
+ const { buff, pkgType, requestId, bodyOffset } = a;
148
+ if (pkgType === this.responsePkgType) {
149
+ const body = buff.subarray(bodyOffset);
150
+ conn.a5(requestId, body);
151
+ }
152
+ else {
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
+ }
157
159
  }
158
160
  }
161
+ catch {
162
+ conn.close(new Error(NetErrorString.$));
163
+ }
159
164
  }
160
- V;
165
+ a4;
161
166
  s;
162
- T;
163
- U;
164
- A;
167
+ a2;
168
+ a3;
169
+ E;
165
170
  t;
166
- f;
167
- L;
168
- J;
171
+ h;
172
+ T;
173
+ P;
169
174
  }
170
- class x extends MonitorConn {
171
- constructor(w, b, id) {
175
+ class w extends MonitorConn {
176
+ constructor(v, c, id) {
172
177
  super();
173
178
  this.id = id;
174
- this.b = b;
175
- this.C = w;
176
- this.Z = 0;
179
+ this.c = c;
180
+ this.F = v;
181
+ this.a6 = 0;
177
182
  }
178
183
  context;
179
184
  id;
180
- b;
181
- get localAddress() {
182
- return this.b.localAddress;
183
- }
184
- get localPort() {
185
- return this.b.localPort;
186
- }
187
- get remoteAddress() {
188
- return this.b.remoteAddress;
189
- }
190
- get remoteFamily() {
191
- return this.b.remoteFamily;
192
- }
193
- get remotePort() {
194
- return this.b.remotePort;
185
+ c;
186
+ get socket() {
187
+ return this.c.socket;
195
188
  }
196
189
  sendMessage(message) {
197
190
  const pkgType = message.constructor.pkgType;
198
191
  const encoded = [message.buff];
199
- this.C.makePkgBuff(pkgType, 0, encoded);
200
- return this.b.p(encoded);
192
+ this.F.makePkgBuff(pkgType, 0, encoded);
193
+ return this.c.n(encoded);
201
194
  }
202
195
  sendRequest(request) {
203
- this.k = new Map();
204
- this.sendRequest = this.a0;
205
- this.X = this.ah;
206
- this.n = this.ai;
207
- 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);
208
201
  }
209
202
  sendErrorResponse(error, requestId) {
210
203
  const pkgType = error.constructor.pkgType;
211
204
  const encoded = [error.buff];
212
- this.C.makePkgBuff(pkgType, requestId, encoded);
213
- return this.b.p(encoded);
205
+ this.F.makePkgBuff(pkgType, requestId, encoded);
206
+ return this.c.n(encoded);
214
207
  }
215
208
  sendResponse(request, requestId) {
216
209
  const encoded = [request.respBuff];
217
- const { makePkgBuff, responsePkgType } = this.C;
210
+ const { makePkgBuff, responsePkgType } = this.F;
218
211
  makePkgBuff(responsePkgType, requestId, encoded);
219
- return this.b.p(encoded);
212
+ return this.c.n(encoded);
220
213
  }
221
214
  async close(err) {
222
- await this.b.close(err);
215
+ await this.c.close(err);
223
216
  }
224
- X(requestId, ap) {
217
+ a5(requestId, an) {
225
218
  if (requestId === 0x200000 && this.context === undefined) {
226
- this.close(new Error(NetErrorString.I));
219
+ this.close(new Error(NetErrorString.H));
227
220
  }
228
221
  }
229
- ag(requestId, error) {
230
- const j = this.k.get(requestId);
231
- if (j) {
232
- this.k.delete(requestId);
233
- 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);
234
227
  }
235
228
  }
236
229
  keepAlive() {
237
- this.b.N(this.C.u).catch(l);
230
+ this.c.D(this.F.r).catch(l);
238
231
  }
239
232
  timeout() {
240
- this.close(new Error(NetErrorString.a2));
233
+ this.close(new Error(NetErrorString.Z));
241
234
  }
242
- n(aj) {
235
+ o(aa) {
243
236
  }
244
- async a0(request) {
245
- const requestId = (this.Z++) & 0x1fffff;
237
+ async a7(request) {
238
+ const requestId = (this.a6++) & 0x1fffff;
246
239
  const pkgType = request.constructor.pkgType;
247
240
  const encoded = [request.buff];
248
- this.C.makePkgBuff(pkgType, requestId, encoded);
249
- const ak = new Promise((d, i) => {
250
- const al = { d, i };
251
- this.k.set(requestId, al);
252
- this.b.p(encoded).catch((err) => {
253
- this.k.delete(requestId);
254
- 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);
255
248
  });
256
249
  });
257
- request.respBuff = await ak;
250
+ request.respBuff = await ab;
258
251
  }
259
- ah(requestId, h) {
260
- const j = this.k.get(requestId);
261
- if (j) {
262
- this.k.delete(requestId);
263
- 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);
264
257
  return;
265
258
  }
266
259
  if (requestId === 0x200000 && this.context === undefined) {
267
- this.close(new Error(NetErrorString.I));
260
+ this.close(new Error(NetErrorString.H));
268
261
  }
269
262
  }
270
- ai(err) {
271
- const H = this.k;
272
- if (H.size > 0) {
263
+ aj(err) {
264
+ const C = this.m;
265
+ if (C.size > 0) {
273
266
  if (!err) {
274
- err = new Error(NetErrorString.a1);
267
+ err = new Error(NetErrorString.Y);
275
268
  }
276
- for (const [requestId, j] of H) {
277
- H.delete(requestId);
278
- j.i(err);
269
+ for (const [requestId, i] of C) {
270
+ C.delete(requestId);
271
+ i.j(err);
279
272
  }
280
273
  }
281
- this.k = undefined;
274
+ this.m = undefined;
282
275
  }
283
- C;
284
- k;
285
- Z;
276
+ F;
277
+ m;
278
+ a6;
286
279
  }
287
- class aa {
288
- constructor(id, am) {
280
+ class a0 {
281
+ constructor(id, al) {
289
282
  this.id = id;
290
- this.M = am;
283
+ this.U = al;
291
284
  }
292
285
  context;
293
286
  id;
294
- localAddress;
295
- localPort;
296
- remoteAddress;
297
- remotePort;
287
+ socket;
298
288
  get remoteFamily() {
299
289
  return 'Local';
300
290
  }
301
291
  async sendMessage(message) {
302
- return this.M.ab(this, message);
292
+ return this.U.af(this, message);
303
293
  }
304
294
  async sendRequest(request) {
305
- return this.M.ac(this, request);
295
+ return this.U.ag(this, request);
306
296
  }
307
- sendErrorResponse(aq, an) {
297
+ sendErrorResponse(ao, am) {
308
298
  throw null;
309
299
  }
310
- sendResponse(_request, an) {
300
+ sendResponse(ap, am) {
311
301
  throw null;
312
302
  }
313
- async close(aj) {
303
+ async close(aa) {
314
304
  }
315
- M;
305
+ U;
316
306
  }
317
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.2",
3
+ "version": "0.3.0",
4
4
  "scripts": {
5
5
  "start": "webpack serve"
6
6
  },
@@ -36,4 +36,4 @@
36
36
  "webpack": "^5.98.0",
37
37
  "webpack-cli": "^6.0.1"
38
38
  }
39
- }
39
+ }