@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
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = Application;
|
|
4
|
+
const FastCarApplication_1 = require("../FastCarApplication");
|
|
5
|
+
const ClassUtils_1 = require("../utils/ClassUtils");
|
|
6
|
+
const TypeUtil_1 = require("../utils/TypeUtil");
|
|
7
|
+
//基础服务的应用
|
|
8
|
+
function Application(target) {
|
|
9
|
+
return new Proxy(target, {
|
|
10
|
+
construct: (target, args) => {
|
|
11
|
+
let app = new FastCarApplication_1.default();
|
|
12
|
+
let appProxy = new target(...args);
|
|
13
|
+
Reflect.set(appProxy, "app", app);
|
|
14
|
+
let keys = ClassUtils_1.default.getProtoType(target);
|
|
15
|
+
for (let key of keys) {
|
|
16
|
+
if (key != "constructor") {
|
|
17
|
+
let desc = ClassUtils_1.default.getProtoDesc(target, key);
|
|
18
|
+
if (desc) {
|
|
19
|
+
let beforeFun = Object.getOwnPropertyDescriptor(FastCarApplication_1.default.prototype, key)?.value;
|
|
20
|
+
let afterFun = desc.value;
|
|
21
|
+
if (Reflect.has(app, key) && TypeUtil_1.default.isFunction(afterFun) && TypeUtil_1.default.isFunction(beforeFun)) {
|
|
22
|
+
let mixFn = async (...args) => {
|
|
23
|
+
let res;
|
|
24
|
+
if (TypeUtil_1.default.isPromise(beforeFun)) {
|
|
25
|
+
res = await Promise.resolve(Reflect.apply(beforeFun, app, args));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
res = Reflect.apply(beforeFun, app, args);
|
|
29
|
+
}
|
|
30
|
+
TypeUtil_1.default.isPromise(afterFun) ? await Promise.resolve(Reflect.apply(afterFun, appProxy, args)) : Reflect.apply(afterFun, appProxy, args);
|
|
31
|
+
return res;
|
|
32
|
+
};
|
|
33
|
+
Reflect.defineProperty(app, key, Object.assign(desc, { value: mixFn }));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
Reflect.defineProperty(app, key, desc);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
app.loadLoggerIOC(appProxy);
|
|
42
|
+
app.init();
|
|
43
|
+
return appProxy;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
console.error(`
|
|
9
|
-
console.error(`
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
console.error("
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = ExceptionMonitor;
|
|
4
|
+
const process = require("process");
|
|
5
|
+
//异常监听器
|
|
6
|
+
function ExceptionMonitor(target) {
|
|
7
|
+
process.on("uncaughtException", (err, origin) => {
|
|
8
|
+
console.error(`Caught exception: ${err.message}`);
|
|
9
|
+
console.error(`Exception origin: ${origin}`);
|
|
10
|
+
console.error(`stack: ${err.stack}`);
|
|
11
|
+
});
|
|
12
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
13
|
+
console.error("Unhandled Rejection at:", promise);
|
|
14
|
+
console.error("reason:", reason);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddInjectionService = AddInjectionService;
|
|
4
|
+
const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
|
|
5
|
+
function AddInjectionService({ target, propertyKey, kind, alias }) {
|
|
6
|
+
let services = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.InjectionSingleInstance, target);
|
|
7
|
+
if (!services) {
|
|
8
|
+
services = [];
|
|
9
|
+
Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.InjectionSingleInstance, services, target);
|
|
10
|
+
}
|
|
11
|
+
services.push({
|
|
12
|
+
key: propertyKey,
|
|
13
|
+
kind: kind,
|
|
14
|
+
alias,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
iocMap.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
modules
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = AddRequireModule;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
|
|
6
|
+
/***
|
|
7
|
+
* @version 1.0 依赖模块注入
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
function AddRequireModule(target, m, alias) {
|
|
11
|
+
let relyname = FastCarMetaData_1.FastCarMetaData.IocModule;
|
|
12
|
+
if (Reflect.hasMetadata(relyname, target)) {
|
|
13
|
+
let iocMap = Reflect.getMetadata(relyname, target);
|
|
14
|
+
iocMap.set(m, alias);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
let modules = new Map();
|
|
18
|
+
modules.set(m, alias);
|
|
19
|
+
Reflect.defineMetadata(relyname, modules, target);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
exports.default = AliasInjection;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = AliasInjection;
|
|
4
|
+
const ComponentDesc_1 = require("../../type/ComponentDesc");
|
|
5
|
+
const AddInjectionService_1 = require("./AddInjectionService");
|
|
6
|
+
/***
|
|
7
|
+
* @version 1.0 根据别名注入依赖
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
function AliasInjection(alias) {
|
|
11
|
+
return function (target, propertyKey) {
|
|
12
|
+
(0, AddInjectionService_1.AddInjectionService)({
|
|
13
|
+
target,
|
|
14
|
+
propertyKey,
|
|
15
|
+
alias,
|
|
16
|
+
kind: ComponentDesc_1.InjectionType.ALIAS,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @version 1.
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = Autowired;
|
|
4
|
+
const CallDependency_1 = require("./CallDependency");
|
|
5
|
+
/***
|
|
6
|
+
* @version 1.0 说明哪些模块需要被加载
|
|
7
|
+
* @version 1.1 更改为和call类型一致
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
function Autowired(target, propertyKey) {
|
|
11
|
+
// //反向找设计类型
|
|
12
|
+
(0, CallDependency_1.default)(target, propertyKey);
|
|
13
|
+
}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
throw injectionError;
|
|
18
|
-
}
|
|
19
|
-
return app.getComponentByName(key);
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.default = CallDependency;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = CallDependency;
|
|
4
|
+
const ComponentDesc_1 = require("../../type/ComponentDesc");
|
|
5
|
+
const AddInjectionService_1 = require("./AddInjectionService");
|
|
6
|
+
/***
|
|
7
|
+
* @version 1.0 在使用该函数时进行调用 声明的类可以不是组件
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
function CallDependency(target, propertyKey) {
|
|
11
|
+
(0, AddInjectionService_1.AddInjectionService)({
|
|
12
|
+
target,
|
|
13
|
+
propertyKey,
|
|
14
|
+
kind: ComponentDesc_1.InjectionType.PROPERTYKEY,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DemandInjection;
|
|
4
|
+
//延迟注入作用用于类上,用于没有初始时的依赖注入
|
|
5
|
+
const CommonConstant_1 = require("../../constant/CommonConstant");
|
|
6
|
+
function DemandInjection(Target) {
|
|
7
|
+
return new Proxy(Target, {
|
|
8
|
+
construct: (Target, args) => {
|
|
9
|
+
let c = new Target(...args);
|
|
10
|
+
let app = Reflect.get(global, CommonConstant_1.CommonConstant.FastcarApp);
|
|
11
|
+
app?.loadInjectionService(c);
|
|
12
|
+
return c;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DBType;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const DesignMeta_1 = require("../../type/DesignMeta");
|
|
6
|
+
//字段名称 如果没有则为统一
|
|
7
|
+
function DBType(name) {
|
|
8
|
+
return function (target, propertyKey) {
|
|
9
|
+
Reflect.defineMetadata(DesignMeta_1.DesignMeta.dbType, name, target, propertyKey);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DS;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
|
|
6
|
+
const ClassUtils_1 = require("../../utils/ClassUtils");
|
|
7
|
+
const TypeUtil_1 = require("../../utils/TypeUtil");
|
|
8
|
+
const ValidationUtil_1 = require("../../utils/ValidationUtil");
|
|
9
|
+
//动态数据源获取 根据就近原则 传入参数-函数-类名
|
|
10
|
+
function DS(name) {
|
|
11
|
+
return function (target, methodName, descriptor) {
|
|
12
|
+
if (methodName && descriptor) {
|
|
13
|
+
const orignFunction = descriptor.value;
|
|
14
|
+
//定义数据源
|
|
15
|
+
Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.DS, name, target, methodName);
|
|
16
|
+
//取出ds标记的位置 在编译前规避这个问题
|
|
17
|
+
const dsIndex = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.DSIndex, target, methodName);
|
|
18
|
+
if (!ValidationUtil_1.default.isNumber(dsIndex)) {
|
|
19
|
+
throw new Error(`${methodName} function dynamic data source not found`);
|
|
20
|
+
}
|
|
21
|
+
descriptor.value = function (...args) {
|
|
22
|
+
let dsName = args[dsIndex];
|
|
23
|
+
if (!dsName) {
|
|
24
|
+
args[dsIndex] = name;
|
|
25
|
+
}
|
|
26
|
+
return Promise.resolve(Reflect.apply(orignFunction, this, args));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.DS, name, target.prototype);
|
|
31
|
+
//找所有的方法 将符合要求的进行注入定义
|
|
32
|
+
let targetProto = target.prototype;
|
|
33
|
+
let keys = ClassUtils_1.default.getProtoType(target);
|
|
34
|
+
for (let key of keys) {
|
|
35
|
+
let dsIndex = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.DSIndex, targetProto, key);
|
|
36
|
+
if (ValidationUtil_1.default.isNumber(dsIndex)) {
|
|
37
|
+
let originValue = Reflect.get(targetProto, key);
|
|
38
|
+
if (TypeUtil_1.default.isFunction(originValue)) {
|
|
39
|
+
Reflect.defineProperty(targetProto, key, {
|
|
40
|
+
value: function (...args) {
|
|
41
|
+
let dsName = args[dsIndex];
|
|
42
|
+
if (!dsName) {
|
|
43
|
+
let fnDSName = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.DS, targetProto, key);
|
|
44
|
+
args[dsIndex] = fnDSName || name;
|
|
45
|
+
}
|
|
46
|
+
return Promise.resolve(Reflect.apply(originValue, this, args));
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DSIndex;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
|
|
6
|
+
//用于标记数据源位置
|
|
7
|
+
function DSIndex(target, name, index) {
|
|
8
|
+
Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.DSIndex, index, target, name);
|
|
9
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = Entity;
|
|
4
|
+
const DesignMeta_1 = require("../../type/DesignMeta");
|
|
5
|
+
//这是一个模板类 代表具体的映射关系
|
|
6
|
+
function Entity(className) {
|
|
7
|
+
return function (target) {
|
|
8
|
+
Reflect.defineMetadata(DesignMeta_1.DesignMeta.entity, className, target.prototype);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = Field;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const DesignMeta_1 = require("../../type/DesignMeta");
|
|
6
|
+
//数据库列名称
|
|
7
|
+
function Field(name) {
|
|
8
|
+
return function (target, propertyKey) {
|
|
9
|
+
let fieldMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.fieldMap, target);
|
|
10
|
+
if (!fieldMap) {
|
|
11
|
+
Reflect.defineMetadata(DesignMeta_1.DesignMeta.fieldMap, new Set([propertyKey]), target);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
fieldMap.add(propertyKey);
|
|
15
|
+
}
|
|
16
|
+
Reflect.defineMetadata(DesignMeta_1.DesignMeta.field, name, target, propertyKey);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = PrimaryKey;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const DesignMeta_1 = require("../../type/DesignMeta");
|
|
6
|
+
//是否为主键
|
|
7
|
+
function PrimaryKey(target, propertyKey) {
|
|
8
|
+
Reflect.defineMetadata(DesignMeta_1.DesignMeta.primaryKey, true, target, propertyKey);
|
|
9
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = SqlSession;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const DesignMeta_1 = require("../../type/DesignMeta");
|
|
6
|
+
//事务管理会话
|
|
7
|
+
function SqlSession(target, name, index) {
|
|
8
|
+
Reflect.defineMetadata(DesignMeta_1.DesignMeta.sqlSession, index, target, name);
|
|
9
|
+
}
|