@fastcar/core 0.2.39 → 0.2.40
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/index.d.ts +5 -0
- package/package.json +1 -1
- package/src/FastCarApplication.ts +2 -2
- package/src/annotation/bind/AliasInjection.ts +2 -2
- package/src/annotation/data/Transactional.ts +3 -3
- package/src/annotation/stereotype/Log.ts +2 -2
- package/src/interface/ApplicationInterface.ts +206 -0
- package/target/FastCarApplication.js +1 -1
- package/target/interface/ApplicationInterface.js +2 -0
- package/test/example/logs/[fastcar-server] logger.log +3 -0
- package/test/example/logs/[fastcar-server] sys1.log +8 -0
- package/test/example/logs/sys.log +0 -2
- package/test/example/logs/sys1.log +0 -0
package/index.d.ts
CHANGED
|
@@ -149,6 +149,11 @@ export class FastCarApplication extends Events {
|
|
|
149
149
|
*/
|
|
150
150
|
getComponentDetailsList(): ComponentDesc[];
|
|
151
151
|
|
|
152
|
+
/**
|
|
153
|
+
* @version 1.0 判断组件是否存在
|
|
154
|
+
*/
|
|
155
|
+
hasComponentByName(name: string | symbol): boolean;
|
|
156
|
+
|
|
152
157
|
/**
|
|
153
158
|
* @version 1.0 开启日志系统
|
|
154
159
|
*/
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
+
import * as fs from "fs";
|
|
2
3
|
import * as process from "process";
|
|
3
4
|
import * as Events from "events";
|
|
4
5
|
import * as path from "path";
|
|
@@ -12,7 +13,6 @@ import { ApplicationConfig } from "./config/ApplicationConfig";
|
|
|
12
13
|
import { ComponentKind } from "./constant/ComponentKind";
|
|
13
14
|
import { CommonConstant } from "./constant/CommonConstant";
|
|
14
15
|
import { LifeCycleModule } from "./constant/LifeCycleModule";
|
|
15
|
-
import * as fs from "fs";
|
|
16
16
|
import { AppStatusEnum } from "./constant/AppStatusEnum";
|
|
17
17
|
import ValidationUtil from "./utils/ValidationUtil";
|
|
18
18
|
import Component from "./annotation/stereotype/Component";
|
|
@@ -473,7 +473,7 @@ class FastCarApplication extends Events {
|
|
|
473
473
|
/***
|
|
474
474
|
* @version 1.0 判断是否拥有组件名称
|
|
475
475
|
*/
|
|
476
|
-
hasComponentByName(name: string | symbol):
|
|
476
|
+
hasComponentByName(name: string | symbol): boolean {
|
|
477
477
|
return this.componentMap.has(name);
|
|
478
478
|
}
|
|
479
479
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonConstant } from "../../constant/CommonConstant";
|
|
2
|
-
import
|
|
2
|
+
import ApplicationInterface from "../../interface/ApplicationInterface";
|
|
3
3
|
|
|
4
4
|
/***
|
|
5
5
|
* @version 1.0 根据别名注入依赖
|
|
@@ -9,7 +9,7 @@ export default function AliasInjection(alias: string) {
|
|
|
9
9
|
return function (target: any, propertyKey: string) {
|
|
10
10
|
Reflect.defineProperty(target, propertyKey, {
|
|
11
11
|
get: () => {
|
|
12
|
-
let app:
|
|
12
|
+
let app: ApplicationInterface = Reflect.get(global, CommonConstant.FastcarApp);
|
|
13
13
|
|
|
14
14
|
if (!app.hasComponentByName(alias)) {
|
|
15
15
|
//找不到依赖组件异常
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { CommonConstant } from "../../constant/CommonConstant";
|
|
3
|
-
import
|
|
3
|
+
import ApplicationInterface from "../../interface/ApplicationInterface";
|
|
4
4
|
import DataSourceManager from "../../interface/DataSourceManager";
|
|
5
5
|
import Logger from "../../interface/Logger";
|
|
6
6
|
import { DesignMeta } from "../../type/DesignMeta";
|
|
@@ -11,7 +11,7 @@ import SqlError from "../../type/SqlError";
|
|
|
11
11
|
* */
|
|
12
12
|
export default function Transactional(driver: string = "MysqlDataSourceManager") {
|
|
13
13
|
return function (target: any, methodName: string, descriptor: PropertyDescriptor) {
|
|
14
|
-
const orignFunction = descriptor.value;
|
|
14
|
+
const orignFunction: Function = descriptor.value;
|
|
15
15
|
|
|
16
16
|
//在初始化时就应该检测是否注入了sessionID
|
|
17
17
|
const paramsIndex = Reflect.getOwnMetadata(DesignMeta.sqlSession, target, methodName);
|
|
@@ -22,7 +22,7 @@ export default function Transactional(driver: string = "MysqlDataSourceManager")
|
|
|
22
22
|
descriptor.value = async function (...args: any[]) {
|
|
23
23
|
//创建会话id
|
|
24
24
|
|
|
25
|
-
let app:
|
|
25
|
+
let app: ApplicationInterface = Reflect.get(global, CommonConstant.FastcarApp);
|
|
26
26
|
|
|
27
27
|
let sysLogger: Logger = app.getSysLogger() || console;
|
|
28
28
|
let dsm: DataSourceManager = app.getComponentByName(driver);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonConstant } from "../../constant/CommonConstant";
|
|
2
|
-
import
|
|
2
|
+
import ApplicationInterface from "../../interface/ApplicationInterface";
|
|
3
3
|
import Logger from "../../interface/Logger";
|
|
4
4
|
|
|
5
5
|
//日志实例
|
|
@@ -9,7 +9,7 @@ export default function Log(category?: string) {
|
|
|
9
9
|
|
|
10
10
|
Reflect.defineProperty(target, propertyKey, {
|
|
11
11
|
get: (): Logger => {
|
|
12
|
-
let app:
|
|
12
|
+
let app: ApplicationInterface = Reflect.get(global, CommonConstant.FastcarApp);
|
|
13
13
|
let appid = app.getSetting(CommonConstant.APPId) || ""; //进行差异化区分
|
|
14
14
|
return app ? app.getLogger(appid ? `[${appid}] ${m}` : m) : console;
|
|
15
15
|
},
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { ApplicationConfig } from "../config/ApplicationConfig";
|
|
2
|
+
import { ComponentKind } from "../constant/ComponentKind";
|
|
3
|
+
import { LifeCycleModule } from "../constant/LifeCycleModule";
|
|
4
|
+
import { ComponentDesc } from "../type/ComponentDesc";
|
|
5
|
+
import { ProcessType } from "../type/ProcessType";
|
|
6
|
+
import Logger from "./Logger";
|
|
7
|
+
|
|
8
|
+
export default interface ApplicationInterface {
|
|
9
|
+
/***
|
|
10
|
+
* @version 1.0 根据原型加载注入的方法
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
getInjectionUniqueKey(target: Object): string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @version 1.0 自身作为一个组件注入进去
|
|
17
|
+
*/
|
|
18
|
+
loadSelf(): void;
|
|
19
|
+
|
|
20
|
+
/***
|
|
21
|
+
* @version 1.0 热更新组件
|
|
22
|
+
*/
|
|
23
|
+
addHot(): void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @version 1.0 获取资源路径
|
|
27
|
+
*/
|
|
28
|
+
getResourcePath(): string;
|
|
29
|
+
|
|
30
|
+
/***
|
|
31
|
+
* @version 1.0 获取项目的基本路径
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
getBasePath(): string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @version 1.0 加载系统配置 加载顺序为 default json < yaml < env
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
loadSysConfig(): void;
|
|
41
|
+
|
|
42
|
+
setSetting(key: string | symbol, value: any): void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @version 1.0 获取自定义设置 设置优先级 配置自定义>系统配置>初始化
|
|
46
|
+
* @param key
|
|
47
|
+
*/
|
|
48
|
+
getSetting(key: string | symbol): any;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @version 1.0 获取应用配置
|
|
52
|
+
* @return
|
|
53
|
+
*/
|
|
54
|
+
getapplicationConfig(): ApplicationConfig;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @version 1.0 扫描组件
|
|
58
|
+
*/
|
|
59
|
+
loadClass(): void;
|
|
60
|
+
|
|
61
|
+
/***
|
|
62
|
+
* @version 1.0 装配单个模块
|
|
63
|
+
* @deprecated 修改为主动查找时装配
|
|
64
|
+
*/
|
|
65
|
+
injectionModule(instance: any, instanceName: string | symbol): void;
|
|
66
|
+
|
|
67
|
+
/***
|
|
68
|
+
* @version 1.0 根据名称获取组件的加载情况
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
getComponentDetailByName(name: string | symbol): ComponentDesc | undefined;
|
|
72
|
+
|
|
73
|
+
/***
|
|
74
|
+
* @version 1.0 根据原型获取组件的加载信息
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
getComponentDetailByTarget(target: Object): ComponentDesc | undefined;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @version 1.0 加载需要注入的类
|
|
81
|
+
* @deprecated 修改为主动查找时装配
|
|
82
|
+
*/
|
|
83
|
+
loadInjectionModule(): void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @version 1.0 根据类型获取组件
|
|
87
|
+
* @param name
|
|
88
|
+
* @return
|
|
89
|
+
*/
|
|
90
|
+
getComponentByType(name: ComponentKind): any[];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @version 1.0 获取全部的组件列表
|
|
94
|
+
* @return
|
|
95
|
+
*/
|
|
96
|
+
getComponentList(): any[];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @version 1.0 根据名称组件
|
|
100
|
+
* @param name
|
|
101
|
+
*/
|
|
102
|
+
getComponentByName(name: string | symbol): any;
|
|
103
|
+
|
|
104
|
+
/***
|
|
105
|
+
* @version 1.0 根据原型获取实例
|
|
106
|
+
*/
|
|
107
|
+
getComponentByTarget(target: Object): any;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @version 1.0 获取组件详情列表
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
getComponentDetailsList(): ComponentDesc[];
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @version 1.0 判断组件是否存在
|
|
117
|
+
*/
|
|
118
|
+
hasComponentByName(name: string | symbol): boolean;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @version 1.0 开启日志系统
|
|
122
|
+
*/
|
|
123
|
+
startLog(): void;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @version 1.0 初始化应用
|
|
127
|
+
*/
|
|
128
|
+
init(): void;
|
|
129
|
+
|
|
130
|
+
/***
|
|
131
|
+
* @version 1.0 退出事件监听
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
addExitEvent(): void;
|
|
135
|
+
|
|
136
|
+
/***
|
|
137
|
+
* @version 1.0 异常事件进行监听 不至于程序异常直接退出
|
|
138
|
+
*/
|
|
139
|
+
addExecptionEvent(): void;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @version 1.0 自动调用方法
|
|
143
|
+
* @param name
|
|
144
|
+
*/
|
|
145
|
+
automaticRun(name: LifeCycleModule): void;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @version 1.0 开启应用前执行的操作 加载配置,扫描组件,注入依赖组件
|
|
149
|
+
*/
|
|
150
|
+
beforeStartServer(): void;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @version 1.0 启动服务
|
|
154
|
+
*/
|
|
155
|
+
startServer(): void;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @version 1.0 停止服务前自动调用服务
|
|
159
|
+
*/
|
|
160
|
+
beforeStopServer(): void;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @version 1.0 停止服务
|
|
164
|
+
*/
|
|
165
|
+
stopServer(): void;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @version 1.0 获取app名称
|
|
169
|
+
*/
|
|
170
|
+
getApplicationName(): string;
|
|
171
|
+
|
|
172
|
+
/***
|
|
173
|
+
* @version 1.0 获取系统日志
|
|
174
|
+
*
|
|
175
|
+
*/
|
|
176
|
+
getSysLogger(): Logger;
|
|
177
|
+
|
|
178
|
+
/***
|
|
179
|
+
* @version 0.2.11 根据名称获取logger
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
getLogger(category?: string): Logger;
|
|
183
|
+
|
|
184
|
+
/***
|
|
185
|
+
* @version 1.0 获取文件内容
|
|
186
|
+
*/
|
|
187
|
+
getFileContent(fp: string): string;
|
|
188
|
+
|
|
189
|
+
/***
|
|
190
|
+
* @version 1.0 是否支持热更
|
|
191
|
+
*
|
|
192
|
+
*/
|
|
193
|
+
isHotter(): boolean;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @version 1.0 指定热更新文件
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
specifyHotUpdate(fp: string): void;
|
|
200
|
+
|
|
201
|
+
/***
|
|
202
|
+
* @version 1.0 获取进程的信息
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
getMemoryUsage(): ProcessType;
|
|
206
|
+
}
|
|
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var FastCarApplication_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
require("reflect-metadata");
|
|
14
|
+
const fs = require("fs");
|
|
14
15
|
const process = require("process");
|
|
15
16
|
const Events = require("events");
|
|
16
17
|
const path = require("path");
|
|
@@ -22,7 +23,6 @@ const SysConfig_1 = require("./config/SysConfig");
|
|
|
22
23
|
const FastCarMetaData_1 = require("./constant/FastCarMetaData");
|
|
23
24
|
const CommonConstant_1 = require("./constant/CommonConstant");
|
|
24
25
|
const LifeCycleModule_1 = require("./constant/LifeCycleModule");
|
|
25
|
-
const fs = require("fs");
|
|
26
26
|
const AppStatusEnum_1 = require("./constant/AppStatusEnum");
|
|
27
27
|
const ValidationUtil_1 = require("./utils/ValidationUtil");
|
|
28
28
|
const Component_1 = require("./annotation/stereotype/Component");
|
|
@@ -4,3 +4,6 @@
|
|
|
4
4
|
{"timestamp":"2022-12-21 18:00:16.672","level":"INFO","label":"[fastcar-server] logger","message":"自定义的日志输出"}
|
|
5
5
|
{"timestamp":"2022-12-21 18:00:16.673","level":"WARN","label":"[fastcar-server] logger","message":"自定义警告"}
|
|
6
6
|
{"timestamp":"2022-12-21 18:00:16.674","level":"ERROR","label":"[fastcar-server] logger","message":"自定义报错"}
|
|
7
|
+
{"timestamp":"2023-01-04 16:48:09.670","level":"INFO","label":"[fastcar-server] logger","message":"自定义的日志输出"}
|
|
8
|
+
{"timestamp":"2023-01-04 16:48:09.671","level":"WARN","label":"[fastcar-server] logger","message":"自定义警告"}
|
|
9
|
+
{"timestamp":"2023-01-04 16:48:09.672","level":"ERROR","label":"[fastcar-server] logger","message":"自定义报错"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{"timestamp":"2023-01-04 16:48:09.561","level":"INFO","label":"[fastcar-server] sys","message":"Start scanning component"}
|
|
2
|
+
{"timestamp":"2023-01-04 16:48:09.655","level":"INFO","label":"[fastcar-server] sys","message":"Complete component scan"}
|
|
3
|
+
{"timestamp":"2023-01-04 16:48:09.657","level":"INFO","label":"[fastcar-server] sys","message":"Call application initialization method"}
|
|
4
|
+
{"timestamp":"2023-01-04 16:48:09.660","level":"INFO","label":"[fastcar-server] sys","message":"start server app is run"}
|
|
5
|
+
{"timestamp":"2023-01-04 16:48:09.660","level":"INFO","label":"[fastcar-server] sys","message":"version 1.0.0"}
|
|
6
|
+
{"timestamp":"2023-01-04 16:48:11.690","level":"INFO","label":"[fastcar-server] sys","message":"exit reason","splat":"[\"beforeExit exit\"]"}
|
|
7
|
+
{"timestamp":"2023-01-04 16:48:11.691","level":"INFO","label":"[fastcar-server] sys","message":"Call the method before the application stops"}
|
|
8
|
+
{"timestamp":"2023-01-04 16:48:16.703","level":"INFO","label":"[fastcar-server] sys","message":"application stop"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
{"timestamp":"2022-12-21 18:00:16.682","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":"2022-12-21 18:00:16.690","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)"}
|
|
File without changes
|