@domain.js/main 0.7.15 → 1.0.0-alpha.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/.husky/pre-commit +1 -1
- package/.prettierignore +34 -0
- package/.prettierrc +11 -0
- package/.vscode/extensions.json +7 -0
- package/.vscode/settings.json +27 -1
- package/dist/Errors/index.d.ts +1 -1
- package/dist/Errors/index.js +1 -2
- package/dist/cfg/index.js +1 -2
- package/dist/cli/index.js +22 -8
- package/dist/defaults.d.ts +0 -30
- package/dist/defaults.js +22 -18
- package/dist/deps/aes/index.js +63 -14
- package/dist/deps/cache/index.d.ts +25 -4
- package/dist/deps/cache/index.js +33 -13
- package/dist/deps/checker/index.js +2 -2
- package/dist/deps/counter/index.js +2 -2
- package/dist/deps/cron/index.d.ts +1 -1
- package/dist/deps/cron/index.js +2 -2
- package/dist/deps/defines.d.ts +0 -2
- package/dist/deps/defines.js +38 -26
- package/dist/deps/frequency/index.js +2 -2
- package/dist/deps/graceful/index.d.ts +1 -1
- package/dist/deps/graceful/index.js +2 -2
- package/dist/deps/hash/index.js +2 -2
- package/dist/deps/logger/index.d.ts +1 -9
- package/dist/deps/logger/index.js +8 -8
- package/dist/deps/myCia/errors.d.ts +1 -1
- package/dist/deps/myCia/errors.js +22 -8
- package/dist/deps/myCia/index.d.ts +2 -10
- package/dist/deps/myCia/index.js +15 -12
- package/dist/deps/parallel/index.js +24 -10
- package/dist/deps/redis/index.js +2 -2
- package/dist/deps/rest/Before.d.ts +2 -2
- package/dist/deps/rest/Before.js +1 -2
- package/dist/deps/rest/index.d.ts +10 -18
- package/dist/deps/rest/index.js +3 -3
- package/dist/deps/rest/stats.d.ts +1 -9
- package/dist/deps/rest/stats.js +1 -2
- package/dist/deps/rest/utils.d.ts +5 -9
- package/dist/deps/rest/utils.js +26 -13
- package/dist/deps/schema/index.d.ts +2 -2
- package/dist/deps/schema/index.js +24 -10
- package/dist/deps/sequelize/index.d.ts +3 -3
- package/dist/deps/sequelize/index.js +2 -2
- package/dist/deps/signer/index.js +24 -10
- package/dist/dm/index.d.ts +1 -1
- package/dist/dm/index.js +24 -11
- package/dist/http/defines.d.ts +13 -0
- package/dist/http/index.d.ts +11 -3
- package/dist/http/index.js +53 -50
- package/dist/http/router.d.ts +20 -20
- package/dist/http/router.js +43 -97
- package/dist/http/socket.d.ts +2 -2
- package/dist/http/socket.js +1 -2
- package/dist/http/utils.d.ts +11 -7
- package/dist/http/utils.js +71 -22
- package/dist/index.d.ts +24 -10
- package/dist/index.js +28 -11
- package/dist/types/index.d.ts +2 -2
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +24 -10
- package/eslint.config.js +117 -0
- package/package.json +37 -45
- package/.eslintrc.js +0 -33
- package/dist/deps/cache/After.d.ts +0 -2
- package/dist/deps/cache/After.js +0 -29
- package/dist/deps/cache/Before.d.ts +0 -4
- package/dist/deps/cache/Before.js +0 -16
- package/dist/deps/cache/Define.d.ts +0 -30
- package/dist/deps/cache/Define.js +0 -2
- package/dist/deps/request/index.d.ts +0 -43
- package/dist/deps/request/index.js +0 -67
package/.husky/pre-commit
CHANGED
package/.prettierignore
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
dist/
|
|
4
|
+
coverage/
|
|
5
|
+
|
|
6
|
+
# Build outputs
|
|
7
|
+
*.min.js
|
|
8
|
+
*.min.css
|
|
9
|
+
|
|
10
|
+
# Lock files
|
|
11
|
+
package-lock.json
|
|
12
|
+
yarn.lock
|
|
13
|
+
pnpm-lock.yaml
|
|
14
|
+
|
|
15
|
+
# Generated files
|
|
16
|
+
*.d.ts
|
|
17
|
+
|
|
18
|
+
# Logs
|
|
19
|
+
*.log
|
|
20
|
+
|
|
21
|
+
# OS generated files
|
|
22
|
+
.DS_Store
|
|
23
|
+
Thumbs.db
|
|
24
|
+
|
|
25
|
+
# IDE files
|
|
26
|
+
.vscode/
|
|
27
|
+
.idea/
|
|
28
|
+
|
|
29
|
+
# Test coverage
|
|
30
|
+
coverage/
|
|
31
|
+
|
|
32
|
+
# Temporary files
|
|
33
|
+
*.tmp
|
|
34
|
+
*.temp
|
package/.prettierrc
ADDED
package/.vscode/settings.json
CHANGED
|
@@ -11,5 +11,31 @@
|
|
|
11
11
|
"other": true,
|
|
12
12
|
"comments": true,
|
|
13
13
|
"strings": true
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
|
+
"editor.formatOnSave": true,
|
|
16
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
17
|
+
"[typescript]": {
|
|
18
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
19
|
+
"editor.formatOnSave": true
|
|
20
|
+
},
|
|
21
|
+
"[javascript]": {
|
|
22
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
23
|
+
"editor.formatOnSave": true
|
|
24
|
+
},
|
|
25
|
+
"[json]": {
|
|
26
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
27
|
+
"editor.formatOnSave": true
|
|
28
|
+
},
|
|
29
|
+
"[jsonc]": {
|
|
30
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
31
|
+
"editor.formatOnSave": true
|
|
32
|
+
},
|
|
33
|
+
"editor.codeActionsOnSave": {
|
|
34
|
+
"source.fixAll.eslint": "explicit",
|
|
35
|
+
"source.organizeImports": "explicit"
|
|
36
|
+
},
|
|
37
|
+
"eslint.validate": [
|
|
38
|
+
"javascript",
|
|
39
|
+
"typescript"
|
|
40
|
+
]
|
|
15
41
|
}
|
package/dist/Errors/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface MyError extends Error {
|
|
|
6
6
|
export interface ErrorFn {
|
|
7
7
|
(...args: any): MyError;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
type RemoveReadonlyArray<T extends readonly any[]> = T extends readonly (infer A)[] ? A extends readonly [infer key, any] ? key : never : never;
|
|
10
10
|
/**
|
|
11
11
|
* Convert error configuration to errors function
|
|
12
12
|
* @param defines error configuration
|
package/dist/Errors/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Errors =
|
|
3
|
+
exports.Errors = Errors;
|
|
4
4
|
/**
|
|
5
5
|
* Convert error configuration to errors function
|
|
6
6
|
* @param defines error configuration
|
|
@@ -24,4 +24,3 @@ function Errors(defines) {
|
|
|
24
24
|
}
|
|
25
25
|
return errors;
|
|
26
26
|
}
|
|
27
|
-
exports.Errors = Errors;
|
package/dist/cfg/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Main =
|
|
6
|
+
exports.Main = Main;
|
|
7
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
8
8
|
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
9
9
|
const ajv_keywords_1 = __importDefault(require("ajv-keywords"));
|
|
@@ -28,4 +28,3 @@ function Main(object, schema) {
|
|
|
28
28
|
return obj[key];
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
exports.Main = Main;
|
package/dist/cli/index.js
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
6
10
|
}) : (function(o, m, k, k2) {
|
|
7
11
|
if (k2 === undefined) k2 = k;
|
|
8
12
|
o[k2] = m[k];
|
|
@@ -12,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
12
16
|
}) : function(o, v) {
|
|
13
17
|
o["default"] = v;
|
|
14
18
|
});
|
|
15
|
-
var __importStar = (this && this.__importStar) || function (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
22
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
37
|
const child_process_1 = require("child_process");
|
|
24
38
|
const fs = __importStar(require("fs"));
|
package/dist/defaults.d.ts
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
1
|
import * as ajv from "ajv";
|
|
2
2
|
import * as ajvFormats from "ajv-formats";
|
|
3
3
|
import ajvKeywords from "ajv-keywords";
|
|
4
|
-
import * as async from "async";
|
|
5
|
-
import * as axios from "axios";
|
|
6
4
|
import * as cronParser from "cron-parser";
|
|
7
5
|
import humanInterval from "human-interval";
|
|
8
6
|
import IORedis from "ioredis";
|
|
9
|
-
import _ from "lodash";
|
|
10
7
|
import LRU from "lru-cache";
|
|
11
|
-
import moment from "moment";
|
|
12
8
|
import * as mysql from "mysql2";
|
|
13
9
|
import * as Sequelize from "sequelize";
|
|
14
|
-
import * as uuid from "uuid";
|
|
15
10
|
import { errors } from "./basic-errors";
|
|
16
11
|
import * as utils from "./utils";
|
|
17
12
|
/** npm packages injection */
|
|
18
13
|
export interface Defaults {
|
|
19
|
-
/**
|
|
20
|
-
* The Lodash library exported as Node.js modules.
|
|
21
|
-
* @link https://www.npmjs.com/package/lodash
|
|
22
|
-
*/
|
|
23
|
-
_: typeof _;
|
|
24
|
-
/**
|
|
25
|
-
* For the creation of RFC4122 UUIDs
|
|
26
|
-
* @link https://www.npmjs.com/package/uuid
|
|
27
|
-
*/
|
|
28
|
-
uuid: typeof uuid;
|
|
29
14
|
/**
|
|
30
15
|
* Ajv JSON schema validator
|
|
31
16
|
* @link https://www.npmjs.com/package/ajv
|
|
@@ -37,17 +22,6 @@ export interface Defaults {
|
|
|
37
22
|
*/
|
|
38
23
|
ajvFormats: typeof ajvFormats;
|
|
39
24
|
ajvKeywords: typeof ajvKeywords;
|
|
40
|
-
/**
|
|
41
|
-
* Async is a utility module which provides straight-forward
|
|
42
|
-
* powerful functions for working with asynchronous JavaScript.
|
|
43
|
-
* @link https://www.npmjs.com/package/async
|
|
44
|
-
*/
|
|
45
|
-
async: typeof async;
|
|
46
|
-
/**
|
|
47
|
-
* Promise based HTTP client for the browser and node.js
|
|
48
|
-
* @Link https://www.npmjs.com/package/axios
|
|
49
|
-
*/
|
|
50
|
-
axios: typeof axios;
|
|
51
25
|
/**
|
|
52
26
|
* Node.js library for parsing and manipulating crontab instructions.
|
|
53
27
|
* It includes support for timezones and DST transitions.
|
|
@@ -84,10 +58,6 @@ export interface Defaults {
|
|
|
84
58
|
* @link https://www.npmjs.com/package/sequelize
|
|
85
59
|
*/
|
|
86
60
|
Sequelize: typeof Sequelize;
|
|
87
|
-
/**
|
|
88
|
-
* A JavaScript date library for parsing, validating, manipulating, and formatting dates.
|
|
89
|
-
*/
|
|
90
|
-
moment: typeof moment;
|
|
91
61
|
/**
|
|
92
62
|
* utils tools function
|
|
93
63
|
*/
|
package/dist/defaults.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
11
15
|
}) : function(o, v) {
|
|
12
16
|
o["default"] = v;
|
|
13
17
|
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
21
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
37
|
};
|
|
@@ -26,34 +40,24 @@ exports.defaults = void 0;
|
|
|
26
40
|
const ajv = __importStar(require("ajv"));
|
|
27
41
|
const ajvFormats = __importStar(require("ajv-formats"));
|
|
28
42
|
const ajv_keywords_1 = __importDefault(require("ajv-keywords"));
|
|
29
|
-
const async = __importStar(require("async"));
|
|
30
|
-
const axios = __importStar(require("axios"));
|
|
31
43
|
const cronParser = __importStar(require("cron-parser"));
|
|
32
44
|
const human_interval_1 = __importDefault(require("human-interval"));
|
|
33
45
|
const ioredis_1 = __importDefault(require("ioredis"));
|
|
34
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
35
46
|
const lru_cache_1 = __importDefault(require("lru-cache"));
|
|
36
|
-
const moment_1 = __importDefault(require("moment"));
|
|
37
47
|
const mysql = __importStar(require("mysql2"));
|
|
38
48
|
const Sequelize = __importStar(require("sequelize"));
|
|
39
|
-
const uuid = __importStar(require("uuid"));
|
|
40
49
|
const basic_errors_1 = require("./basic-errors");
|
|
41
50
|
const utils = __importStar(require("./utils"));
|
|
42
51
|
exports.defaults = {
|
|
43
|
-
_: lodash_1.default,
|
|
44
|
-
uuid,
|
|
45
52
|
ajv,
|
|
46
53
|
ajvFormats,
|
|
47
54
|
ajvKeywords: ajv_keywords_1.default,
|
|
48
|
-
async,
|
|
49
|
-
axios,
|
|
50
55
|
cronParser,
|
|
51
56
|
humanInterval: human_interval_1.default,
|
|
52
57
|
IORedis: ioredis_1.default,
|
|
53
58
|
LRU: lru_cache_1.default,
|
|
54
59
|
mysql,
|
|
55
60
|
Sequelize,
|
|
56
|
-
moment: moment_1.default,
|
|
57
61
|
utils,
|
|
58
62
|
U: utils,
|
|
59
63
|
errors: basic_errors_1.errors,
|
package/dist/deps/aes/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,25 +15,70 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
11
15
|
}) : function(o, v) {
|
|
12
16
|
o["default"] = v;
|
|
13
17
|
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
21
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.Main =
|
|
23
|
-
const
|
|
24
|
-
const cryptojs = __importStar(require("crypto-js/core"));
|
|
36
|
+
exports.Main = Main;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
25
38
|
function Main() {
|
|
26
39
|
// aes-256-cbc encrypt
|
|
27
|
-
const encrypt = (message, key) =>
|
|
40
|
+
const encrypt = (message, key) => {
|
|
41
|
+
// 生成随机 IV
|
|
42
|
+
const iv = crypto.randomBytes(16);
|
|
43
|
+
// 使用 PBKDF2 从密钥生成固定长度的密钥
|
|
44
|
+
const derivedKey = crypto.pbkdf2Sync(key, "salt", 1000, 32, "sha256");
|
|
45
|
+
// 创建加密器
|
|
46
|
+
const cipher = crypto.createCipheriv("aes-256-cbc", derivedKey, iv);
|
|
47
|
+
cipher.setAutoPadding(true);
|
|
48
|
+
// 加密
|
|
49
|
+
let encrypted = cipher.update(message, "utf8", "hex");
|
|
50
|
+
encrypted += cipher.final("hex");
|
|
51
|
+
// 返回 IV + 加密数据的组合
|
|
52
|
+
const result = iv.toString("hex") + ":" + encrypted;
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
28
55
|
// aes-256-cbc decrypt
|
|
29
|
-
const decrypt = (message, key) =>
|
|
56
|
+
const decrypt = (message, key) => {
|
|
57
|
+
try {
|
|
58
|
+
// 分离 IV 和加密数据
|
|
59
|
+
const parts = message.split(":");
|
|
60
|
+
if (parts.length !== 2) {
|
|
61
|
+
throw new Error("Invalid encrypted message format");
|
|
62
|
+
}
|
|
63
|
+
const iv = Buffer.from(parts[0], "hex");
|
|
64
|
+
const encrypted = parts[1];
|
|
65
|
+
// 使用相同的 PBKDF2 生成密钥
|
|
66
|
+
const derivedKey = crypto.pbkdf2Sync(key, "salt", 1000, 32, "sha256");
|
|
67
|
+
// 创建解密器
|
|
68
|
+
const decipher = crypto.createDecipheriv("aes-256-cbc", derivedKey, iv);
|
|
69
|
+
decipher.setAutoPadding(true);
|
|
70
|
+
// 解密
|
|
71
|
+
let decrypted = decipher.update(encrypted, "hex", "utf8");
|
|
72
|
+
decrypted += decipher.final("utf8");
|
|
73
|
+
return decrypted;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
77
|
+
throw new Error("Decryption failed: " + errorMessage);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
30
80
|
return Object.freeze({
|
|
31
81
|
encrypt,
|
|
32
82
|
decrypt,
|
|
33
83
|
});
|
|
34
84
|
}
|
|
35
|
-
exports.Main = Main;
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
1
|
+
import { Redis } from "ioredis";
|
|
2
|
+
import { LRUCache } from "lru-cache";
|
|
3
|
+
export interface CnfDef {
|
|
4
|
+
cache: {
|
|
5
|
+
isMulti?: boolean;
|
|
6
|
+
delSignalChannel?: string;
|
|
7
|
+
} & LRUCache.Options<{}, {}, unknown>;
|
|
8
|
+
redis?: any;
|
|
9
|
+
}
|
|
10
|
+
export interface DepsDef {
|
|
11
|
+
IORedis: typeof Redis;
|
|
12
|
+
logger: {
|
|
13
|
+
info: (message: string, extra?: any) => void;
|
|
14
|
+
error: (error: Error, extra?: any) => void;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface Cache extends LRUCache<{}, {}, unknown> {
|
|
18
|
+
caching: <T extends (...args: any[]) => Promise<any>>(func: T, life: number, getKey: (...args: Parameters<T>) => string, hit?: (hited: boolean) => void) => T;
|
|
19
|
+
hitCount: () => {
|
|
20
|
+
hits: number;
|
|
21
|
+
misseds: number;
|
|
22
|
+
};
|
|
23
|
+
needToBroad: boolean;
|
|
24
|
+
}
|
|
5
25
|
export declare const Deps: string[];
|
|
26
|
+
export declare function Main(cnf: CnfDef, deps: DepsDef): Cache;
|
package/dist/deps/cache/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deps =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function Main(cnf, deps, pubsub) {
|
|
3
|
+
exports.Deps = void 0;
|
|
4
|
+
exports.Main = Main;
|
|
5
|
+
const lru_cache_1 = require("lru-cache");
|
|
6
|
+
exports.Deps = ["logger", "LRU", "IORedis"];
|
|
7
|
+
function Main(cnf, deps) {
|
|
9
8
|
let hits = 0; // 击中次数
|
|
10
9
|
let misseds = 0; // 未击中次数
|
|
11
|
-
const {
|
|
12
|
-
const lru = new
|
|
10
|
+
const { logger, IORedis } = deps;
|
|
11
|
+
const lru = new lru_cache_1.LRUCache(cnf.cache);
|
|
13
12
|
const isFunction = (arg) => typeof arg === "function";
|
|
14
13
|
function caching(func, life, getKey, hit) {
|
|
15
14
|
if (!isFunction(func))
|
|
@@ -32,19 +31,40 @@ function Main(cnf, deps, pubsub) {
|
|
|
32
31
|
hit(false);
|
|
33
32
|
misseds += 1;
|
|
34
33
|
const res = await func(...args);
|
|
35
|
-
lru.set(key, res, life);
|
|
34
|
+
lru.set(key, res, { ttl: life });
|
|
36
35
|
return res;
|
|
37
36
|
};
|
|
38
37
|
return wrapped;
|
|
39
38
|
}
|
|
40
39
|
const hitCount = () => ({ hits, misseds });
|
|
41
|
-
const needToBroad = Boolean(
|
|
40
|
+
const needToBroad = Boolean(cnf.cache.isMulti);
|
|
41
|
+
// 如果不是多节点分部署部署,则不需要处理
|
|
42
|
+
// 开启多节点分布式部署后,要通过redis广播cache的del事件,依次来保持cache的有效性
|
|
43
|
+
if (needToBroad) {
|
|
44
|
+
const pub = new IORedis(cnf.redis);
|
|
45
|
+
const sub = new IORedis(cnf.redis);
|
|
46
|
+
const { delSignalChannel = "LRU_DEL_SIGNAL_CHANNEL" } = cnf.cache;
|
|
47
|
+
sub.subscribe(delSignalChannel, (err, count) => {
|
|
48
|
+
logger.info("cache.redis.subscribe", { chanels: delSignalChannel, count });
|
|
49
|
+
if (err)
|
|
50
|
+
return logger.error(err);
|
|
51
|
+
return logger.info(`cache.redis.subscribe succeed, channel count: ${count}`);
|
|
52
|
+
});
|
|
53
|
+
const del = lru.delete.bind(lru);
|
|
54
|
+
lru.delete = (key) => {
|
|
55
|
+
del(key);
|
|
56
|
+
pub.publish(delSignalChannel, key);
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
sub.on("message", async (channel, key) => {
|
|
60
|
+
if (channel === delSignalChannel)
|
|
61
|
+
del(key);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
42
64
|
const cache = Object.assign(lru, {
|
|
43
65
|
caching,
|
|
44
66
|
hitCount,
|
|
45
|
-
needToBroad,
|
|
67
|
+
needToBroad: Boolean(cnf.cache.isMulti),
|
|
46
68
|
});
|
|
47
69
|
return cache;
|
|
48
70
|
}
|
|
49
|
-
exports.Main = Main;
|
|
50
|
-
exports.Deps = ["logger", "LRU", "IORedis"];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deps =
|
|
3
|
+
exports.Deps = void 0;
|
|
4
|
+
exports.Main = Main;
|
|
4
5
|
function Main(cnf, deps) {
|
|
5
6
|
const { async, errors } = deps;
|
|
6
7
|
/** 检测两个值是否相等 */
|
|
@@ -20,5 +21,4 @@ function Main(cnf, deps) {
|
|
|
20
21
|
privacy,
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
|
-
exports.Main = Main;
|
|
24
24
|
exports.Deps = ["errors", "async"];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deps =
|
|
3
|
+
exports.Deps = void 0;
|
|
4
|
+
exports.Main = Main;
|
|
4
5
|
function Main(cnf, deps) {
|
|
5
6
|
const { counter: { key: REDIS_KEY }, } = cnf;
|
|
6
7
|
const { redis } = deps;
|
|
@@ -38,5 +39,4 @@ function Main(cnf, deps) {
|
|
|
38
39
|
};
|
|
39
40
|
return { mget, get, set, incr, decr };
|
|
40
41
|
}
|
|
41
|
-
exports.Main = Main;
|
|
42
42
|
exports.Deps = ["redis"];
|
|
@@ -28,7 +28,7 @@ interface Deps {
|
|
|
28
28
|
*/
|
|
29
29
|
export declare const timeout: (fn: Function, timeoutMS: number) => void;
|
|
30
30
|
export declare function Main(cnf: Cnf, deps: Deps): {
|
|
31
|
-
regist: (name: string, intervalStr: string, startAt?: string
|
|
31
|
+
regist: (name: string, intervalStr: string, startAt?: string) => void;
|
|
32
32
|
start: () => void;
|
|
33
33
|
getStats: () => {
|
|
34
34
|
name: string;
|
package/dist/deps/cron/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deps = exports.
|
|
3
|
+
exports.Deps = exports.timeout = void 0;
|
|
4
|
+
exports.Main = Main;
|
|
4
5
|
/**
|
|
5
6
|
* 定时执行函数, 解决 setTimeout 第二个参数不能大于 2147483647 的问题
|
|
6
7
|
* @param fn 要执行的函数
|
|
@@ -108,5 +109,4 @@ function Main(cnf, deps) {
|
|
|
108
109
|
};
|
|
109
110
|
return { regist, start, getStats };
|
|
110
111
|
}
|
|
111
|
-
exports.Main = Main;
|
|
112
112
|
exports.Deps = ["myCia", "humanInterval", "cronParser"];
|
package/dist/deps/defines.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import * as logger from "./logger";
|
|
|
10
10
|
import * as myCia from "./myCia";
|
|
11
11
|
import * as parallel from "./parallel";
|
|
12
12
|
import * as redis from "./redis";
|
|
13
|
-
import * as request from "./request";
|
|
14
13
|
import * as rest from "./rest";
|
|
15
14
|
import * as schema from "./schema";
|
|
16
15
|
import * as sequelize from "./sequelize";
|
|
@@ -28,7 +27,6 @@ declare const _default: {
|
|
|
28
27
|
myCia: typeof myCia;
|
|
29
28
|
parallel: typeof parallel;
|
|
30
29
|
redis: typeof redis;
|
|
31
|
-
request: typeof request;
|
|
32
30
|
rest: typeof rest;
|
|
33
31
|
schema: typeof schema;
|
|
34
32
|
sequelize: typeof sequelize;
|