@fastcar/core 0.3.13 → 0.3.15
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 +2 -2
- package/src/utils/ClassLoader.ts +8 -13
- package/src/utils/FilterCondition.ts +49 -0
- package/src/utils/ValidationUtil.ts +9 -1
- package/src/utils.ts +2 -1
- package/target/utils/ClassLoader.js +8 -13
- package/target/utils/FilterCondition.js +45 -0
- package/target/utils/ValidationUtil.js +7 -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 +7 -0
- package/test/example/logs/fastcar-server.sys1.log +2 -0
- package/test/example/logs/other-server.app.log +0 -0
- package/test/example/logs/other-server.sys.log +6 -0
- package/utils.d.ts +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastcar/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.15",
|
|
4
4
|
"homepage": "https://github.com/williamDazhangyu/fast-car",
|
|
5
5
|
"main": "target/index.js",
|
|
6
6
|
"author": "william_zhong",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"node": ">=18"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"
|
|
35
|
+
"@fastcar/watchfile": "^0.0.2",
|
|
36
36
|
"reflect-metadata": "^0.2.2",
|
|
37
37
|
"winston": "^3.10.0",
|
|
38
38
|
"yaml": "^2.6.1"
|
package/src/utils/ClassLoader.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import TypeUtil from "./TypeUtil";
|
|
2
2
|
import FileUtil from "./FileUtil";
|
|
3
3
|
import { HotReloadEnum } from "../type/FileHotterDesc";
|
|
4
|
-
import
|
|
4
|
+
import { WatchSingleton } from "@fastcar/watchfile";
|
|
5
5
|
|
|
6
6
|
export default class ClassLoader {
|
|
7
7
|
/***
|
|
@@ -60,20 +60,15 @@ export default class ClassLoader {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
//添加热更方法
|
|
63
|
-
const watcher =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
awaitWriteFinish: {
|
|
67
|
-
stabilityThreshold: 500,
|
|
68
|
-
pollInterval: 100,
|
|
69
|
-
},
|
|
70
|
-
usePolling: true,
|
|
71
|
-
atomic: true,
|
|
72
|
-
interval: 1000,
|
|
63
|
+
const watcher = WatchSingleton({
|
|
64
|
+
pollInterval: 1000,
|
|
65
|
+
notifyTime: 3000,
|
|
73
66
|
});
|
|
74
67
|
|
|
75
|
-
watcher.
|
|
76
|
-
|
|
68
|
+
watcher.addWatch({
|
|
69
|
+
fp,
|
|
70
|
+
context,
|
|
71
|
+
eventName,
|
|
77
72
|
});
|
|
78
73
|
|
|
79
74
|
return true;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import ValidationUtil from "./ValidationUtil";
|
|
2
|
+
|
|
3
|
+
export default class FilterCondition {
|
|
4
|
+
private where: { [key: string]: any };
|
|
5
|
+
|
|
6
|
+
constructor(where?: { [key: string]: any }, info?: { field?: string[]; excludeField?: string[] }) {
|
|
7
|
+
this.where = {};
|
|
8
|
+
if (ValidationUtil.isNotNull(where) && where) {
|
|
9
|
+
this.addFiled(where, info);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//过滤空的值
|
|
14
|
+
filterNull(excludeField: string[] = []) {
|
|
15
|
+
let keys = Object.keys(this.where);
|
|
16
|
+
keys.forEach((key) => {
|
|
17
|
+
let value = Reflect.get(this.where, key);
|
|
18
|
+
if (!excludeField.includes(key) && !ValidationUtil.isNotMinSize(value, 1)) {
|
|
19
|
+
Reflect.deleteProperty(this.where, key);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
addFiled(where: { [key: string]: any }, info?: { field?: string[]; excludeField?: string[] }) {
|
|
27
|
+
let { field = [], excludeField = [] } = info || {};
|
|
28
|
+
let all = field.length == 0 && excludeField.length == 0;
|
|
29
|
+
|
|
30
|
+
for (let key in where) {
|
|
31
|
+
if (all || (field.length > 0 && field.includes(key)) || (field.length == 0 && !excludeField.includes(key))) {
|
|
32
|
+
let value = where[key];
|
|
33
|
+
//排除基础类型,数组和空对象
|
|
34
|
+
if (ValidationUtil.isNotNull(value) && ValidationUtil.isObject(value) && !ValidationUtil.isArray(value, "array")) {
|
|
35
|
+
let beforeObj = Reflect.get(this.where, key) || {};
|
|
36
|
+
Reflect.set(this.where, key, Object.assign({}, beforeObj, where[key]));
|
|
37
|
+
} else {
|
|
38
|
+
Reflect.set(this.where, key, value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
toObject() {
|
|
47
|
+
return this.where;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -68,7 +68,15 @@ export default class ValidationUtil {
|
|
|
68
68
|
return param.length >= value;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
if (TypeUtil.isMap(param) || TypeUtil.isSet(param)) {
|
|
72
|
+
return param.size >= value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (ValidationUtil.isNull(param)) {
|
|
76
|
+
return 0 >= value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let v = param.toString();
|
|
72
80
|
return v.length >= value;
|
|
73
81
|
}
|
|
74
82
|
|
package/src/utils.ts
CHANGED
|
@@ -9,6 +9,7 @@ import MixTool from "./utils/Mix";
|
|
|
9
9
|
import TypeUtil from "./utils/TypeUtil";
|
|
10
10
|
import ValidationUtil from "./utils/ValidationUtil";
|
|
11
11
|
import IPUtils from "./utils/IPUtils";
|
|
12
|
+
import FilterCondition from "./utils/FilterCondition";
|
|
12
13
|
|
|
13
14
|
//实用工具集合类
|
|
14
|
-
export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool, IPUtils };
|
|
15
|
+
export { DateUtil, DataFormat, CryptoUtil, FileUtil, TypeUtil, ValidationUtil, FormatStr, ClassUtils, ClassLoader, MixTool, IPUtils, FilterCondition };
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const TypeUtil_1 = require("./TypeUtil");
|
|
4
4
|
const FileUtil_1 = require("./FileUtil");
|
|
5
5
|
const FileHotterDesc_1 = require("../type/FileHotterDesc");
|
|
6
|
-
const
|
|
6
|
+
const watchfile_1 = require("@fastcar/watchfile");
|
|
7
7
|
class ClassLoader {
|
|
8
8
|
/***
|
|
9
9
|
* @version 1.0 加载模块
|
|
@@ -47,19 +47,14 @@ class ClassLoader {
|
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
//添加热更方法
|
|
50
|
-
const watcher =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
awaitWriteFinish: {
|
|
54
|
-
stabilityThreshold: 500,
|
|
55
|
-
pollInterval: 100,
|
|
56
|
-
},
|
|
57
|
-
usePolling: true,
|
|
58
|
-
atomic: true,
|
|
59
|
-
interval: 1000,
|
|
50
|
+
const watcher = (0, watchfile_1.WatchSingleton)({
|
|
51
|
+
pollInterval: 1000,
|
|
52
|
+
notifyTime: 3000,
|
|
60
53
|
});
|
|
61
|
-
watcher.
|
|
62
|
-
|
|
54
|
+
watcher.addWatch({
|
|
55
|
+
fp,
|
|
56
|
+
context,
|
|
57
|
+
eventName,
|
|
63
58
|
});
|
|
64
59
|
return true;
|
|
65
60
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ValidationUtil_1 = require("./ValidationUtil");
|
|
4
|
+
class FilterCondition {
|
|
5
|
+
where;
|
|
6
|
+
constructor(where, info) {
|
|
7
|
+
this.where = {};
|
|
8
|
+
if (ValidationUtil_1.default.isNotNull(where) && where) {
|
|
9
|
+
this.addFiled(where, info);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//过滤空的值
|
|
13
|
+
filterNull(excludeField = []) {
|
|
14
|
+
let keys = Object.keys(this.where);
|
|
15
|
+
keys.forEach((key) => {
|
|
16
|
+
let value = Reflect.get(this.where, key);
|
|
17
|
+
if (!excludeField.includes(key) && !ValidationUtil_1.default.isNotMinSize(value, 1)) {
|
|
18
|
+
Reflect.deleteProperty(this.where, key);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
addFiled(where, info) {
|
|
24
|
+
let { field = [], excludeField = [] } = info || {};
|
|
25
|
+
let all = field.length == 0 && excludeField.length == 0;
|
|
26
|
+
for (let key in where) {
|
|
27
|
+
if (all || (field.length > 0 && field.includes(key)) || (field.length == 0 && !excludeField.includes(key))) {
|
|
28
|
+
let value = where[key];
|
|
29
|
+
//排除基础类型,数组和空对象
|
|
30
|
+
if (ValidationUtil_1.default.isNotNull(value) && ValidationUtil_1.default.isObject(value) && !ValidationUtil_1.default.isArray(value, "array")) {
|
|
31
|
+
let beforeObj = Reflect.get(this.where, key) || {};
|
|
32
|
+
Reflect.set(this.where, key, Object.assign({}, beforeObj, where[key]));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
Reflect.set(this.where, key, value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
toObject() {
|
|
42
|
+
return this.where;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.default = FilterCondition;
|
|
@@ -55,7 +55,13 @@ class ValidationUtil {
|
|
|
55
55
|
if (Array.isArray(param)) {
|
|
56
56
|
return param.length >= value;
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
if (TypeUtil_1.default.isMap(param) || TypeUtil_1.default.isSet(param)) {
|
|
59
|
+
return param.size >= value;
|
|
60
|
+
}
|
|
61
|
+
if (ValidationUtil.isNull(param)) {
|
|
62
|
+
return 0 >= value;
|
|
63
|
+
}
|
|
64
|
+
let v = param.toString();
|
|
59
65
|
return v.length >= value;
|
|
60
66
|
}
|
|
61
67
|
static isNotMaxSize(param, value) {
|
package/target/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.FilterCondition = 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");
|
|
@@ -23,3 +23,5 @@ const ValidationUtil_1 = require("./utils/ValidationUtil");
|
|
|
23
23
|
exports.ValidationUtil = ValidationUtil_1.default;
|
|
24
24
|
const IPUtils_1 = require("./utils/IPUtils");
|
|
25
25
|
exports.IPUtils = IPUtils_1.default;
|
|
26
|
+
const FilterCondition_1 = require("./utils/FilterCondition");
|
|
27
|
+
exports.FilterCondition = FilterCondition_1.default;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
{"timestamp":"2025-11-14 18:41:08.659","level":"INFO","label":"fastcar-server.logger","message":"自定义的日志输出"}
|
|
2
|
+
{"timestamp":"2025-11-14 18:41:08.661","level":"WARN","label":"fastcar-server.logger","message":"自定义警告"}
|
|
3
|
+
{"timestamp":"2025-11-14 18:41:08.663","level":"ERROR","label":"fastcar-server.logger","message":"自定义报错"}
|
|
@@ -3,3 +3,10 @@
|
|
|
3
3
|
{"timestamp":"2025-08-25 15:08:20.824","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
|
|
4
4
|
{"timestamp":"2025-08-25 15:08:20.828","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
|
|
5
5
|
{"timestamp":"2025-08-25 15:08:20.829","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
|
|
6
|
+
{"timestamp":"2025-11-14 18:41:08.206","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
|
|
7
|
+
{"timestamp":"2025-11-14 18:41:08.628","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
|
|
8
|
+
{"timestamp":"2025-11-14 18:41:08.635","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
|
|
9
|
+
{"timestamp":"2025-11-14 18:41:08.642","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
|
|
10
|
+
{"timestamp":"2025-11-14 18:41:08.643","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
|
|
11
|
+
{"timestamp":"2025-11-14 18:41:21.809","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\resource\\hello.yml"}
|
|
12
|
+
{"timestamp":"2025-11-14 18:42:06.154","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\resource\\hello.yml"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{"timestamp":"2025-11-14 18:39:59.442","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\resource\\hello.yml"}
|
|
2
|
+
{"timestamp":"2025-11-14 18:40:37.689","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\resource\\hello.yml"}
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{"timestamp":"2025-11-14 18:38:44.920","level":"INFO","label":"other-server.sys","message":"Start scanning component"}
|
|
2
|
+
{"timestamp":"2025-11-14 18:38:45.774","level":"INFO","label":"other-server.sys","message":"Complete component scan"}
|
|
3
|
+
{"timestamp":"2025-11-14 18:38:45.777","level":"INFO","label":"other-server.sys","message":"Call application initialization method"}
|
|
4
|
+
{"timestamp":"2025-11-14 18:38:45.780","level":"INFO","label":"other-server.sys","message":"start server app is run"}
|
|
5
|
+
{"timestamp":"2025-11-14 18:38:45.781","level":"INFO","label":"other-server.sys","message":"version 1.0.0"}
|
|
6
|
+
{"timestamp":"2025-11-14 18:38:51.375","level":"INFO","label":"other-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\resource\\hello.yml"}
|
package/utils.d.ts
CHANGED
|
@@ -180,3 +180,13 @@ export class MixTool {
|
|
|
180
180
|
export class IPUtils {
|
|
181
181
|
static isInnerIP(ip: string): boolean;
|
|
182
182
|
}
|
|
183
|
+
|
|
184
|
+
export class FilterCondition {
|
|
185
|
+
constructor(where?: { [key: string]: any }, info?: { field?: string[]; excludeField?: string[] });
|
|
186
|
+
|
|
187
|
+
filterNull(excludeField?: string[]): this;
|
|
188
|
+
|
|
189
|
+
addFiled(where: { [key: string]: any }, info?: { field?: string[]; excludeField?: string[] }): this;
|
|
190
|
+
|
|
191
|
+
toObject(): { [key: string]: any };
|
|
192
|
+
}
|