@jayfong/x-server 1.30.0 → 1.31.1
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.
- package/CHANGELOG.md +23 -0
- package/lib/_cjs/cli/templates/crons.ts +2 -0
- package/lib/_cjs/client_helper.js +17 -20
- package/lib/_cjs/core/define_cron.js +14 -0
- package/lib/_cjs/core/define_task.js +0 -9
- package/lib/_cjs/core/handler.js +5 -3
- package/lib/_cjs/core/server.js +3 -3
- package/lib/_cjs/core/types.js +7 -2
- package/lib/_cjs/index.js +8 -0
- package/lib/cli/templates/crons.ts +2 -0
- package/lib/client_helper.d.ts +1 -3
- package/lib/client_helper.js +12 -16
- package/lib/core/define_cron.d.ts +2 -0
- package/lib/core/define_cron.js +8 -0
- package/lib/core/define_task.js +0 -9
- package/lib/core/handler.js +2 -2
- package/lib/core/server.d.ts +1 -1
- package/lib/core/server.js +3 -3
- package/lib/core/types.d.ts +18 -0
- package/lib/core/types.js +5 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/package.json +5 -1
- package/lib/_cjs/cli/templates/tasks.ts +0 -1
- package/lib/_cjs/utils/shorty.js +0 -236
- package/lib/cli/templates/tasks.ts +0 -1
- package/lib/utils/shorty.d.ts +0 -6
- package/lib/utils/shorty.js +0 -229
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.31.1](https://github.com/jfWorks/x-server/compare/v1.31.0...v1.31.1) (2022-05-30)
|
|
6
|
+
|
|
7
|
+
## [1.31.0](https://github.com/jfWorks/x-server/compare/v1.30.2...v1.31.0) (2022-05-30)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* defineCron ([f9f362e](https://github.com/jfWorks/x-server/commit/f9f362ee0a9845f662af0b686781299390c5647d))
|
|
13
|
+
|
|
14
|
+
### [1.30.2](https://github.com/jfWorks/x-server/compare/v1.30.1...v1.30.2) (2022-05-26)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* use lz-string ([bf0e9af](https://github.com/jfWorks/x-server/commit/bf0e9af411c86ebd2b6527fc75be1476559c25fa))
|
|
20
|
+
|
|
21
|
+
### [1.30.1](https://github.com/jfWorks/x-server/compare/v1.30.0...v1.30.1) (2022-05-26)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* deflate <-> inflate ([e7c5f63](https://github.com/jfWorks/x-server/commit/e7c5f631a6a5165bbecf20b5b5923bbef4b6db1e))
|
|
27
|
+
|
|
5
28
|
## [1.30.0](https://github.com/jfWorks/x-server/compare/v1.29.0...v1.30.0) (2022-05-26)
|
|
6
29
|
|
|
7
30
|
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
exports.XServerClientHelper = void 0;
|
|
5
|
-
|
|
6
|
-
var _vtils = require("vtils");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.processXServerResponse = processXServerResponse;
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
static processResponse(data) {
|
|
12
|
-
// 处理混淆
|
|
13
|
-
// _#
|
|
14
|
-
const shortyKey = String.fromCharCode(95) + String.fromCharCode(35);
|
|
8
|
+
var _lzString = _interopRequireDefault(require("lz-string"));
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
data = JSON.parse(new _shorty.Shorty().decode(data[shortyKey]));
|
|
19
|
-
} catch {}
|
|
20
|
-
} // 处理数组打包
|
|
10
|
+
var _vtils = require("vtils");
|
|
21
11
|
|
|
12
|
+
// _#
|
|
13
|
+
const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
|
|
22
14
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
function processXServerResponse(data) {
|
|
16
|
+
// 处理混淆
|
|
17
|
+
if (data && typeof data === 'object' && data[obfuscateKey] != null) {
|
|
18
|
+
try {
|
|
19
|
+
data = JSON.parse(_lzString.default.decompress(data[obfuscateKey]));
|
|
20
|
+
} catch {}
|
|
21
|
+
} // 处理数组打包
|
|
26
22
|
|
|
27
|
-
}
|
|
28
23
|
|
|
29
|
-
|
|
24
|
+
data = _vtils.DataPacker.unpackIfNeeded(data);
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.defineCron = defineCron;
|
|
5
|
+
|
|
6
|
+
var _cron = require("cron");
|
|
7
|
+
|
|
8
|
+
function defineCron(options) {
|
|
9
|
+
return new _cron.CronJob({
|
|
10
|
+
cronTime: options.expression,
|
|
11
|
+
runOnInit: true,
|
|
12
|
+
onTick: options.handle
|
|
13
|
+
});
|
|
14
|
+
}
|
package/lib/_cjs/core/handler.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
3
5
|
exports.__esModule = true;
|
|
4
6
|
exports.Handler = void 0;
|
|
5
7
|
|
|
8
|
+
var _lzString = _interopRequireDefault(require("lz-string"));
|
|
9
|
+
|
|
6
10
|
var _vtils = require("vtils");
|
|
7
11
|
|
|
8
12
|
var _dispose = require("../services/dispose");
|
|
9
13
|
|
|
10
14
|
var _http_error = require("../core/http_error");
|
|
11
15
|
|
|
12
|
-
var _shorty = require("../utils/shorty");
|
|
13
|
-
|
|
14
16
|
var _validator = require("vtils/validator");
|
|
15
17
|
|
|
16
18
|
class Handler {
|
|
@@ -59,7 +61,7 @@ class Handler {
|
|
|
59
61
|
|
|
60
62
|
if (this.options.responseDataObfuscate) {
|
|
61
63
|
res = {
|
|
62
|
-
'_#':
|
|
64
|
+
'_#': _lzString.default.compress(JSON.stringify(res))
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
67
|
|
package/lib/_cjs/core/server.js
CHANGED
|
@@ -31,7 +31,7 @@ class Server {
|
|
|
31
31
|
await this.applyRoutes();
|
|
32
32
|
await this.applyHooks();
|
|
33
33
|
await this.startFastify();
|
|
34
|
-
await this.
|
|
34
|
+
await this.startCrons();
|
|
35
35
|
await this.applyAutoClose();
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -145,9 +145,9 @@ class Server {
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
async
|
|
148
|
+
async startCrons() {
|
|
149
149
|
// @ts-ignore
|
|
150
|
-
await Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('.x/
|
|
150
|
+
await Promise.resolve().then(() => (0, _interopRequireWildcard2.default)(require('.x/crons')));
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
async applyAutoClose() {
|
package/lib/_cjs/core/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.XTask = exports.XServer = exports.XHandler = void 0;
|
|
4
|
+
exports.XTask = exports.XServer = exports.XHandler = exports.XCron = void 0;
|
|
5
5
|
let XServer;
|
|
6
6
|
exports.XServer = XServer;
|
|
7
7
|
|
|
@@ -15,4 +15,9 @@ exports.XHandler = XHandler;
|
|
|
15
15
|
let XTask;
|
|
16
16
|
exports.XTask = XTask;
|
|
17
17
|
|
|
18
|
-
(function (_XTask) {})(XTask || (exports.XTask = XTask = {}));
|
|
18
|
+
(function (_XTask) {})(XTask || (exports.XTask = XTask = {}));
|
|
19
|
+
|
|
20
|
+
let XCron;
|
|
21
|
+
exports.XCron = XCron;
|
|
22
|
+
|
|
23
|
+
(function (_XCron) {})(XCron || (exports.XCron = XCron = {}));
|
package/lib/_cjs/index.js
CHANGED
|
@@ -10,6 +10,14 @@ Object.keys(_define_bus).forEach(function (key) {
|
|
|
10
10
|
exports[key] = _define_bus[key];
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
var _define_cron = require("./core/define_cron");
|
|
14
|
+
|
|
15
|
+
Object.keys(_define_cron).forEach(function (key) {
|
|
16
|
+
if (key === "default" || key === "__esModule") return;
|
|
17
|
+
if (key in exports && exports[key] === _define_cron[key]) return;
|
|
18
|
+
exports[key] = _define_cron[key];
|
|
19
|
+
});
|
|
20
|
+
|
|
13
21
|
var _define_handler = require("./core/define_handler");
|
|
14
22
|
|
|
15
23
|
Object.keys(_define_handler).forEach(function (key) {
|
package/lib/client_helper.d.ts
CHANGED
package/lib/client_helper.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export class XServerClientHelper {
|
|
4
|
-
static processResponse(data) {
|
|
5
|
-
// 处理混淆
|
|
6
|
-
// _#
|
|
7
|
-
const shortyKey = String.fromCharCode(95) + String.fromCharCode(35);
|
|
1
|
+
import LZString from 'lz-string';
|
|
2
|
+
import { DataPacker } from 'vtils'; // _#
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
const obfuscateKey = [90, 30].map(v => String.fromCharCode(v + 5)).join('');
|
|
5
|
+
export function processXServerResponse(data) {
|
|
6
|
+
// 处理混淆
|
|
7
|
+
if (data && typeof data === 'object' && data[obfuscateKey] != null) {
|
|
8
|
+
try {
|
|
9
|
+
data = JSON.parse(LZString.decompress(data[obfuscateKey]));
|
|
10
|
+
} catch {}
|
|
11
|
+
} // 处理数组打包
|
|
14
12
|
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
14
|
+
data = DataPacker.unpackIfNeeded(data);
|
|
15
|
+
return data;
|
|
20
16
|
}
|
package/lib/core/define_task.js
CHANGED
package/lib/core/handler.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import LZString from 'lz-string';
|
|
1
2
|
import { DataPacker } from 'vtils';
|
|
2
3
|
import { DisposeService } from "../services/dispose";
|
|
3
4
|
import { HttpError } from "../core/http_error";
|
|
4
|
-
import { Shorty } from "../utils/shorty";
|
|
5
5
|
import { yup } from 'vtils/validator';
|
|
6
6
|
export class Handler {
|
|
7
7
|
constructor(options) {
|
|
@@ -49,7 +49,7 @@ export class Handler {
|
|
|
49
49
|
|
|
50
50
|
if (this.options.responseDataObfuscate) {
|
|
51
51
|
res = {
|
|
52
|
-
'_#':
|
|
52
|
+
'_#': LZString.compress(JSON.stringify(res))
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
package/lib/core/server.d.ts
CHANGED
package/lib/core/server.js
CHANGED
|
@@ -18,7 +18,7 @@ export class Server {
|
|
|
18
18
|
await this.applyRoutes();
|
|
19
19
|
await this.applyHooks();
|
|
20
20
|
await this.startFastify();
|
|
21
|
-
await this.
|
|
21
|
+
await this.startCrons();
|
|
22
22
|
await this.applyAutoClose();
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -130,9 +130,9 @@ export class Server {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
async
|
|
133
|
+
async startCrons() {
|
|
134
134
|
// @ts-ignore
|
|
135
|
-
await import('.x/
|
|
135
|
+
await import('.x/crons');
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
async applyAutoClose() {
|
package/lib/core/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BasePlugin } from '../plugins/base';
|
|
3
3
|
import { BaseService } from '../services/base';
|
|
4
|
+
import { CronJob } from 'cron';
|
|
4
5
|
import { FastifyReply, FastifyRequest, FastifyServerOptions } from 'fastify';
|
|
5
6
|
import { yup } from 'vtils/validator';
|
|
6
7
|
import type { AsyncOrSync, LiteralUnion, OneOrMore, RequiredDeep } from 'vtils/types';
|
|
@@ -152,4 +153,21 @@ export declare namespace XTask {
|
|
|
152
153
|
interface Task<T> extends Queue<T> {
|
|
153
154
|
}
|
|
154
155
|
}
|
|
156
|
+
export declare namespace XCron {
|
|
157
|
+
interface Options {
|
|
158
|
+
/**
|
|
159
|
+
* 定时语法
|
|
160
|
+
*
|
|
161
|
+
* @see https://crontab.guru/
|
|
162
|
+
* @see https://crontab.cronhub.io/
|
|
163
|
+
*/
|
|
164
|
+
expression: string;
|
|
165
|
+
/**
|
|
166
|
+
* 处理器
|
|
167
|
+
*/
|
|
168
|
+
handle: () => any;
|
|
169
|
+
}
|
|
170
|
+
interface Cron extends CronJob {
|
|
171
|
+
}
|
|
172
|
+
}
|
|
155
173
|
export declare type XFile = MultipartFile;
|
package/lib/core/types.js
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// @index(['./**/*.ts', '!**/*.test.ts', '!./cli/**'], f => `export * from '${f.path}'`)
|
|
1
|
+
// @index(['./**/*.ts', '!**/*.test.ts', '!./cli/**', '!./client_helper.ts'], f => `export * from '${f.path}'`)
|
|
2
2
|
export * from "./core/define_bus";
|
|
3
|
+
export * from "./core/define_cron";
|
|
3
4
|
export * from "./core/define_handler";
|
|
4
5
|
export * from "./core/define_hook";
|
|
5
6
|
export * from "./core/define_server";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@prisma/client": "^3.12.0",
|
|
31
31
|
"@types/bull": "^3.15.8",
|
|
32
32
|
"@types/busboy": "^0.3.2",
|
|
33
|
+
"@types/cron": "^2.0.0",
|
|
33
34
|
"@types/http-errors": "^1.8.2",
|
|
34
35
|
"@types/jsonwebtoken": "^8.5.8",
|
|
35
36
|
"@types/nodemailer": "^6.4.4",
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"chokidar": "^3.5.3",
|
|
41
42
|
"comment-parser": "^1.3.1",
|
|
42
43
|
"compressing": "^1.5.1",
|
|
44
|
+
"cron": "^2.0.0",
|
|
43
45
|
"cuid": "^2.1.8",
|
|
44
46
|
"debug": "^4.3.4",
|
|
45
47
|
"esbuild": "^0.14.36",
|
|
@@ -56,6 +58,7 @@
|
|
|
56
58
|
"http-errors": "^1.8.1",
|
|
57
59
|
"ioredis": "^4.28.5",
|
|
58
60
|
"jsonwebtoken": "^8.5.1",
|
|
61
|
+
"lz-string": "^1.4.4",
|
|
59
62
|
"mini-svg-data-uri": "^1.4.4",
|
|
60
63
|
"mint-filter": "^3.0.1",
|
|
61
64
|
"node-ssh": "^12.0.4",
|
|
@@ -76,6 +79,7 @@
|
|
|
76
79
|
"@types/fs-extra": "^9.0.13",
|
|
77
80
|
"@types/ioredis": "^4.28.10",
|
|
78
81
|
"@types/json-schema": "^7.0.11",
|
|
82
|
+
"@types/lz-string": "^1.3.34",
|
|
79
83
|
"eslint": "^7.32.0",
|
|
80
84
|
"haoma": "^3.6.4",
|
|
81
85
|
"husky": "^4.3.8",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../../src/tasks/index'
|
package/lib/_cjs/utils/shorty.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.Shorty = void 0;
|
|
5
|
-
|
|
6
|
-
/* eslint-disable */
|
|
7
|
-
// @ts-nocheck
|
|
8
|
-
// https://github.com/enkimute/shorty.js
|
|
9
|
-
function ShortyRaw(tokensize) {
|
|
10
|
-
this.tokensize = tokensize || 10;
|
|
11
|
-
this.reset(true);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
ShortyRaw.prototype.reset = function (full) {
|
|
15
|
-
if (full === true) {
|
|
16
|
-
this.nodes = [{
|
|
17
|
-
up: 0,
|
|
18
|
-
weight: 0
|
|
19
|
-
}];
|
|
20
|
-
this.nyt = 0;
|
|
21
|
-
this.nodecount = 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.data = '';
|
|
25
|
-
this.curpos = 0;
|
|
26
|
-
this.bitCount = 7;
|
|
27
|
-
this.bitChar = 0;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
ShortyRaw.prototype.findNode = function (x) {
|
|
31
|
-
for (let i = this.nodes.length - 1; i > 0; i--) if (typeof this.nodes[i].symbol != 'undefined' && this.nodes[i].symbol == x) return i;
|
|
32
|
-
|
|
33
|
-
return 0;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
ShortyRaw.prototype.addNode = function (token) {
|
|
37
|
-
if (this.nodecount >= 2046) return 0;
|
|
38
|
-
this.nodes[++this.nodecount] = {
|
|
39
|
-
up: this.nyt,
|
|
40
|
-
symbol: token,
|
|
41
|
-
weight: 1
|
|
42
|
-
};
|
|
43
|
-
this.nodes[++this.nodecount] = {
|
|
44
|
-
up: this.nyt,
|
|
45
|
-
weight: 0
|
|
46
|
-
};
|
|
47
|
-
this.nodes[this.nyt].weight += 1;
|
|
48
|
-
this.nyt = this.nodecount;
|
|
49
|
-
if (this.nodes[this.nodecount - 2].up != this.nodecount - 2) this.balanceNode(this.nodes[this.nodecount - 2].up);
|
|
50
|
-
return this.nodecount - 2;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
ShortyRaw.prototype.swapNode = function (a, b) {
|
|
54
|
-
const t = this.nodes[a].symbol;
|
|
55
|
-
const u = this.nodes[b].symbol;
|
|
56
|
-
const v = this.nodes[a].weight;
|
|
57
|
-
this.nodes[a].symbol = u;
|
|
58
|
-
this.nodes[b].symbol = t;
|
|
59
|
-
this.nodes[a].weight = this.nodes[b].weight;
|
|
60
|
-
this.nodes[b].weight = v;
|
|
61
|
-
|
|
62
|
-
for (let n = this.nodes.length - 1; n > 0; n--) 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
|
-
ShortyRaw.prototype.balanceNode = function (node) {
|
|
66
|
-
while (true) {
|
|
67
|
-
let minnr = node;
|
|
68
|
-
const weight = this.nodes[node].weight;
|
|
69
|
-
|
|
70
|
-
while (minnr > 1 && this.nodes[minnr - 1].weight == weight) minnr--;
|
|
71
|
-
|
|
72
|
-
if (minnr != node && minnr != this.nodes[node].up) {
|
|
73
|
-
this.swapNode(minnr, node);
|
|
74
|
-
node = minnr;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
this.nodes[node].weight++;
|
|
78
|
-
if (this.nodes[node].up == node) return;
|
|
79
|
-
node = this.nodes[node].up;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
ShortyRaw.prototype.emitNode = function (node) {
|
|
84
|
-
const emit = [];
|
|
85
|
-
|
|
86
|
-
while (node != 0) {
|
|
87
|
-
emit.unshift(node % 2);
|
|
88
|
-
node = this.nodes[node].up;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
for (let e = 0; e < emit.length; e++) this.emitBit(emit[e]);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
ShortyRaw.prototype.emitNyt = function (token) {
|
|
95
|
-
this.emitNode(this.nyt);
|
|
96
|
-
const ll = token.length - 1;
|
|
97
|
-
if (this.tokensize > 8) this.emitBit(ll & 8);
|
|
98
|
-
if (this.tokensize > 4) this.emitBit(ll & 4);
|
|
99
|
-
if (this.tokensize > 2) this.emitBit(ll & 2);
|
|
100
|
-
if (this.tokensize > 1) this.emitBit(ll & 1);
|
|
101
|
-
|
|
102
|
-
for (let cc = 0; cc < token.length; cc++) this.emitByte(token.charCodeAt(cc));
|
|
103
|
-
|
|
104
|
-
return this.nyt;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
ShortyRaw.prototype.readNode = function () {
|
|
108
|
-
if (this.nyt == 0) {
|
|
109
|
-
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;
|
|
110
|
-
var stream = '';
|
|
111
|
-
|
|
112
|
-
while (len--) stream += this.readByte();
|
|
113
|
-
|
|
114
|
-
return stream;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
let node = 0;
|
|
118
|
-
|
|
119
|
-
while (true) {
|
|
120
|
-
const bit = this.readBit();
|
|
121
|
-
if (this.nodes[node].symbol == undefined) for (let m = 0;; m++) if (this.nodes[m].up == node && m != node && m % 2 == bit) {
|
|
122
|
-
node = m;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (this.nodes[node].symbol != undefined || this.nodes[node].weight == 0) {
|
|
127
|
-
if (this.nodes[node].weight) return this.nodes[node].symbol;
|
|
128
|
-
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;
|
|
129
|
-
var stream = '';
|
|
130
|
-
|
|
131
|
-
while (len--) stream += this.readByte();
|
|
132
|
-
|
|
133
|
-
return stream;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
ShortyRaw.prototype.emitBit = function (bit) {
|
|
139
|
-
if (bit) this.bitChar += 1 << this.bitCount;
|
|
140
|
-
|
|
141
|
-
if (--this.bitCount < 0) {
|
|
142
|
-
this.data += String.fromCharCode(this.bitChar);
|
|
143
|
-
this.bitCount = 7;
|
|
144
|
-
this.bitChar = 0;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
ShortyRaw.prototype.emitByte = function (byte) {
|
|
149
|
-
for (let i = 7; i >= 0; i--) {
|
|
150
|
-
this.emitBit(byte >> i & 1);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
ShortyRaw.prototype.readBit = function () {
|
|
155
|
-
if (this.curpos == this.data.length * 8) throw 'done';
|
|
156
|
-
const bit = this.data.charCodeAt(this.curpos >> 3) >> (7 - this.curpos & 7) & 1;
|
|
157
|
-
this.curpos++;
|
|
158
|
-
return bit;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
ShortyRaw.prototype.readByte = function () {
|
|
162
|
-
res = 0;
|
|
163
|
-
|
|
164
|
-
for (let i = 0; i < 8; i++) res += (128 >> i) * this.readBit();
|
|
165
|
-
|
|
166
|
-
return String.fromCharCode(res);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
ShortyRaw.prototype.deflate = function (data) {
|
|
170
|
-
let token,
|
|
171
|
-
l = data.length,
|
|
172
|
-
i,
|
|
173
|
-
x;
|
|
174
|
-
this.reset();
|
|
175
|
-
|
|
176
|
-
for (i = 0; i < l; i++) {
|
|
177
|
-
token = data[i];
|
|
178
|
-
|
|
179
|
-
if (this.tokensize > 1) {
|
|
180
|
-
if (/[a-zA-Z]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[a-zA-Z]/.test(data[i + 1])) {
|
|
181
|
-
token += data[++i];
|
|
182
|
-
} else if (/[=\[\],\.:\"'\{\}]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[=\[\],\.:\"'\{\}]/.test(data[i + 1])) {
|
|
183
|
-
i++;
|
|
184
|
-
token += data[i];
|
|
185
|
-
} //joe hl patch "
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
x = this.findNode(token);
|
|
189
|
-
|
|
190
|
-
if (!x) {
|
|
191
|
-
this.emitNyt(token);
|
|
192
|
-
x = this.addNode(token);
|
|
193
|
-
} else {
|
|
194
|
-
this.emitNode(x);
|
|
195
|
-
this.balanceNode(x);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (this.bitCount != 7) {
|
|
200
|
-
const oldlength = this.data.length;
|
|
201
|
-
this.emitNode(this.nyt);
|
|
202
|
-
if (oldlength == this.data.length) this.emitByte(0);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return this.data;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
ShortyRaw.prototype.inflate = function (data) {
|
|
209
|
-
this.reset();
|
|
210
|
-
this.data = data;
|
|
211
|
-
let output = '';
|
|
212
|
-
|
|
213
|
-
try {
|
|
214
|
-
for (let i = 0; i >= 0; i++) {
|
|
215
|
-
const token = this.readNode();
|
|
216
|
-
output += token;
|
|
217
|
-
const node = this.findNode(token);
|
|
218
|
-
if (!node) this.addNode(token);else this.balanceNode(node);
|
|
219
|
-
}
|
|
220
|
-
} catch (e) {}
|
|
221
|
-
|
|
222
|
-
return output;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
class Shorty extends ShortyRaw {
|
|
226
|
-
encode(data) {
|
|
227
|
-
return this.inflate(data);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
decode(data) {
|
|
231
|
-
return this.deflate(data);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
exports.Shorty = Shorty;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '../../src/tasks/index'
|
package/lib/utils/shorty.d.ts
DELETED
package/lib/utils/shorty.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
// https://github.com/enkimute/shorty.js
|
|
4
|
-
function ShortyRaw(tokensize) {
|
|
5
|
-
this.tokensize = tokensize || 10;
|
|
6
|
-
this.reset(true);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
ShortyRaw.prototype.reset = function (full) {
|
|
10
|
-
if (full === true) {
|
|
11
|
-
this.nodes = [{
|
|
12
|
-
up: 0,
|
|
13
|
-
weight: 0
|
|
14
|
-
}];
|
|
15
|
-
this.nyt = 0;
|
|
16
|
-
this.nodecount = 0;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
this.data = '';
|
|
20
|
-
this.curpos = 0;
|
|
21
|
-
this.bitCount = 7;
|
|
22
|
-
this.bitChar = 0;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
ShortyRaw.prototype.findNode = function (x) {
|
|
26
|
-
for (let i = this.nodes.length - 1; i > 0; i--) if (typeof this.nodes[i].symbol != 'undefined' && this.nodes[i].symbol == x) return i;
|
|
27
|
-
|
|
28
|
-
return 0;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
ShortyRaw.prototype.addNode = function (token) {
|
|
32
|
-
if (this.nodecount >= 2046) return 0;
|
|
33
|
-
this.nodes[++this.nodecount] = {
|
|
34
|
-
up: this.nyt,
|
|
35
|
-
symbol: token,
|
|
36
|
-
weight: 1
|
|
37
|
-
};
|
|
38
|
-
this.nodes[++this.nodecount] = {
|
|
39
|
-
up: this.nyt,
|
|
40
|
-
weight: 0
|
|
41
|
-
};
|
|
42
|
-
this.nodes[this.nyt].weight += 1;
|
|
43
|
-
this.nyt = this.nodecount;
|
|
44
|
-
if (this.nodes[this.nodecount - 2].up != this.nodecount - 2) this.balanceNode(this.nodes[this.nodecount - 2].up);
|
|
45
|
-
return this.nodecount - 2;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
ShortyRaw.prototype.swapNode = function (a, b) {
|
|
49
|
-
const t = this.nodes[a].symbol;
|
|
50
|
-
const u = this.nodes[b].symbol;
|
|
51
|
-
const v = this.nodes[a].weight;
|
|
52
|
-
this.nodes[a].symbol = u;
|
|
53
|
-
this.nodes[b].symbol = t;
|
|
54
|
-
this.nodes[a].weight = this.nodes[b].weight;
|
|
55
|
-
this.nodes[b].weight = v;
|
|
56
|
-
|
|
57
|
-
for (let n = this.nodes.length - 1; n > 0; n--) if (this.nodes[n].up == a) this.nodes[n].up = b;else if (this.nodes[n].up == b) this.nodes[n].up = a;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
ShortyRaw.prototype.balanceNode = function (node) {
|
|
61
|
-
while (true) {
|
|
62
|
-
let minnr = node;
|
|
63
|
-
const weight = this.nodes[node].weight;
|
|
64
|
-
|
|
65
|
-
while (minnr > 1 && this.nodes[minnr - 1].weight == weight) minnr--;
|
|
66
|
-
|
|
67
|
-
if (minnr != node && minnr != this.nodes[node].up) {
|
|
68
|
-
this.swapNode(minnr, node);
|
|
69
|
-
node = minnr;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.nodes[node].weight++;
|
|
73
|
-
if (this.nodes[node].up == node) return;
|
|
74
|
-
node = this.nodes[node].up;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
ShortyRaw.prototype.emitNode = function (node) {
|
|
79
|
-
const emit = [];
|
|
80
|
-
|
|
81
|
-
while (node != 0) {
|
|
82
|
-
emit.unshift(node % 2);
|
|
83
|
-
node = this.nodes[node].up;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
for (let e = 0; e < emit.length; e++) this.emitBit(emit[e]);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
ShortyRaw.prototype.emitNyt = function (token) {
|
|
90
|
-
this.emitNode(this.nyt);
|
|
91
|
-
const ll = token.length - 1;
|
|
92
|
-
if (this.tokensize > 8) this.emitBit(ll & 8);
|
|
93
|
-
if (this.tokensize > 4) this.emitBit(ll & 4);
|
|
94
|
-
if (this.tokensize > 2) this.emitBit(ll & 2);
|
|
95
|
-
if (this.tokensize > 1) this.emitBit(ll & 1);
|
|
96
|
-
|
|
97
|
-
for (let cc = 0; cc < token.length; cc++) this.emitByte(token.charCodeAt(cc));
|
|
98
|
-
|
|
99
|
-
return this.nyt;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
ShortyRaw.prototype.readNode = function () {
|
|
103
|
-
if (this.nyt == 0) {
|
|
104
|
-
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;
|
|
105
|
-
var stream = '';
|
|
106
|
-
|
|
107
|
-
while (len--) stream += this.readByte();
|
|
108
|
-
|
|
109
|
-
return stream;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
let node = 0;
|
|
113
|
-
|
|
114
|
-
while (true) {
|
|
115
|
-
const bit = this.readBit();
|
|
116
|
-
if (this.nodes[node].symbol == undefined) for (let m = 0;; m++) if (this.nodes[m].up == node && m != node && m % 2 == bit) {
|
|
117
|
-
node = m;
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (this.nodes[node].symbol != undefined || this.nodes[node].weight == 0) {
|
|
122
|
-
if (this.nodes[node].weight) return this.nodes[node].symbol;
|
|
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--) stream += this.readByte();
|
|
127
|
-
|
|
128
|
-
return stream;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
ShortyRaw.prototype.emitBit = function (bit) {
|
|
134
|
-
if (bit) this.bitChar += 1 << this.bitCount;
|
|
135
|
-
|
|
136
|
-
if (--this.bitCount < 0) {
|
|
137
|
-
this.data += String.fromCharCode(this.bitChar);
|
|
138
|
-
this.bitCount = 7;
|
|
139
|
-
this.bitChar = 0;
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
ShortyRaw.prototype.emitByte = function (byte) {
|
|
144
|
-
for (let i = 7; i >= 0; i--) {
|
|
145
|
-
this.emitBit(byte >> i & 1);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
ShortyRaw.prototype.readBit = function () {
|
|
150
|
-
if (this.curpos == this.data.length * 8) throw 'done';
|
|
151
|
-
const bit = this.data.charCodeAt(this.curpos >> 3) >> (7 - this.curpos & 7) & 1;
|
|
152
|
-
this.curpos++;
|
|
153
|
-
return bit;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
ShortyRaw.prototype.readByte = function () {
|
|
157
|
-
res = 0;
|
|
158
|
-
|
|
159
|
-
for (let i = 0; i < 8; i++) res += (128 >> i) * this.readBit();
|
|
160
|
-
|
|
161
|
-
return String.fromCharCode(res);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
ShortyRaw.prototype.deflate = function (data) {
|
|
165
|
-
let token,
|
|
166
|
-
l = data.length,
|
|
167
|
-
i,
|
|
168
|
-
x;
|
|
169
|
-
this.reset();
|
|
170
|
-
|
|
171
|
-
for (i = 0; i < l; i++) {
|
|
172
|
-
token = data[i];
|
|
173
|
-
|
|
174
|
-
if (this.tokensize > 1) {
|
|
175
|
-
if (/[a-zA-Z]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[a-zA-Z]/.test(data[i + 1])) {
|
|
176
|
-
token += data[++i];
|
|
177
|
-
} else if (/[=\[\],\.:\"'\{\}]/.test(token)) while (i + 1 < l && token.length < this.tokensize && /[=\[\],\.:\"'\{\}]/.test(data[i + 1])) {
|
|
178
|
-
i++;
|
|
179
|
-
token += data[i];
|
|
180
|
-
} //joe hl patch "
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
x = this.findNode(token);
|
|
184
|
-
|
|
185
|
-
if (!x) {
|
|
186
|
-
this.emitNyt(token);
|
|
187
|
-
x = this.addNode(token);
|
|
188
|
-
} else {
|
|
189
|
-
this.emitNode(x);
|
|
190
|
-
this.balanceNode(x);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (this.bitCount != 7) {
|
|
195
|
-
const oldlength = this.data.length;
|
|
196
|
-
this.emitNode(this.nyt);
|
|
197
|
-
if (oldlength == this.data.length) this.emitByte(0);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return this.data;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
ShortyRaw.prototype.inflate = function (data) {
|
|
204
|
-
this.reset();
|
|
205
|
-
this.data = data;
|
|
206
|
-
let output = '';
|
|
207
|
-
|
|
208
|
-
try {
|
|
209
|
-
for (let i = 0; i >= 0; i++) {
|
|
210
|
-
const token = this.readNode();
|
|
211
|
-
output += token;
|
|
212
|
-
const node = this.findNode(token);
|
|
213
|
-
if (!node) this.addNode(token);else this.balanceNode(node);
|
|
214
|
-
}
|
|
215
|
-
} catch (e) {}
|
|
216
|
-
|
|
217
|
-
return output;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export class Shorty extends ShortyRaw {
|
|
221
|
-
encode(data) {
|
|
222
|
-
return this.inflate(data);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
decode(data) {
|
|
226
|
-
return this.deflate(data);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
}
|