@jayfong/x-server-client-helper 1.30.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.
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.XServerClientHelper = void 0;
5
+
6
+ var _vtils = require("vtils");
7
+
8
+ var _shorty = require("./utils/shorty");
9
+
10
+ var XServerClientHelper = /*#__PURE__*/function () {
11
+ function XServerClientHelper() {}
12
+
13
+ XServerClientHelper.processResponse = function processResponse(data) {
14
+ // 处理混淆
15
+ // _#
16
+ var shortyKey = String.fromCharCode(95) + String.fromCharCode(35);
17
+
18
+ if (data && typeof data === 'object' && data[shortyKey] != null) {
19
+ try {
20
+ data = JSON.parse(new _shorty.Shorty().decode(data[shortyKey]));
21
+ } catch (_unused) {}
22
+ } // 处理数组打包
23
+
24
+
25
+ data = _vtils.DataPacker.unpackIfNeeded(data);
26
+ return data;
27
+ };
28
+
29
+ return XServerClientHelper;
30
+ }();
31
+
32
+ exports.XServerClientHelper = XServerClientHelper;
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ exports.__esModule = true;
6
+ exports.Shorty = void 0;
7
+
8
+ var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
9
+
10
+ /* eslint-disable */
11
+ // @ts-nocheck
12
+ // https://github.com/enkimute/shorty.js
13
+ function ShortyRaw(tokensize) {
14
+ this.tokensize = tokensize || 10;
15
+ this.reset(true);
16
+ }
17
+
18
+ ShortyRaw.prototype.reset = function (full) {
19
+ if (full === true) {
20
+ this.nodes = [{
21
+ up: 0,
22
+ weight: 0
23
+ }];
24
+ this.nyt = 0;
25
+ this.nodecount = 0;
26
+ }
27
+
28
+ this.data = '';
29
+ this.curpos = 0;
30
+ this.bitCount = 7;
31
+ this.bitChar = 0;
32
+ };
33
+
34
+ ShortyRaw.prototype.findNode = function (x) {
35
+ for (var i = this.nodes.length - 1; i > 0; i--) {
36
+ if (typeof this.nodes[i].symbol != 'undefined' && this.nodes[i].symbol == x) return i;
37
+ }
38
+
39
+ return 0;
40
+ };
41
+
42
+ ShortyRaw.prototype.addNode = function (token) {
43
+ if (this.nodecount >= 2046) return 0;
44
+ this.nodes[++this.nodecount] = {
45
+ up: this.nyt,
46
+ symbol: token,
47
+ weight: 1
48
+ };
49
+ this.nodes[++this.nodecount] = {
50
+ up: this.nyt,
51
+ weight: 0
52
+ };
53
+ this.nodes[this.nyt].weight += 1;
54
+ this.nyt = this.nodecount;
55
+ if (this.nodes[this.nodecount - 2].up != this.nodecount - 2) this.balanceNode(this.nodes[this.nodecount - 2].up);
56
+ return this.nodecount - 2;
57
+ };
58
+
59
+ ShortyRaw.prototype.swapNode = function (a, b) {
60
+ var t = this.nodes[a].symbol;
61
+ var u = this.nodes[b].symbol;
62
+ var v = this.nodes[a].weight;
63
+ this.nodes[a].symbol = u;
64
+ this.nodes[b].symbol = t;
65
+ this.nodes[a].weight = this.nodes[b].weight;
66
+ this.nodes[b].weight = v;
67
+
68
+ for (var n = this.nodes.length - 1; n > 0; n--) {
69
+ if (this.nodes[n].up == a) this.nodes[n].up = b;else if (this.nodes[n].up == b) this.nodes[n].up = a;
70
+ }
71
+ };
72
+
73
+ ShortyRaw.prototype.balanceNode = function (node) {
74
+ while (true) {
75
+ var minnr = node;
76
+ var weight = this.nodes[node].weight;
77
+
78
+ while (minnr > 1 && this.nodes[minnr - 1].weight == weight) {
79
+ minnr--;
80
+ }
81
+
82
+ if (minnr != node && minnr != this.nodes[node].up) {
83
+ this.swapNode(minnr, node);
84
+ node = minnr;
85
+ }
86
+
87
+ this.nodes[node].weight++;
88
+ if (this.nodes[node].up == node) return;
89
+ node = this.nodes[node].up;
90
+ }
91
+ };
92
+
93
+ ShortyRaw.prototype.emitNode = function (node) {
94
+ var emit = [];
95
+
96
+ while (node != 0) {
97
+ emit.unshift(node % 2);
98
+ node = this.nodes[node].up;
99
+ }
100
+
101
+ for (var e = 0; e < emit.length; e++) {
102
+ this.emitBit(emit[e]);
103
+ }
104
+ };
105
+
106
+ ShortyRaw.prototype.emitNyt = function (token) {
107
+ this.emitNode(this.nyt);
108
+ var ll = token.length - 1;
109
+ if (this.tokensize > 8) this.emitBit(ll & 8);
110
+ if (this.tokensize > 4) this.emitBit(ll & 4);
111
+ if (this.tokensize > 2) this.emitBit(ll & 2);
112
+ if (this.tokensize > 1) this.emitBit(ll & 1);
113
+
114
+ for (var cc = 0; cc < token.length; cc++) {
115
+ this.emitByte(token.charCodeAt(cc));
116
+ }
117
+
118
+ return this.nyt;
119
+ };
120
+
121
+ ShortyRaw.prototype.readNode = function () {
122
+ if (this.nyt == 0) {
123
+ var len = (this.tokensize > 8 ? this.readBit() * 8 : 0) + (this.tokensize > 4 ? this.readBit() * 4 : 0) + (this.tokensize > 2 ? this.readBit() * 2 : 0) + (this.tokensize > 1 ? this.readBit() : 0) + 1;
124
+ var stream = '';
125
+
126
+ while (len--) {
127
+ stream += this.readByte();
128
+ }
129
+
130
+ return stream;
131
+ }
132
+
133
+ var node = 0;
134
+
135
+ while (true) {
136
+ var bit = this.readBit();
137
+ if (this.nodes[node].symbol == undefined) for (var m = 0;; m++) {
138
+ if (this.nodes[m].up == node && m != node && m % 2 == bit) {
139
+ node = m;
140
+ break;
141
+ }
142
+ }
143
+
144
+ if (this.nodes[node].symbol != undefined || this.nodes[node].weight == 0) {
145
+ if (this.nodes[node].weight) return this.nodes[node].symbol;
146
+ var len = (this.tokensize > 8 ? this.readBit() * 8 : 0) + (this.tokensize > 4 ? this.readBit() * 4 : 0) + (this.tokensize > 2 ? this.readBit() * 2 : 0) + (this.tokensize > 1 ? this.readBit() : 0) + 1;
147
+ var stream = '';
148
+
149
+ while (len--) {
150
+ stream += this.readByte();
151
+ }
152
+
153
+ return stream;
154
+ }
155
+ }
156
+ };
157
+
158
+ ShortyRaw.prototype.emitBit = function (bit) {
159
+ if (bit) this.bitChar += 1 << this.bitCount;
160
+
161
+ if (--this.bitCount < 0) {
162
+ this.data += String.fromCharCode(this.bitChar);
163
+ this.bitCount = 7;
164
+ this.bitChar = 0;
165
+ }
166
+ };
167
+
168
+ ShortyRaw.prototype.emitByte = function (_byte) {
169
+ for (var i = 7; i >= 0; i--) {
170
+ this.emitBit(_byte >> i & 1);
171
+ }
172
+ };
173
+
174
+ ShortyRaw.prototype.readBit = function () {
175
+ if (this.curpos == this.data.length * 8) throw 'done';
176
+ var bit = this.data.charCodeAt(this.curpos >> 3) >> (7 - this.curpos & 7) & 1;
177
+ this.curpos++;
178
+ return bit;
179
+ };
180
+
181
+ ShortyRaw.prototype.readByte = function () {
182
+ res = 0;
183
+
184
+ for (var i = 0; i < 8; i++) {
185
+ res += (128 >> i) * this.readBit();
186
+ }
187
+
188
+ return String.fromCharCode(res);
189
+ };
190
+
191
+ ShortyRaw.prototype.deflate = function (data) {
192
+ var token,
193
+ l = data.length,
194
+ i,
195
+ x;
196
+ this.reset();
197
+
198
+ for (i = 0; i < l; i++) {
199
+ token = data[i];
200
+
201
+ if (this.tokensize > 1) {
202
+ if (/[a-zA-Z]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[a-zA-Z]/.test(data[i + 1])) {
203
+ token += data[++i];
204
+ } else if (/[=\[\],\.:\"'\{\}]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[=\[\],\.:\"'\{\}]/.test(data[i + 1])) {
205
+ i++;
206
+ token += data[i];
207
+ } //joe hl patch "
208
+ }
209
+
210
+ x = this.findNode(token);
211
+
212
+ if (!x) {
213
+ this.emitNyt(token);
214
+ x = this.addNode(token);
215
+ } else {
216
+ this.emitNode(x);
217
+ this.balanceNode(x);
218
+ }
219
+ }
220
+
221
+ if (this.bitCount != 7) {
222
+ var oldlength = this.data.length;
223
+ this.emitNode(this.nyt);
224
+ if (oldlength == this.data.length) this.emitByte(0);
225
+ }
226
+
227
+ return this.data;
228
+ };
229
+
230
+ ShortyRaw.prototype.inflate = function (data) {
231
+ this.reset();
232
+ this.data = data;
233
+ var output = '';
234
+
235
+ try {
236
+ for (var i = 0; i >= 0; i++) {
237
+ var token = this.readNode();
238
+ output += token;
239
+ var node = this.findNode(token);
240
+ if (!node) this.addNode(token);else this.balanceNode(node);
241
+ }
242
+ } catch (e) {}
243
+
244
+ return output;
245
+ };
246
+
247
+ var Shorty = /*#__PURE__*/function (_ShortyRaw) {
248
+ (0, _inheritsLoose2.default)(Shorty, _ShortyRaw);
249
+
250
+ function Shorty() {
251
+ return _ShortyRaw.apply(this, arguments) || this;
252
+ }
253
+
254
+ var _proto = Shorty.prototype;
255
+
256
+ _proto.encode = function encode(data) {
257
+ return this.inflate(data);
258
+ };
259
+
260
+ _proto.decode = function decode(data) {
261
+ return this.deflate(data);
262
+ };
263
+
264
+ return Shorty;
265
+ }(ShortyRaw);
266
+
267
+ exports.Shorty = Shorty;
@@ -0,0 +1,3 @@
1
+ export declare class XServerClientHelper {
2
+ static processResponse<T>(data: any): T;
3
+ }
@@ -0,0 +1,23 @@
1
+ import { DataPacker } from 'vtils';
2
+ import { Shorty } from "./utils/shorty";
3
+ export var XServerClientHelper = /*#__PURE__*/function () {
4
+ function XServerClientHelper() {}
5
+
6
+ XServerClientHelper.processResponse = function processResponse(data) {
7
+ // 处理混淆
8
+ // _#
9
+ var shortyKey = String.fromCharCode(95) + String.fromCharCode(35);
10
+
11
+ if (data && typeof data === 'object' && data[shortyKey] != null) {
12
+ try {
13
+ data = JSON.parse(new Shorty().decode(data[shortyKey]));
14
+ } catch (_unused) {}
15
+ } // 处理数组打包
16
+
17
+
18
+ data = DataPacker.unpackIfNeeded(data);
19
+ return data;
20
+ };
21
+
22
+ return XServerClientHelper;
23
+ }();
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@jayfong/x-server-client-helper",
3
+ "version": "1.30.0",
4
+ "license": "ISC",
5
+ "sideEffects": false,
6
+ "main": "_cjs/client_helper.js",
7
+ "module": "client_helper.js",
8
+ "types": "client_helper.d.ts",
9
+ "dependencies": {
10
+ "vtils": "^4.60.0"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ }
15
+ }
@@ -0,0 +1,6 @@
1
+ declare function ShortyRaw(tokensize: any): void;
2
+ export declare class Shorty extends ShortyRaw {
3
+ encode(data: string): string;
4
+ decode(data: string): string;
5
+ }
6
+ export {};
@@ -0,0 +1,258 @@
1
+ import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
2
+
3
+ /* eslint-disable */
4
+ // @ts-nocheck
5
+ // https://github.com/enkimute/shorty.js
6
+ function ShortyRaw(tokensize) {
7
+ this.tokensize = tokensize || 10;
8
+ this.reset(true);
9
+ }
10
+
11
+ ShortyRaw.prototype.reset = function (full) {
12
+ if (full === true) {
13
+ this.nodes = [{
14
+ up: 0,
15
+ weight: 0
16
+ }];
17
+ this.nyt = 0;
18
+ this.nodecount = 0;
19
+ }
20
+
21
+ this.data = '';
22
+ this.curpos = 0;
23
+ this.bitCount = 7;
24
+ this.bitChar = 0;
25
+ };
26
+
27
+ ShortyRaw.prototype.findNode = function (x) {
28
+ for (var i = this.nodes.length - 1; i > 0; i--) {
29
+ if (typeof this.nodes[i].symbol != 'undefined' && this.nodes[i].symbol == x) return i;
30
+ }
31
+
32
+ return 0;
33
+ };
34
+
35
+ ShortyRaw.prototype.addNode = function (token) {
36
+ if (this.nodecount >= 2046) return 0;
37
+ this.nodes[++this.nodecount] = {
38
+ up: this.nyt,
39
+ symbol: token,
40
+ weight: 1
41
+ };
42
+ this.nodes[++this.nodecount] = {
43
+ up: this.nyt,
44
+ weight: 0
45
+ };
46
+ this.nodes[this.nyt].weight += 1;
47
+ this.nyt = this.nodecount;
48
+ if (this.nodes[this.nodecount - 2].up != this.nodecount - 2) this.balanceNode(this.nodes[this.nodecount - 2].up);
49
+ return this.nodecount - 2;
50
+ };
51
+
52
+ ShortyRaw.prototype.swapNode = function (a, b) {
53
+ var t = this.nodes[a].symbol;
54
+ var u = this.nodes[b].symbol;
55
+ var v = this.nodes[a].weight;
56
+ this.nodes[a].symbol = u;
57
+ this.nodes[b].symbol = t;
58
+ this.nodes[a].weight = this.nodes[b].weight;
59
+ this.nodes[b].weight = v;
60
+
61
+ for (var n = this.nodes.length - 1; n > 0; n--) {
62
+ if (this.nodes[n].up == a) this.nodes[n].up = b;else if (this.nodes[n].up == b) this.nodes[n].up = a;
63
+ }
64
+ };
65
+
66
+ ShortyRaw.prototype.balanceNode = function (node) {
67
+ while (true) {
68
+ var minnr = node;
69
+ var weight = this.nodes[node].weight;
70
+
71
+ while (minnr > 1 && this.nodes[minnr - 1].weight == weight) {
72
+ minnr--;
73
+ }
74
+
75
+ if (minnr != node && minnr != this.nodes[node].up) {
76
+ this.swapNode(minnr, node);
77
+ node = minnr;
78
+ }
79
+
80
+ this.nodes[node].weight++;
81
+ if (this.nodes[node].up == node) return;
82
+ node = this.nodes[node].up;
83
+ }
84
+ };
85
+
86
+ ShortyRaw.prototype.emitNode = function (node) {
87
+ var emit = [];
88
+
89
+ while (node != 0) {
90
+ emit.unshift(node % 2);
91
+ node = this.nodes[node].up;
92
+ }
93
+
94
+ for (var e = 0; e < emit.length; e++) {
95
+ this.emitBit(emit[e]);
96
+ }
97
+ };
98
+
99
+ ShortyRaw.prototype.emitNyt = function (token) {
100
+ this.emitNode(this.nyt);
101
+ var ll = token.length - 1;
102
+ if (this.tokensize > 8) this.emitBit(ll & 8);
103
+ if (this.tokensize > 4) this.emitBit(ll & 4);
104
+ if (this.tokensize > 2) this.emitBit(ll & 2);
105
+ if (this.tokensize > 1) this.emitBit(ll & 1);
106
+
107
+ for (var cc = 0; cc < token.length; cc++) {
108
+ this.emitByte(token.charCodeAt(cc));
109
+ }
110
+
111
+ return this.nyt;
112
+ };
113
+
114
+ ShortyRaw.prototype.readNode = function () {
115
+ if (this.nyt == 0) {
116
+ var len = (this.tokensize > 8 ? this.readBit() * 8 : 0) + (this.tokensize > 4 ? this.readBit() * 4 : 0) + (this.tokensize > 2 ? this.readBit() * 2 : 0) + (this.tokensize > 1 ? this.readBit() : 0) + 1;
117
+ var stream = '';
118
+
119
+ while (len--) {
120
+ stream += this.readByte();
121
+ }
122
+
123
+ return stream;
124
+ }
125
+
126
+ var node = 0;
127
+
128
+ while (true) {
129
+ var bit = this.readBit();
130
+ if (this.nodes[node].symbol == undefined) for (var m = 0;; m++) {
131
+ if (this.nodes[m].up == node && m != node && m % 2 == bit) {
132
+ node = m;
133
+ break;
134
+ }
135
+ }
136
+
137
+ if (this.nodes[node].symbol != undefined || this.nodes[node].weight == 0) {
138
+ if (this.nodes[node].weight) return this.nodes[node].symbol;
139
+ var len = (this.tokensize > 8 ? this.readBit() * 8 : 0) + (this.tokensize > 4 ? this.readBit() * 4 : 0) + (this.tokensize > 2 ? this.readBit() * 2 : 0) + (this.tokensize > 1 ? this.readBit() : 0) + 1;
140
+ var stream = '';
141
+
142
+ while (len--) {
143
+ stream += this.readByte();
144
+ }
145
+
146
+ return stream;
147
+ }
148
+ }
149
+ };
150
+
151
+ ShortyRaw.prototype.emitBit = function (bit) {
152
+ if (bit) this.bitChar += 1 << this.bitCount;
153
+
154
+ if (--this.bitCount < 0) {
155
+ this.data += String.fromCharCode(this.bitChar);
156
+ this.bitCount = 7;
157
+ this.bitChar = 0;
158
+ }
159
+ };
160
+
161
+ ShortyRaw.prototype.emitByte = function (_byte) {
162
+ for (var i = 7; i >= 0; i--) {
163
+ this.emitBit(_byte >> i & 1);
164
+ }
165
+ };
166
+
167
+ ShortyRaw.prototype.readBit = function () {
168
+ if (this.curpos == this.data.length * 8) throw 'done';
169
+ var bit = this.data.charCodeAt(this.curpos >> 3) >> (7 - this.curpos & 7) & 1;
170
+ this.curpos++;
171
+ return bit;
172
+ };
173
+
174
+ ShortyRaw.prototype.readByte = function () {
175
+ res = 0;
176
+
177
+ for (var i = 0; i < 8; i++) {
178
+ res += (128 >> i) * this.readBit();
179
+ }
180
+
181
+ return String.fromCharCode(res);
182
+ };
183
+
184
+ ShortyRaw.prototype.deflate = function (data) {
185
+ var token,
186
+ l = data.length,
187
+ i,
188
+ x;
189
+ this.reset();
190
+
191
+ for (i = 0; i < l; i++) {
192
+ token = data[i];
193
+
194
+ if (this.tokensize > 1) {
195
+ if (/[a-zA-Z]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[a-zA-Z]/.test(data[i + 1])) {
196
+ token += data[++i];
197
+ } else if (/[=\[\],\.:\"'\{\}]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[=\[\],\.:\"'\{\}]/.test(data[i + 1])) {
198
+ i++;
199
+ token += data[i];
200
+ } //joe hl patch "
201
+ }
202
+
203
+ x = this.findNode(token);
204
+
205
+ if (!x) {
206
+ this.emitNyt(token);
207
+ x = this.addNode(token);
208
+ } else {
209
+ this.emitNode(x);
210
+ this.balanceNode(x);
211
+ }
212
+ }
213
+
214
+ if (this.bitCount != 7) {
215
+ var oldlength = this.data.length;
216
+ this.emitNode(this.nyt);
217
+ if (oldlength == this.data.length) this.emitByte(0);
218
+ }
219
+
220
+ return this.data;
221
+ };
222
+
223
+ ShortyRaw.prototype.inflate = function (data) {
224
+ this.reset();
225
+ this.data = data;
226
+ var output = '';
227
+
228
+ try {
229
+ for (var i = 0; i >= 0; i++) {
230
+ var token = this.readNode();
231
+ output += token;
232
+ var node = this.findNode(token);
233
+ if (!node) this.addNode(token);else this.balanceNode(node);
234
+ }
235
+ } catch (e) {}
236
+
237
+ return output;
238
+ };
239
+
240
+ export var Shorty = /*#__PURE__*/function (_ShortyRaw) {
241
+ _inheritsLoose(Shorty, _ShortyRaw);
242
+
243
+ function Shorty() {
244
+ return _ShortyRaw.apply(this, arguments) || this;
245
+ }
246
+
247
+ var _proto = Shorty.prototype;
248
+
249
+ _proto.encode = function encode(data) {
250
+ return this.inflate(data);
251
+ };
252
+
253
+ _proto.decode = function decode(data) {
254
+ return this.deflate(data);
255
+ };
256
+
257
+ return Shorty;
258
+ }(ShortyRaw);