@fastcar/core 0.2.64 → 0.3.0
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/README.md +5 -2
- package/annotation.d.ts +3 -0
- package/index.d.ts +57 -50
- package/package.json +4 -4
- package/src/FastCarApplication.ts +184 -123
- package/src/annotation/Application.ts +3 -1
- package/src/annotation/bind/AddInjectionService.ts +17 -0
- package/src/annotation/bind/AddRequireModule.ts +1 -1
- package/src/annotation/bind/AliasInjection.ts +8 -15
- package/src/annotation/bind/Autowired.ts +1 -1
- package/src/annotation/bind/CallDependency.ts +7 -17
- package/src/annotation/bind/DemandInjection.ts +16 -0
- package/src/annotation/stereotype/Log.ts +13 -9
- package/src/annotation/stereotype/Value.ts +5 -0
- package/src/annotation.ts +2 -0
- package/src/constant/FastCarMetaData.ts +2 -0
- package/src/model/WinstonLogger.ts +1 -1
- package/src/type/ClassConstructor.ts +5 -0
- package/src/type/ComponentDesc.ts +13 -0
- package/src/type/FileHotterDesc.ts +6 -0
- package/src/utils/ClassLoader.ts +2 -1
- package/target/FastCarApplication.js +764 -708
- package/target/annotation/Application.js +46 -45
- package/target/annotation/ExceptionMonitor.js +16 -16
- package/target/annotation/bind/AddInjectionService.js +16 -0
- package/target/annotation/bind/AddRequireModule.js +21 -21
- package/target/annotation/bind/AliasInjection.js +19 -23
- package/target/annotation/bind/Autowired.js +13 -13
- package/target/annotation/bind/CallDependency.js +16 -23
- package/target/annotation/bind/DemandInjection.js +15 -0
- package/target/annotation/data/DBType.js +11 -11
- package/target/annotation/data/DS.js +54 -54
- package/target/annotation/data/DSIndex.js +9 -9
- package/target/annotation/data/Entity.js +10 -10
- package/target/annotation/data/Field.js +18 -18
- package/target/annotation/data/PrimaryKey.js +9 -9
- package/target/annotation/data/SqlSession.js +9 -9
- package/target/annotation/data/Table.js +35 -35
- package/target/annotation/data/Transactional.js +52 -52
- package/target/annotation/env/ApplicationSetting.js +25 -25
- package/target/annotation/env/BaseFilePath.js +14 -14
- package/target/annotation/env/BaseName.js +9 -9
- package/target/annotation/env/BasePath.js +14 -14
- package/target/annotation/env/ENV.js +10 -10
- package/target/annotation/env/ResourcePath.js +9 -9
- package/target/annotation/lifeCycle/AddLifeCycleItem.js +17 -18
- package/target/annotation/lifeCycle/ApplicationDestory.js +15 -15
- package/target/annotation/lifeCycle/ApplicationInit.js +15 -15
- package/target/annotation/lifeCycle/ApplicationRunner.js +7 -7
- package/target/annotation/lifeCycle/ApplicationStart.js +24 -24
- package/target/annotation/lifeCycle/ApplicationStop.js +20 -20
- package/target/annotation/property/Deprecate.js +19 -19
- package/target/annotation/property/NotImplemented.js +8 -8
- package/target/annotation/property/Override.js +7 -7
- package/target/annotation/property/Readonly.js +16 -16
- package/target/annotation/scan/ComponentInjection.js +21 -21
- package/target/annotation/scan/ComponentScan.js +9 -9
- package/target/annotation/scan/ComponentScanExclusion.js +25 -25
- package/target/annotation/scan/ComponentScanMust.js +25 -25
- package/target/annotation/scan/Hotter.js +8 -8
- package/target/annotation/stereotype/BeanName.js +11 -11
- package/target/annotation/stereotype/Component.js +8 -8
- package/target/annotation/stereotype/Configure.js +14 -14
- package/target/annotation/stereotype/Controller.js +9 -9
- package/target/annotation/stereotype/Injection.js +12 -12
- package/target/annotation/stereotype/Log.js +19 -17
- package/target/annotation/stereotype/Repository.js +9 -9
- package/target/annotation/stereotype/Service.js +9 -9
- package/target/annotation/stereotype/Value.js +5 -0
- package/target/annotation/valid/AddChildValid.js +56 -56
- package/target/annotation/valid/CustomType.js +11 -11
- package/target/annotation/valid/DefaultVal.js +10 -10
- package/target/annotation/valid/NotNull.js +8 -8
- package/target/annotation/valid/Rule.js +99 -100
- package/target/annotation/valid/Size.js +10 -10
- package/target/annotation/valid/Type.js +10 -10
- package/target/annotation/valid/ValidCustom.js +17 -17
- package/target/annotation/valid/ValidForm.js +133 -133
- package/target/annotation.js +110 -108
- package/target/config/ApplicationConfig.js +2 -2
- package/target/config/SysConfig.js +19 -19
- package/target/constant/AppStatusEnum.js +9 -9
- package/target/constant/BootPriority.js +11 -11
- package/target/constant/CommonConstant.js +18 -18
- package/target/constant/ComponentKind.js +11 -11
- package/target/constant/DataTypes.js +19 -19
- package/target/constant/FastCarMetaData.js +33 -31
- package/target/constant/LifeCycleModule.js +9 -9
- package/target/db.js +49 -49
- package/target/index.js +21 -21
- package/target/interface/ApplicationHook.js +2 -2
- package/target/interface/ApplicationInterface.js +2 -2
- package/target/interface/ApplicationRunnerService.js +2 -2
- package/target/interface/DataSourceManager.js +2 -2
- package/target/interface/Logger.js +5 -5
- package/target/model/BaseMapper.js +103 -98
- package/target/model/DataMap.js +87 -87
- package/target/model/FormRuleModel.js +2 -2
- package/target/model/ValidError.js +5 -5
- package/target/model/WinstonLogger.js +98 -96
- package/target/type/ClassConstructor.js +2 -0
- package/target/type/ComponentDesc.js +9 -2
- package/target/type/DesignMeta.js +15 -15
- package/target/type/FileHotterDesc.js +9 -2
- package/target/type/MapperType.js +2 -2
- package/target/type/ProcessType.js +2 -2
- package/target/type/SqlError.js +5 -5
- package/target/type/WinstonLoggerType.js +9 -9
- package/target/utils/ClassLoader.js +66 -65
- package/target/utils/ClassUtils.js +35 -35
- package/target/utils/CryptoUtil.js +86 -86
- package/target/utils/DataFormat.js +88 -88
- package/target/utils/DateUtil.js +71 -71
- package/target/utils/FileUtil.js +153 -153
- package/target/utils/FormatStr.js +14 -14
- package/target/utils/IPUtils.js +34 -34
- package/target/utils/Id.js +8 -9
- package/target/utils/Mix.js +62 -62
- package/target/utils/ReflectUtil.js +22 -22
- package/target/utils/TypeUtil.js +53 -53
- package/target/utils/ValidationUtil.js +123 -123
- package/target/utils.js +25 -25
- package/test/example/logs/fastcar-server.app.log +0 -0
- package/test/example/logs/fastcar-server.sys.log +10 -0
- package/test/example/logs/fastcar-server.sys1.log +8 -0
- package/test/example/logs/fastcar-server.sys2.log +11 -0
- package/test/example/logs/fastcar-server.sys3.log +0 -0
- package/test/example/logs/other-server.app.log +0 -0
- package/test/example/logs/other-server.sys.log +5 -0
- package/test/example/logs/sys.log +0 -0
- package/test/example/logs/sys1.log +0 -0
- package/test/example/resource/application.yml +2 -0
- package/test/example/resource/hello.yml +1 -1
- package/test/example/simple/app-test.ts +2 -1
- package/test/example/simple/app.ts +16 -16
- package/test/example/simple/service/CallService.ts +2 -0
- package/test/example/simple/service/HelloService.ts +2 -0
- package/test/unit/sys2.log +6 -0
- package/test/unit/sys3.log +6 -0
- package/test/unit/sys4.log +6 -0
- package/test/unit/sys5.log +6 -0
- package/test/unit/sys6.log +6 -0
package/target/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommonConstant = exports.Logger = exports.DataMap = exports.ValidError = exports.FastCarMetaData = exports.FastCarApplication = exports.BootPriority = exports.ComponentKind = exports.LifeCycleModule = void 0;
|
|
4
|
-
const BootPriority_1 = require("./constant/BootPriority");
|
|
5
|
-
Object.defineProperty(exports, "BootPriority", { enumerable: true, get: function () { return BootPriority_1.BootPriority; } });
|
|
6
|
-
const CommonConstant_1 = require("./constant/CommonConstant");
|
|
7
|
-
Object.defineProperty(exports, "CommonConstant", { enumerable: true, get: function () { return CommonConstant_1.CommonConstant; } });
|
|
8
|
-
const ComponentKind_1 = require("./constant/ComponentKind");
|
|
9
|
-
Object.defineProperty(exports, "ComponentKind", { enumerable: true, get: function () { return ComponentKind_1.ComponentKind; } });
|
|
10
|
-
const FastCarMetaData_1 = require("./constant/FastCarMetaData");
|
|
11
|
-
Object.defineProperty(exports, "FastCarMetaData", { enumerable: true, get: function () { return FastCarMetaData_1.FastCarMetaData; } });
|
|
12
|
-
const LifeCycleModule_1 = require("./constant/LifeCycleModule");
|
|
13
|
-
Object.defineProperty(exports, "LifeCycleModule", { enumerable: true, get: function () { return LifeCycleModule_1.LifeCycleModule; } });
|
|
14
|
-
const FastCarApplication_1 = require("./FastCarApplication");
|
|
15
|
-
exports.FastCarApplication = FastCarApplication_1.default;
|
|
16
|
-
const Logger_1 = require("./interface/Logger");
|
|
17
|
-
exports.Logger = Logger_1.default;
|
|
18
|
-
const DataMap_1 = require("./model/DataMap");
|
|
19
|
-
exports.DataMap = DataMap_1.default;
|
|
20
|
-
const ValidError_1 = require("./model/ValidError");
|
|
21
|
-
exports.ValidError = ValidError_1.default;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonConstant = exports.Logger = exports.DataMap = exports.ValidError = exports.FastCarMetaData = exports.FastCarApplication = exports.BootPriority = exports.ComponentKind = exports.LifeCycleModule = void 0;
|
|
4
|
+
const BootPriority_1 = require("./constant/BootPriority");
|
|
5
|
+
Object.defineProperty(exports, "BootPriority", { enumerable: true, get: function () { return BootPriority_1.BootPriority; } });
|
|
6
|
+
const CommonConstant_1 = require("./constant/CommonConstant");
|
|
7
|
+
Object.defineProperty(exports, "CommonConstant", { enumerable: true, get: function () { return CommonConstant_1.CommonConstant; } });
|
|
8
|
+
const ComponentKind_1 = require("./constant/ComponentKind");
|
|
9
|
+
Object.defineProperty(exports, "ComponentKind", { enumerable: true, get: function () { return ComponentKind_1.ComponentKind; } });
|
|
10
|
+
const FastCarMetaData_1 = require("./constant/FastCarMetaData");
|
|
11
|
+
Object.defineProperty(exports, "FastCarMetaData", { enumerable: true, get: function () { return FastCarMetaData_1.FastCarMetaData; } });
|
|
12
|
+
const LifeCycleModule_1 = require("./constant/LifeCycleModule");
|
|
13
|
+
Object.defineProperty(exports, "LifeCycleModule", { enumerable: true, get: function () { return LifeCycleModule_1.LifeCycleModule; } });
|
|
14
|
+
const FastCarApplication_1 = require("./FastCarApplication");
|
|
15
|
+
exports.FastCarApplication = FastCarApplication_1.default;
|
|
16
|
+
const Logger_1 = require("./interface/Logger");
|
|
17
|
+
exports.Logger = Logger_1.default;
|
|
18
|
+
const DataMap_1 = require("./model/DataMap");
|
|
19
|
+
exports.DataMap = DataMap_1.default;
|
|
20
|
+
const ValidError_1 = require("./model/ValidError");
|
|
21
|
+
exports.ValidError = ValidError_1.default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class Logger {
|
|
4
|
-
}
|
|
5
|
-
exports.default = Logger;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Logger {
|
|
4
|
+
}
|
|
5
|
+
exports.default = Logger;
|
|
@@ -1,98 +1,103 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const DesignMeta_1 = require("../type/DesignMeta");
|
|
4
|
-
const DataFormat_1 = require("../utils/DataFormat");
|
|
5
|
-
class BaseMapper {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.mappingMap.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const DesignMeta_1 = require("../type/DesignMeta");
|
|
4
|
+
const DataFormat_1 = require("../utils/DataFormat");
|
|
5
|
+
class BaseMapper {
|
|
6
|
+
tableName;
|
|
7
|
+
classZ; //映射的原型类
|
|
8
|
+
mappingMap; //代码别名-映射关系
|
|
9
|
+
mappingList;
|
|
10
|
+
dbFields; //数据库别名-代码别名
|
|
11
|
+
/***
|
|
12
|
+
* @version 1.0 对于类型做一个转换
|
|
13
|
+
*/
|
|
14
|
+
constructor() {
|
|
15
|
+
let tClass = Reflect.getMetadata(DesignMeta_1.DesignMeta.entity, this);
|
|
16
|
+
this.classZ = tClass;
|
|
17
|
+
let tableName = Reflect.getMetadata(DesignMeta_1.DesignMeta.table, tClass);
|
|
18
|
+
if (!tableName) {
|
|
19
|
+
throw new Error(`This class ${tClass.name} has no annotation table name`);
|
|
20
|
+
}
|
|
21
|
+
this.tableName = tableName;
|
|
22
|
+
this.mappingMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.mapping, tClass); //映射关系
|
|
23
|
+
this.dbFields = Reflect.getMetadata(DesignMeta_1.DesignMeta.dbFields, tClass); //作用的列名
|
|
24
|
+
this.mappingList = Array.of();
|
|
25
|
+
this.mappingMap.forEach(item => {
|
|
26
|
+
this.mappingList.push(item);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//获取数据库别名通过代码内的名称
|
|
30
|
+
getFieldName(name) {
|
|
31
|
+
let info = this.mappingMap.get(name);
|
|
32
|
+
return info ? info.field : name;
|
|
33
|
+
}
|
|
34
|
+
setRow(rowData) {
|
|
35
|
+
let t = new this.classZ();
|
|
36
|
+
this.mappingMap.forEach((item, key) => {
|
|
37
|
+
let value = Reflect.get(rowData, item.field) || Reflect.get(rowData, key);
|
|
38
|
+
if (value != null) {
|
|
39
|
+
let fvalue = DataFormat_1.default.formatValue(value, item.type);
|
|
40
|
+
Reflect.set(t, key, fvalue);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return t;
|
|
44
|
+
}
|
|
45
|
+
setRows(rowDataList) {
|
|
46
|
+
let list = Array.of();
|
|
47
|
+
rowDataList.forEach(item => {
|
|
48
|
+
list.push(this.setRow(item));
|
|
49
|
+
});
|
|
50
|
+
return list;
|
|
51
|
+
}
|
|
52
|
+
saveORUpdate(rows, ds, sessionId) {
|
|
53
|
+
throw new Error("Method not implemented.");
|
|
54
|
+
}
|
|
55
|
+
saveOne(row, ds, sessionId) {
|
|
56
|
+
throw new Error("Method not implemented.");
|
|
57
|
+
}
|
|
58
|
+
saveList(rows, ds, sessionId) {
|
|
59
|
+
throw new Error("Method not implemented.");
|
|
60
|
+
}
|
|
61
|
+
update({ row, where, limit }, ds, sessionId) {
|
|
62
|
+
throw new Error("Method not implemented.");
|
|
63
|
+
}
|
|
64
|
+
updateOne(sqlUpdate, ds, sessionId) {
|
|
65
|
+
throw new Error("Method not implemented.");
|
|
66
|
+
}
|
|
67
|
+
updateByPrimaryKey(row, ds, sessionId) {
|
|
68
|
+
throw new Error("Method not implemented.");
|
|
69
|
+
}
|
|
70
|
+
select(conditions, ds, sessionId) {
|
|
71
|
+
throw new Error("Method not implemented.");
|
|
72
|
+
}
|
|
73
|
+
/***
|
|
74
|
+
* @version 1.0 查询单个对象
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
async selectOne(conditions, ds, sessionId) {
|
|
78
|
+
throw new Error("Method not implemented.");
|
|
79
|
+
}
|
|
80
|
+
/***
|
|
81
|
+
* @version 1.0 通过主键查找对象
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
async selectByPrimaryKey(row, ds, sessionId) {
|
|
85
|
+
throw new Error("Method not implemented.");
|
|
86
|
+
}
|
|
87
|
+
exist(where, ds, sessionId) {
|
|
88
|
+
throw new Error("Method not implemented.");
|
|
89
|
+
}
|
|
90
|
+
count(where, ds, sessionId) {
|
|
91
|
+
throw new Error("Method not implemented.");
|
|
92
|
+
}
|
|
93
|
+
delete(conditions, ds, sessionId) {
|
|
94
|
+
throw new Error("Method not implemented.");
|
|
95
|
+
}
|
|
96
|
+
deleteOne(where, ds, sessionId) {
|
|
97
|
+
throw new Error("Method not implemented.");
|
|
98
|
+
}
|
|
99
|
+
deleteByPrimaryKey(row, ds, sessionId) {
|
|
100
|
+
throw new Error("Method not implemented.");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.default = BaseMapper;
|
package/target/model/DataMap.js
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class DataMap extends Map {
|
|
4
|
-
constructor() {
|
|
5
|
-
super();
|
|
6
|
-
}
|
|
7
|
-
toValues() {
|
|
8
|
-
return [...this.values()];
|
|
9
|
-
}
|
|
10
|
-
toKeys() {
|
|
11
|
-
return [...this.keys()];
|
|
12
|
-
}
|
|
13
|
-
toObject() {
|
|
14
|
-
let o = {};
|
|
15
|
-
this.forEach((v, k) => {
|
|
16
|
-
Reflect.set(o, k, v);
|
|
17
|
-
});
|
|
18
|
-
return o;
|
|
19
|
-
}
|
|
20
|
-
//自定义排序 支持多个排序
|
|
21
|
-
sort(sorts, list) {
|
|
22
|
-
list = !list ? this.toValues() : list;
|
|
23
|
-
if (!sorts || sorts?.length == 0) {
|
|
24
|
-
return list;
|
|
25
|
-
}
|
|
26
|
-
let total = sorts.length;
|
|
27
|
-
list.sort((a, b) => {
|
|
28
|
-
let resultNum = 0;
|
|
29
|
-
sorts.some((f, index) => {
|
|
30
|
-
let field = f.field;
|
|
31
|
-
let aValue = Reflect.get(a, field);
|
|
32
|
-
let bValue = Reflect.get(b, field);
|
|
33
|
-
let flag = f.compare ? f.compare(aValue, bValue) : aValue > bValue;
|
|
34
|
-
resultNum = flag ? total - index : index - total;
|
|
35
|
-
//降序则倒着
|
|
36
|
-
if (f.order) {
|
|
37
|
-
resultNum = -resultNum;
|
|
38
|
-
}
|
|
39
|
-
return !!flag;
|
|
40
|
-
});
|
|
41
|
-
return resultNum;
|
|
42
|
-
});
|
|
43
|
-
return list;
|
|
44
|
-
}
|
|
45
|
-
/***
|
|
46
|
-
* @version 1.0 查找属性名称
|
|
47
|
-
* @params atts代表属性键值对匹配
|
|
48
|
-
*
|
|
49
|
-
*/
|
|
50
|
-
findByAtts(atts) {
|
|
51
|
-
let list = [];
|
|
52
|
-
let keys = Object.keys(atts);
|
|
53
|
-
this.forEach((item) => {
|
|
54
|
-
let flag = keys.every((key) => {
|
|
55
|
-
let v = Reflect.get(atts, key);
|
|
56
|
-
//这边判断 是不是一个复合属性
|
|
57
|
-
if (Reflect.has(item, key)) {
|
|
58
|
-
let itemV = Reflect.get(item, key);
|
|
59
|
-
return itemV == v;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
let keyList = key.split(".");
|
|
63
|
-
if (keyList.length > 1) {
|
|
64
|
-
let tmpV = item;
|
|
65
|
-
let f = keyList.every((tk) => {
|
|
66
|
-
if (!Reflect.has(tmpV, tk)) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
tmpV = Reflect.get(tmpV, tk);
|
|
70
|
-
return true;
|
|
71
|
-
});
|
|
72
|
-
if (!f) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return tmpV == v;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return false;
|
|
79
|
-
});
|
|
80
|
-
if (flag) {
|
|
81
|
-
list.push(item);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return list;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.default = DataMap;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class DataMap extends Map {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
}
|
|
7
|
+
toValues() {
|
|
8
|
+
return [...this.values()];
|
|
9
|
+
}
|
|
10
|
+
toKeys() {
|
|
11
|
+
return [...this.keys()];
|
|
12
|
+
}
|
|
13
|
+
toObject() {
|
|
14
|
+
let o = {};
|
|
15
|
+
this.forEach((v, k) => {
|
|
16
|
+
Reflect.set(o, k, v);
|
|
17
|
+
});
|
|
18
|
+
return o;
|
|
19
|
+
}
|
|
20
|
+
//自定义排序 支持多个排序
|
|
21
|
+
sort(sorts, list) {
|
|
22
|
+
list = !list ? this.toValues() : list;
|
|
23
|
+
if (!sorts || sorts?.length == 0) {
|
|
24
|
+
return list;
|
|
25
|
+
}
|
|
26
|
+
let total = sorts.length;
|
|
27
|
+
list.sort((a, b) => {
|
|
28
|
+
let resultNum = 0;
|
|
29
|
+
sorts.some((f, index) => {
|
|
30
|
+
let field = f.field;
|
|
31
|
+
let aValue = Reflect.get(a, field);
|
|
32
|
+
let bValue = Reflect.get(b, field);
|
|
33
|
+
let flag = f.compare ? f.compare(aValue, bValue) : aValue > bValue;
|
|
34
|
+
resultNum = flag ? total - index : index - total;
|
|
35
|
+
//降序则倒着
|
|
36
|
+
if (f.order) {
|
|
37
|
+
resultNum = -resultNum;
|
|
38
|
+
}
|
|
39
|
+
return !!flag;
|
|
40
|
+
});
|
|
41
|
+
return resultNum;
|
|
42
|
+
});
|
|
43
|
+
return list;
|
|
44
|
+
}
|
|
45
|
+
/***
|
|
46
|
+
* @version 1.0 查找属性名称
|
|
47
|
+
* @params atts代表属性键值对匹配
|
|
48
|
+
*
|
|
49
|
+
*/
|
|
50
|
+
findByAtts(atts) {
|
|
51
|
+
let list = [];
|
|
52
|
+
let keys = Object.keys(atts);
|
|
53
|
+
this.forEach((item) => {
|
|
54
|
+
let flag = keys.every((key) => {
|
|
55
|
+
let v = Reflect.get(atts, key);
|
|
56
|
+
//这边判断 是不是一个复合属性
|
|
57
|
+
if (Reflect.has(item, key)) {
|
|
58
|
+
let itemV = Reflect.get(item, key);
|
|
59
|
+
return itemV == v;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
let keyList = key.split(".");
|
|
63
|
+
if (keyList.length > 1) {
|
|
64
|
+
let tmpV = item;
|
|
65
|
+
let f = keyList.every((tk) => {
|
|
66
|
+
if (!Reflect.has(tmpV, tk)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
tmpV = Reflect.get(tmpV, tk);
|
|
70
|
+
return true;
|
|
71
|
+
});
|
|
72
|
+
if (!f) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return tmpV == v;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
});
|
|
80
|
+
if (flag) {
|
|
81
|
+
list.push(item);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return list;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.default = DataMap;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class ValidError extends Error {
|
|
4
|
-
}
|
|
5
|
-
exports.default = ValidError;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ValidError extends Error {
|
|
4
|
+
}
|
|
5
|
+
exports.default = ValidError;
|