@domain.js/main 0.3.22 → 0.3.25
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/.vscode/settings.json
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
4
|
};
|
|
21
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
6
|
exports.Deps = exports.Main = void 0;
|
|
23
|
-
const
|
|
24
|
-
const
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const util_1 = require("util");
|
|
25
11
|
const date = (offset = 0) => new Date(Date.now() + (offset | 0)).toISOString();
|
|
26
12
|
function Main(cnf, deps) {
|
|
27
|
-
const { logger: { errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
|
|
13
|
+
const { logger: { level, errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
|
|
28
14
|
const { _, uuid: { v4: uuid }, } = deps;
|
|
29
15
|
const makeDir = _.memoize((dir) => {
|
|
30
|
-
if (!
|
|
31
|
-
|
|
16
|
+
if (!(0, fs_1.existsSync)(dir))
|
|
17
|
+
(0, fs_1.mkdirSync)(dir);
|
|
32
18
|
});
|
|
33
19
|
const ignores = new Set(ignoreErrors);
|
|
34
20
|
const error = (e, extra) => {
|
|
21
|
+
if (level === "none")
|
|
22
|
+
return;
|
|
35
23
|
if (!e) {
|
|
36
24
|
console.trace("Logger.error but error is null or undefined");
|
|
37
25
|
return;
|
|
@@ -42,40 +30,53 @@ function Main(cnf, deps) {
|
|
|
42
30
|
// 忽略某些错误
|
|
43
31
|
if (ignores.has(code))
|
|
44
32
|
return;
|
|
45
|
-
const dir =
|
|
33
|
+
const dir = path_1.default.resolve(errorLogPath, today);
|
|
46
34
|
makeDir(dir);
|
|
47
|
-
const file =
|
|
35
|
+
const file = path_1.default.resolve(dir, `${code}.err`);
|
|
48
36
|
const content = [time, clientId, e.message];
|
|
49
|
-
if (e.data)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
fs.appendFileSync(file, `${content.join("\t")}\n`);
|
|
37
|
+
if (e.data) {
|
|
38
|
+
try {
|
|
39
|
+
content.push(JSON.stringify(e.data));
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
content.push((0, util_1.format)(e.data));
|
|
43
|
+
}
|
|
57
44
|
}
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
if (extra !== null || extra !== undefined) {
|
|
46
|
+
try {
|
|
47
|
+
content.push(JSON.stringify(extra));
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
content.push((0, util_1.format)(extra));
|
|
51
|
+
}
|
|
60
52
|
}
|
|
53
|
+
if (e.stack)
|
|
54
|
+
content.push(JSON.stringify(e.stack));
|
|
55
|
+
promises_1.default.appendFile(file, `${content.join("\t")}\n`).catch(console.error);
|
|
61
56
|
};
|
|
62
57
|
const info = (message, extra) => {
|
|
58
|
+
if (level === "none" || level === "error")
|
|
59
|
+
return;
|
|
63
60
|
const time = date();
|
|
64
61
|
const today = time.split("T")[0];
|
|
65
|
-
const dir =
|
|
62
|
+
const dir = path_1.default.resolve(infoLogPath, today);
|
|
66
63
|
makeDir(dir);
|
|
67
|
-
const file =
|
|
64
|
+
const file = path_1.default.resolve(dir, "info.log");
|
|
68
65
|
const content = [time, clientId, message];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
// eslint-disable-next-line no-eq-null
|
|
67
|
+
if (extra !== null || extra !== undefined) {
|
|
68
|
+
try {
|
|
69
|
+
content.push(JSON.stringify(extra));
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
content.push((0, util_1.format)(extra));
|
|
73
|
+
}
|
|
76
74
|
}
|
|
75
|
+
promises_1.default.appendFile(file, `${content.join("\t")}\n`).catch(console.error);
|
|
77
76
|
};
|
|
78
77
|
const logger = (fn, name, isAsync = false, transform = (x) => x, errorHandler = (e) => (e instanceof Error ? e.message : ""), argsHandler = JSON.stringify) => {
|
|
78
|
+
if (level === "none")
|
|
79
|
+
return fn;
|
|
79
80
|
if (isAsync) {
|
|
80
81
|
const handler = {
|
|
81
82
|
async apply(fn, me, args) {
|
|
@@ -6,7 +6,7 @@ interface Deps {
|
|
|
6
6
|
_: typeof _;
|
|
7
7
|
Sequelize: Pick<typeof Sequelize, "literal" | "and" | "fn">;
|
|
8
8
|
}
|
|
9
|
-
export declare function Stats(
|
|
9
|
+
export declare function Stats(_cnf: any, deps: Deps, utils: ReturnType<typeof Utils>): <T extends ModelBase<any, any>>(Model: ModelStatic<T>, params: Record<string, any>, where?: any, conf?: {
|
|
10
10
|
dimensions?: Record<string, string> | undefined;
|
|
11
11
|
metrics: Record<string, string>;
|
|
12
12
|
pagination?: {
|
package/dist/deps/rest/stats.js
CHANGED
package/dist/http/socket.js
CHANGED
|
@@ -116,15 +116,12 @@ function BridgeSocket(io, domain) {
|
|
|
116
116
|
try {
|
|
117
117
|
if (!client.profile || !client.inited)
|
|
118
118
|
return;
|
|
119
|
-
const res = await entrance({
|
|
119
|
+
const res = await entrance({ ...client.profile, roomId }, client);
|
|
120
120
|
client.profile.roomId = roomId;
|
|
121
121
|
client.roomId = roomId;
|
|
122
122
|
client.emit("entranced", res);
|
|
123
123
|
}
|
|
124
124
|
catch (e) {
|
|
125
|
-
client.roomId = undefined;
|
|
126
|
-
if (client.profile)
|
|
127
|
-
client.profile.roomId = undefined;
|
|
128
125
|
if (e instanceof MyError) {
|
|
129
126
|
client.emit("internalError", e.message, e.code || "unknown");
|
|
130
127
|
return;
|