@fastcar/core 0.2.45 → 0.2.47
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/package.json +1 -1
- package/src/FastCarApplication.ts +1 -1
- package/src/utils/IPUtils.ts +35 -0
- package/src/utils/TypeUtil.ts +8 -0
- package/src/utils/ValidationUtil.ts +2 -1
- package/src/utils.ts +2 -1
- package/target/FastCarApplication.js +5 -5
- package/target/utils/IPUtils.js +34 -0
- package/target/utils/TypeUtil.js +6 -0
- package/target/utils/ValidationUtil.js +1 -1
- package/target/utils.js +3 -1
- package/test/example/logs/fastcar-server.logger.log +3 -0
- package/test/example/logs/fastcar-server.sys.log +8 -0
- package/test/example/logs/sys.log +0 -2
- package/test/unit/valid-test.ts +7 -0
- package/utils.d.ts +8 -0
- package/test/example/logs/[fastcar-server] logger.log +0 -3
- package/test/example/logs/[fastcar-server] sys.log +0 -8
- /package/test/example/logs/{[fastcar-server] app.log → fastcar-server.app.log} +0 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import * as fs from "fs";
|
|
|
3
3
|
import * as process from "process";
|
|
4
4
|
import * as Events from "events";
|
|
5
5
|
import * as path from "path";
|
|
6
|
-
import ClassLoader from "./utils/
|
|
6
|
+
import ClassLoader from "./utils/ClassLoader";
|
|
7
7
|
import FileUtil from "./utils/FileUtil";
|
|
8
8
|
import MixTool from "./utils/Mix";
|
|
9
9
|
import TypeUtil from "./utils/TypeUtil";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const getIPNum = function (address: string) {
|
|
2
|
+
let ip = address.split(".");
|
|
3
|
+
let total = 0;
|
|
4
|
+
ip.forEach((item, index) => {
|
|
5
|
+
total += parseInt(item) * Math.pow(256, 3 - index);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
return total;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const InnerIPList = [
|
|
12
|
+
["10.0.0.0", "10.255.255.255"],
|
|
13
|
+
["172.16.0.0", "172.31.255.255"],
|
|
14
|
+
["192.168.0.0", "192.168.255.255"],
|
|
15
|
+
["127.0.0.0", "127.255.255.255"],
|
|
16
|
+
].map((item) => {
|
|
17
|
+
return [getIPNum(item[0]), getIPNum(item[1])];
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export default class IPUtils {
|
|
21
|
+
static isInnerIP = (ip: string): boolean => {
|
|
22
|
+
if (["0.0.0.0", "localhost"].includes(ip)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let n = ip.split(".");
|
|
27
|
+
if (n.length != 4) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
let ipn = getIPNum(ip);
|
|
31
|
+
return InnerIPList.some((item) => {
|
|
32
|
+
return ipn >= item[0] && ipn <= item[1];
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
}
|
package/src/utils/TypeUtil.ts
CHANGED
|
@@ -53,4 +53,12 @@ export default class TypeUtil {
|
|
|
53
53
|
let fname = name.toLowerCase();
|
|
54
54
|
return BasicTypes.includes(fname);
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
static isMap(value: any) {
|
|
58
|
+
return value instanceof Map;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static isSet(value: any) {
|
|
62
|
+
return value instanceof Set;
|
|
63
|
+
}
|
|
56
64
|
}
|
|
@@ -10,9 +10,10 @@ export default class ValidationUtil {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
if (TypeUtil.isObject(param)) {
|
|
13
|
-
if (TypeUtil.isDate(param)) {
|
|
13
|
+
if (TypeUtil.isDate(param) || TypeUtil.isMap(param) || TypeUtil.isSet(param)) {
|
|
14
14
|
return true;
|
|
15
15
|
}
|
|
16
|
+
|
|
16
17
|
return Reflect.ownKeys(param).length > 0;
|
|
17
18
|
}
|
|
18
19
|
|
package/src/utils.ts
CHANGED
|
@@ -8,6 +8,7 @@ import FormatStr from "./utils/FormatStr";
|
|
|
8
8
|
import MixTool from "./utils/Mix";
|
|
9
9
|
import TypeUtil from "./utils/TypeUtil";
|
|
10
10
|
import ValidationUtil from "./utils/ValidationUtil";
|
|
11
|
+
import IPUtils from "./utils/IPUtils";
|
|
11
12
|
|
|
12
13
|
//实用工具集合类
|
|
13
|
-
export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool };
|
|
14
|
+
export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool, IPUtils };
|
|
@@ -15,7 +15,7 @@ const fs = require("fs");
|
|
|
15
15
|
const process = require("process");
|
|
16
16
|
const Events = require("events");
|
|
17
17
|
const path = require("path");
|
|
18
|
-
const
|
|
18
|
+
const ClassLoader_1 = require("./utils/ClassLoader");
|
|
19
19
|
const FileUtil_1 = require("./utils/FileUtil");
|
|
20
20
|
const Mix_1 = require("./utils/Mix");
|
|
21
21
|
const TypeUtil_1 = require("./utils/TypeUtil");
|
|
@@ -99,7 +99,7 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
|
|
|
99
99
|
this.delayHotIds.forEach(({ fp, loadType }) => {
|
|
100
100
|
switch (loadType) {
|
|
101
101
|
case 1: {
|
|
102
|
-
let moduleClass =
|
|
102
|
+
let moduleClass = ClassLoader_1.default.loadModule(fp, true);
|
|
103
103
|
this.sysLogger.info("hot update---" + fp);
|
|
104
104
|
if (moduleClass != null) {
|
|
105
105
|
moduleClass.forEach((func) => {
|
|
@@ -245,7 +245,7 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
|
|
|
245
245
|
if (f.startsWith(resp)) {
|
|
246
246
|
continue;
|
|
247
247
|
}
|
|
248
|
-
let moduleClass =
|
|
248
|
+
let moduleClass = ClassLoader_1.default.loadModule(f);
|
|
249
249
|
if (moduleClass != null) {
|
|
250
250
|
moduleClass.forEach((func, name) => {
|
|
251
251
|
if (this.componentMap.has(name)) {
|
|
@@ -337,7 +337,7 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
|
|
|
337
337
|
};
|
|
338
338
|
if (!fpObj) {
|
|
339
339
|
fpObj = [fpdesc];
|
|
340
|
-
|
|
340
|
+
ClassLoader_1.default.watchServices(fp, this);
|
|
341
341
|
this.watchFiles.set(fp, fpObj);
|
|
342
342
|
}
|
|
343
343
|
else {
|
|
@@ -549,7 +549,7 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
|
|
|
549
549
|
this.loadSysConfig();
|
|
550
550
|
//监听系统配置
|
|
551
551
|
if (this.isHotterSysConfig()) {
|
|
552
|
-
|
|
552
|
+
ClassLoader_1.default.watchServices(this.getResourcePath(), this, "sysReload");
|
|
553
553
|
}
|
|
554
554
|
//开启日志
|
|
555
555
|
this.startLog();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getIPNum = function (address) {
|
|
4
|
+
let ip = address.split(".");
|
|
5
|
+
let total = 0;
|
|
6
|
+
ip.forEach((item, index) => {
|
|
7
|
+
total += parseInt(item) * Math.pow(256, 3 - index);
|
|
8
|
+
});
|
|
9
|
+
return total;
|
|
10
|
+
};
|
|
11
|
+
const InnerIPList = [
|
|
12
|
+
["10.0.0.0", "10.255.255.255"],
|
|
13
|
+
["172.16.0.0", "172.31.255.255"],
|
|
14
|
+
["192.168.0.0", "192.168.255.255"],
|
|
15
|
+
["127.0.0.0", "127.255.255.255"],
|
|
16
|
+
].map((item) => {
|
|
17
|
+
return [getIPNum(item[0]), getIPNum(item[1])];
|
|
18
|
+
});
|
|
19
|
+
class IPUtils {
|
|
20
|
+
}
|
|
21
|
+
exports.default = IPUtils;
|
|
22
|
+
IPUtils.isInnerIP = (ip) => {
|
|
23
|
+
if (["0.0.0.0", "localhost"].includes(ip)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
let n = ip.split(".");
|
|
27
|
+
if (n.length != 4) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
let ipn = getIPNum(ip);
|
|
31
|
+
return InnerIPList.some((item) => {
|
|
32
|
+
return ipn >= item[0] && ipn <= item[1];
|
|
33
|
+
});
|
|
34
|
+
};
|
package/target/utils/TypeUtil.js
CHANGED
|
@@ -43,5 +43,11 @@ class TypeUtil {
|
|
|
43
43
|
let fname = name.toLowerCase();
|
|
44
44
|
return BasicTypes.includes(fname);
|
|
45
45
|
}
|
|
46
|
+
static isMap(value) {
|
|
47
|
+
return value instanceof Map;
|
|
48
|
+
}
|
|
49
|
+
static isSet(value) {
|
|
50
|
+
return value instanceof Set;
|
|
51
|
+
}
|
|
46
52
|
}
|
|
47
53
|
exports.default = TypeUtil;
|
|
@@ -10,7 +10,7 @@ class ValidationUtil {
|
|
|
10
10
|
return param.length > 0;
|
|
11
11
|
}
|
|
12
12
|
if (TypeUtil_1.default.isObject(param)) {
|
|
13
|
-
if (TypeUtil_1.default.isDate(param)) {
|
|
13
|
+
if (TypeUtil_1.default.isDate(param) || TypeUtil_1.default.isMap(param) || TypeUtil_1.default.isSet(param)) {
|
|
14
14
|
return true;
|
|
15
15
|
}
|
|
16
16
|
return Reflect.ownKeys(param).length > 0;
|
package/target/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
|
|
3
|
+
exports.IPUtils = exports.MixTool = exports.ClassLoader = exports.ClassUtils = exports.FormatStr = exports.ValidationUtil = exports.TypeUtil = exports.FileUtil = exports.CryptoUtil = exports.DataFormat = exports.DateUtil = void 0;
|
|
4
4
|
const classLoader_1 = require("./utils/classLoader");
|
|
5
5
|
exports.ClassLoader = classLoader_1.default;
|
|
6
6
|
const ClassUtils_1 = require("./utils/ClassUtils");
|
|
@@ -21,3 +21,5 @@ const TypeUtil_1 = require("./utils/TypeUtil");
|
|
|
21
21
|
exports.TypeUtil = TypeUtil_1.default;
|
|
22
22
|
const ValidationUtil_1 = require("./utils/ValidationUtil");
|
|
23
23
|
exports.ValidationUtil = ValidationUtil_1.default;
|
|
24
|
+
const IPUtils_1 = require("./utils/IPUtils");
|
|
25
|
+
exports.IPUtils = IPUtils_1.default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
{"timestamp":"2023-07-24 16:49:43.665","level":"INFO","label":"fastcar-server.logger","message":"自定义的日志输出"}
|
|
2
|
+
{"timestamp":"2023-07-24 16:49:43.666","level":"WARN","label":"fastcar-server.logger","message":"自定义警告"}
|
|
3
|
+
{"timestamp":"2023-07-24 16:49:43.667","level":"ERROR","label":"fastcar-server.logger","message":"自定义报错"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{"timestamp":"2023-07-24 16:49:36.843","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
|
|
2
|
+
{"timestamp":"2023-07-24 16:49:38.241","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
|
|
3
|
+
{"timestamp":"2023-07-24 16:49:39.408","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
|
|
4
|
+
{"timestamp":"2023-07-24 16:49:39.912","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
|
|
5
|
+
{"timestamp":"2023-07-24 16:49:40.384","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
|
|
6
|
+
{"timestamp":"2023-07-24 16:49:45.679","level":"INFO","label":"fastcar-server.sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
|
|
7
|
+
{"timestamp":"2023-07-24 16:49:45.680","level":"INFO","label":"fastcar-server.sys","message":"Call the method before the application stops"}
|
|
8
|
+
{"timestamp":"2023-07-24 16:49:50.692","level":"INFO","label":"fastcar-server.sys","message":"application stop"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
{"timestamp":"2023-05-17 15:11:40.448","level":"ERROR","label":"sys","message":"Unsatisfied dependency expressed through [notFound] ","stack":"Error: Unsatisfied dependency expressed through [notFound] \n at NotFoundController.get (D:\\code\\fast-car\\fast-car\\fastcar-core\\src\\annotation\\bind\\AliasInjection.ts:16:27)\n at NotFoundController.getNotFound (D:\\code\\fast-car\\fast-car\\fastcar-core\\test\\example\\simple\\controller\\NotFoundController.ts:14:15)\n at Context.<anonymous> (D:\\code\\fast-car\\fast-car\\fastcar-core\\test\\example\\simple\\app.ts:89:13)\n at callFn (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runnable.js:366:21)\n at Test.Runnable.run (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runnable.js:354:5)\n at Runner.runTest (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:678:10)\n at D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:801:12\n at next (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:593:14)\n at D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:603:7\n at next (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:486:14)\n at Immediate._onImmediate (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:571:5)\n at processImmediate (node:internal/timers:466:21)\n at process.topLevelDomainCallback (node:domain:152:15)\n at process.callbackTrampoline (node:internal/async_hooks:128:24)"}
|
|
2
|
-
{"timestamp":"2023-05-17 15:11:40.456","level":"ERROR","label":"sys","message":"Unsatisfied dependency expressed through [autoNotFound] ","stack":"Error: Unsatisfied dependency expressed through [autoNotFound] \n at NotFoundController.get (D:\\code\\fast-car\\fast-car\\fastcar-core\\src\\annotation\\bind\\CallDependency.ts:17:26)\n at NotFoundController.getAutoNotFound (D:\\code\\fast-car\\fast-car\\fastcar-core\\test\\example\\simple\\controller\\NotFoundController.ts:18:15)\n at Context.<anonymous> (D:\\code\\fast-car\\fast-car\\fastcar-core\\test\\example\\simple\\app.ts:95:13)\n at callFn (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runnable.js:366:21)\n at Test.Runnable.run (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runnable.js:354:5)\n at Runner.runTest (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:678:10)\n at D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:801:12\n at next (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:593:14)\n at D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:603:7\n at next (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:486:14)\n at Immediate._onImmediate (D:\\code\\fast-car\\fast-car\\node_modules\\mocha\\lib\\runner.js:571:5)\n at processImmediate (node:internal/timers:466:21)\n at process.topLevelDomainCallback (node:domain:152:15)\n at process.callbackTrampoline (node:internal/async_hooks:128:24)"}
|
package/test/unit/valid-test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import ValidForm from "../../src/annotation/valid/ValidForm";
|
|
|
3
3
|
import NotNull from "../../src/annotation/valid/NotNull";
|
|
4
4
|
import Size from "../../src/annotation/valid/Size";
|
|
5
5
|
import { Rule } from "../../src/annotation/valid/Rule";
|
|
6
|
+
import { ValidationUtil } from "../../src/utils";
|
|
6
7
|
|
|
7
8
|
describe("表单校验测试", () => {
|
|
8
9
|
it("表单单个测试", () => {
|
|
@@ -62,4 +63,10 @@ describe("表单校验测试", () => {
|
|
|
62
63
|
let instance = new A();
|
|
63
64
|
instance.test("a", { c: "c", d: 13 }); //校验失败
|
|
64
65
|
});
|
|
66
|
+
|
|
67
|
+
it("测试map是否为空", () => {
|
|
68
|
+
let d = new Map();
|
|
69
|
+
d.set("hello", "world");
|
|
70
|
+
console.log(ValidationUtil.isNotNull(d) == true);
|
|
71
|
+
});
|
|
65
72
|
});
|
package/utils.d.ts
CHANGED
|
@@ -94,6 +94,10 @@ export class TypeUtil {
|
|
|
94
94
|
|
|
95
95
|
//是否为基本类型
|
|
96
96
|
static isBasic(name: string): boolean;
|
|
97
|
+
|
|
98
|
+
static isMap(value: any): boolean;
|
|
99
|
+
|
|
100
|
+
static isSet(value: any): boolean;
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
export class ValidationUtil {
|
|
@@ -166,3 +170,7 @@ export class MixTool {
|
|
|
166
170
|
//多个对象赋值
|
|
167
171
|
static assign(target: any, source: any): void;
|
|
168
172
|
}
|
|
173
|
+
|
|
174
|
+
export class IPUtils {
|
|
175
|
+
static isInnerIP(ip: string): boolean;
|
|
176
|
+
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
{"timestamp":"2023-05-17 15:11:40.432","level":"INFO","label":"[fastcar-server] logger","message":"自定义的日志输出"}
|
|
2
|
-
{"timestamp":"2023-05-17 15:11:40.433","level":"WARN","label":"[fastcar-server] logger","message":"自定义警告"}
|
|
3
|
-
{"timestamp":"2023-05-17 15:11:40.434","level":"ERROR","label":"[fastcar-server] logger","message":"自定义报错"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{"timestamp":"2023-05-17 15:11:21.300","level":"INFO","label":"[fastcar-server] sys","message":"Start scanning component"}
|
|
2
|
-
{"timestamp":"2023-05-17 15:11:40.421","level":"INFO","label":"[fastcar-server] sys","message":"Complete component scan"}
|
|
3
|
-
{"timestamp":"2023-05-17 15:11:40.422","level":"INFO","label":"[fastcar-server] sys","message":"Call application initialization method"}
|
|
4
|
-
{"timestamp":"2023-05-17 15:11:40.424","level":"INFO","label":"[fastcar-server] sys","message":"start server app is run"}
|
|
5
|
-
{"timestamp":"2023-05-17 15:11:40.425","level":"INFO","label":"[fastcar-server] sys","message":"version 1.0.0"}
|
|
6
|
-
{"timestamp":"2023-05-17 15:11:42.456","level":"INFO","label":"[fastcar-server] sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
|
|
7
|
-
{"timestamp":"2023-05-17 15:11:42.457","level":"INFO","label":"[fastcar-server] sys","message":"Call the method before the application stops"}
|
|
8
|
-
{"timestamp":"2023-05-17 15:11:47.460","level":"INFO","label":"[fastcar-server] sys","message":"application stop"}
|
|
File without changes
|