@fastcar/core 0.3.16 → 0.3.17

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.
Files changed (35) hide show
  1. package/annotation.d.ts +3 -0
  2. package/index.d.ts +6 -0
  3. package/package.json +1 -1
  4. package/src/FastCarApplication.ts +78 -0
  5. package/src/annotation/Application.ts +4 -1
  6. package/src/annotation/bind/DemandInjection.ts +16 -1
  7. package/src/annotation/scan/HotterDemand.ts +10 -0
  8. package/src/annotation.ts +2 -0
  9. package/src/constant/FastCarMetaData.ts +1 -0
  10. package/src/type/FileHotterDesc.ts +1 -0
  11. package/src/utils/ClassUtils.ts +9 -0
  12. package/target/FastCarApplication.js +68 -0
  13. package/target/annotation/Application.js +3 -1
  14. package/target/annotation/bind/DemandInjection.js +13 -1
  15. package/target/annotation/scan/HotterDemand.js +12 -0
  16. package/target/annotation.js +4 -2
  17. package/target/constant/FastCarMetaData.js +1 -0
  18. package/target/type/FileHotterDesc.js +1 -0
  19. package/target/utils/ClassUtils.js +8 -0
  20. package/test/example/logs/fastcar-server.sys10.log +13 -0
  21. package/test/example/logs/fastcar-server.sys11.log +6 -0
  22. package/test/example/logs/fastcar-server.sys2.log +8 -0
  23. package/test/example/logs/fastcar-server.sys3.log +13 -0
  24. package/test/example/logs/fastcar-server.sys4.log +8 -0
  25. package/test/example/logs/fastcar-server.sys5.log +11 -0
  26. package/test/example/logs/fastcar-server.sys6.log +8 -0
  27. package/test/example/logs/fastcar-server.sys7.log +11 -0
  28. package/test/example/logs/fastcar-server.sys8.log +10 -0
  29. package/test/example/logs/fastcar-server.sys9.log +12 -0
  30. package/test/example/logs/other-server.sys.log +5 -0
  31. package/test/example/logs/other-server.sys1.log +5 -0
  32. package/test/example/simple/app.ts +14 -0
  33. package/test/example/simple/service/DemandService.ts +10 -0
  34. package/test/example/logs/fastcar-server.sys.log +0 -12
  35. package/test/example/logs/fastcar-server.sys1.log +0 -2
package/annotation.d.ts CHANGED
@@ -75,6 +75,9 @@ export function CallDependency(target: any, propertyKey: string): void;
75
75
  //按需注入加载
76
76
  export function DemandInjection(target: any): any;
77
77
 
78
+ //启用按需加载热更
79
+ export function HotterDemand(fp: string): Ret;
80
+
78
81
  //异常方法类
79
82
  export function ExceptionMonitor(target: any): void;
80
83
 
package/index.d.ts CHANGED
@@ -252,6 +252,12 @@ export class FastCarApplication extends Events {
252
252
  *
253
253
  */
254
254
  getMemoryUsage(): ProcessType;
255
+
256
+ /**
257
+ *
258
+ * @version 0.3.17 删除按需加载实例
259
+ */
260
+ deleteDemandInstance(instance: ClassConstructor<Object> | Object): void;
255
261
  }
256
262
 
257
263
  //校验错误
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastcar/core",
3
- "version": "0.3.16",
3
+ "version": "0.3.17",
4
4
  "homepage": "https://github.com/williamDazhangyu/fast-car",
5
5
  "main": "target/index.js",
6
6
  "author": "william_zhong",
@@ -28,6 +28,7 @@ import { WinstonLoggerType } from "./type/WinstonLoggerType";
28
28
  import { ClassConstructor } from "./type/ClassConstructor";
29
29
  import ReflectUtil from "./utils/ReflectUtil";
30
30
  import Log from "./annotation/stereotype/Log";
31
+ import DataMap from "./model/DataMap";
31
32
 
32
33
  @Component
33
34
  class FastCarApplication extends Events {
@@ -51,6 +52,8 @@ class FastCarApplication extends Events {
51
52
  protected componentAliasMap: Map<string | symbol, string | symbol>;
52
53
  protected hotConfigure: Map<string, string[]>;
53
54
 
55
+ protected demandInstanceMap: DataMap<string, DataMap<string, Set<ClassConstructor<Object> | Object>>>;
56
+
54
57
  constructor() {
55
58
  super();
56
59
 
@@ -65,6 +68,7 @@ class FastCarApplication extends Events {
65
68
  this.componentAliasMap = new Map();
66
69
  this.hotConfigure = new Map();
67
70
 
71
+ this.demandInstanceMap = new DataMap();
68
72
  this.sysLogger = console;
69
73
 
70
74
  this.loadSelf();
@@ -115,6 +119,14 @@ class FastCarApplication extends Events {
115
119
  this.on(HotReloadEnum.configReload, (fp: string) => {
116
120
  this.addDelayHot(fp, HotReloadEnum.configReload);
117
121
  });
122
+
123
+ this.on(HotReloadEnum.demandload, (fp: string) => {
124
+ if (this.applicationStatus != AppStatusEnum.RUN) {
125
+ return;
126
+ }
127
+
128
+ this.addDelayHot(fp, HotReloadEnum.demandload);
129
+ });
118
130
  }
119
131
 
120
132
  addDelayHot(fp: string, loadType: HotReloadEnum) {
@@ -161,6 +173,30 @@ class FastCarApplication extends Events {
161
173
  }
162
174
  break;
163
175
  }
176
+ case HotReloadEnum.demandload: {
177
+ let moduleClass = ClassLoader.loadModule(fp, true);
178
+ if (moduleClass != null) {
179
+ moduleClass.forEach((classZ) => {
180
+ let m = this.demandInstanceMap.get(fp);
181
+ if (m) {
182
+ let key = classZ.name;
183
+ if (key) {
184
+ let instances = m.get(key);
185
+ if (instances) {
186
+ instances.forEach((beforeInstance) => {
187
+ MixTool.assign(beforeInstance, classZ);
188
+ let cb = Reflect.getMetadata(FastCarMetaData.HotterCallback, classZ.prototype);
189
+ if (cb && Reflect.has(beforeInstance, cb)) {
190
+ Reflect.apply(Reflect.get(beforeInstance, cb), beforeInstance, []);
191
+ }
192
+ });
193
+ }
194
+ }
195
+ }
196
+ });
197
+ }
198
+ break;
199
+ }
164
200
  default: {
165
201
  this.sysLogger.warn(`not found ${loadType} by ${fp}`);
166
202
  break;
@@ -923,6 +959,48 @@ class FastCarApplication extends Events {
923
959
 
924
960
  return logger;
925
961
  }
962
+
963
+ addClassHot(fp: string, instance: ClassConstructor<Object> | Object, key: string) {
964
+ ClassLoader.watchServices(fp, this, HotReloadEnum.demandload);
965
+
966
+ let m = this.demandInstanceMap.get(fp);
967
+ if (!m) {
968
+ m = new DataMap();
969
+ this.demandInstanceMap.set(fp, m);
970
+ }
971
+
972
+ let methods = m.get(key);
973
+ if (!methods) {
974
+ methods = new Set();
975
+ m.set(key, methods);
976
+ }
977
+
978
+ methods.add(instance);
979
+ }
980
+
981
+ deleteDemandInstance(instance: ClassConstructor<Object> | Object) {
982
+ let fp = Reflect.getMetadata(FastCarMetaData.HotterFilePath, instance);
983
+ if (fp) {
984
+ let m = this.demandInstanceMap.get(fp);
985
+ if (m) {
986
+ let key = instance.constructor.name;
987
+ if (key) {
988
+ let instances = m.get(key);
989
+ if (instances && instances?.size > 0) {
990
+ instances.delete(instance);
991
+ }
992
+
993
+ if (instances?.size == 0) {
994
+ m.delete(key);
995
+ }
996
+
997
+ if (m.size == 0) {
998
+ this.demandInstanceMap.delete(fp);
999
+ }
1000
+ }
1001
+ }
1002
+ }
1003
+ }
926
1004
  }
927
1005
 
928
1006
  export default FastCarApplication;
@@ -4,7 +4,7 @@ import TypeUtil from "../utils/TypeUtil";
4
4
 
5
5
  //基础服务的应用
6
6
  export default function Application(target: any) {
7
- return new Proxy(target, {
7
+ const proxy = new Proxy(target, {
8
8
  construct: (target: ClassConstructor<Object>, args: any, newTarget?: any) => {
9
9
  const FastCarApplication = require("../FastCarApplication").default;
10
10
 
@@ -46,4 +46,7 @@ export default function Application(target: any) {
46
46
  return appProxy;
47
47
  },
48
48
  });
49
+
50
+ ClassUtils.cloneMetadata(target, proxy);
51
+ return proxy;
49
52
  }
@@ -1,16 +1,31 @@
1
1
  //延迟注入作用用于类上,用于没有初始时的依赖注入
2
2
  import { CommonConstant } from "../../constant/CommonConstant";
3
+ import { FastCarMetaData } from "../../constant/FastCarMetaData";
3
4
  import { ClassConstructor } from "../../type/ClassConstructor";
5
+ import ClassUtils from "../../utils/ClassUtils";
4
6
 
5
7
  export default function DemandInjection(Target: ClassConstructor<any>) {
6
- return new Proxy(Target, {
8
+ const proxy = new Proxy(Target, {
7
9
  construct: (Target: ClassConstructor<any>, args: any, newTarget?: any) => {
8
10
  let c = Reflect.construct(Target, args, newTarget);
9
11
  let app: any = Reflect.get(global, CommonConstant.FastcarApp);
10
12
 
11
13
  app?.loadInjectionService(c);
12
14
  app?.loadLoggerIOC(c);
15
+
16
+ let hotter = Reflect.getMetadata(FastCarMetaData.HotterFilePath, Target.prototype);
17
+ if (!!hotter) {
18
+ let fp = Reflect.getMetadata(FastCarMetaData.HotterFilePath, Target.prototype);
19
+ if (!!fp) {
20
+ //启用监听
21
+ app?.addClassHot(fp, c, Target.name);
22
+ }
23
+ }
24
+
13
25
  return c;
14
26
  },
15
27
  });
28
+
29
+ ClassUtils.cloneMetadata(Target, proxy);
30
+ return proxy;
16
31
  }
@@ -0,0 +1,10 @@
1
+ import "reflect-metadata";
2
+ import Hotter from "./Hotter";
3
+ import { FastCarMetaData } from "../../constant/FastCarMetaData";
4
+
5
+ export default function HotterDemand(fp: string) {
6
+ return function (target: any) {
7
+ Hotter(target);
8
+ Reflect.defineMetadata(FastCarMetaData.HotterFilePath, fp, target.prototype);
9
+ };
10
+ }
package/src/annotation.ts CHANGED
@@ -55,6 +55,7 @@ import Value from "./annotation/bind/Value";
55
55
  import AppEnv from "./annotation/bind/AppEnv";
56
56
  import HotterCallBack from "./annotation/scan/HotterCallBack";
57
57
  import IsSerial from "./annotation/data/IsSerial";
58
+ import HotterDemand from "./annotation/scan/HotterDemand";
58
59
 
59
60
  //注解暴露出去
60
61
  export {
@@ -100,6 +101,7 @@ export {
100
101
  CustomType,
101
102
  Value,
102
103
  AppEnv,
104
+ HotterDemand,
103
105
  };
104
106
 
105
107
  export {
@@ -19,6 +19,7 @@ export enum FastCarMetaData {
19
19
  ValidCustom = "valid:custom", //自定义校验方式
20
20
  Hotter = "hotter", //是否支持热更
21
21
  HotterCallback = "HotterCallback", //热更回调
22
+ HotterFilePath = "HotterFilePath", //热更的路径 按需加载时的需要
22
23
  InjectionUniqueKey = "injection_uniqueKey",
23
24
  Alias = "alias", //别名
24
25
  LoggerModule = "LoggerModule", //日志模块集合
@@ -7,4 +7,5 @@ export enum HotReloadEnum {
7
7
  reload = "reload",
8
8
  sysReload = "sysReload",
9
9
  configReload = "configReload",
10
+ demandload = "demandload",
10
11
  }
@@ -35,4 +35,13 @@ export default class ClassUtils {
35
35
 
36
36
  return ClassUtils.getProtoDesc(parentObj, key);
37
37
  }
38
+
39
+ //拷贝元数据
40
+ static cloneMetadata(src: any, dst: any): void {
41
+ const keys: any[] = Reflect.getMetadataKeys(src);
42
+ for (const k of keys) {
43
+ const val = Reflect.getMetadata(k, src);
44
+ Reflect.defineMetadata(k, val, dst);
45
+ }
46
+ }
38
47
  }
@@ -32,6 +32,7 @@ const DateUtil_1 = require("./utils/DateUtil");
32
32
  const FileHotterDesc_1 = require("./type/FileHotterDesc");
33
33
  const ReflectUtil_1 = require("./utils/ReflectUtil");
34
34
  const Log_1 = require("./annotation/stereotype/Log");
35
+ const DataMap_1 = require("./model/DataMap");
35
36
  let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends Events {
36
37
  componentMap; //组件键值对
37
38
  sysConfig; //系统配置
@@ -49,6 +50,7 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
49
50
  basename = CommonConstant_1.CommonConstant.Application;
50
51
  componentAliasMap;
51
52
  hotConfigure;
53
+ demandInstanceMap;
52
54
  constructor() {
53
55
  super();
54
56
  this.sysConfig = SysConfig_1.SYSDefaultConfig;
@@ -61,6 +63,7 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
61
63
  this.reloadTimerId = null;
62
64
  this.componentAliasMap = new Map();
63
65
  this.hotConfigure = new Map();
66
+ this.demandInstanceMap = new DataMap_1.default();
64
67
  this.sysLogger = console;
65
68
  this.loadSelf();
66
69
  this.addHot();
@@ -104,6 +107,12 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
104
107
  this.on(FileHotterDesc_1.HotReloadEnum.configReload, (fp) => {
105
108
  this.addDelayHot(fp, FileHotterDesc_1.HotReloadEnum.configReload);
106
109
  });
110
+ this.on(FileHotterDesc_1.HotReloadEnum.demandload, (fp) => {
111
+ if (this.applicationStatus != AppStatusEnum_1.AppStatusEnum.RUN) {
112
+ return;
113
+ }
114
+ this.addDelayHot(fp, FileHotterDesc_1.HotReloadEnum.demandload);
115
+ });
107
116
  }
108
117
  addDelayHot(fp, loadType) {
109
118
  if (this.delayHotIds.has(fp)) {
@@ -148,6 +157,30 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
148
157
  }
149
158
  break;
150
159
  }
160
+ case FileHotterDesc_1.HotReloadEnum.demandload: {
161
+ let moduleClass = ClassLoader_1.default.loadModule(fp, true);
162
+ if (moduleClass != null) {
163
+ moduleClass.forEach((classZ) => {
164
+ let m = this.demandInstanceMap.get(fp);
165
+ if (m) {
166
+ let key = classZ.name;
167
+ if (key) {
168
+ let instances = m.get(key);
169
+ if (instances) {
170
+ instances.forEach((beforeInstance) => {
171
+ Mix_1.default.assign(beforeInstance, classZ);
172
+ let cb = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.HotterCallback, classZ.prototype);
173
+ if (cb && Reflect.has(beforeInstance, cb)) {
174
+ Reflect.apply(Reflect.get(beforeInstance, cb), beforeInstance, []);
175
+ }
176
+ });
177
+ }
178
+ }
179
+ }
180
+ });
181
+ }
182
+ break;
183
+ }
151
184
  default: {
152
185
  this.sysLogger.warn(`not found ${loadType} by ${fp}`);
153
186
  break;
@@ -797,6 +830,41 @@ let FastCarApplication = FastCarApplication_1 = class FastCarApplication extends
797
830
  }
798
831
  return logger;
799
832
  }
833
+ addClassHot(fp, instance, key) {
834
+ ClassLoader_1.default.watchServices(fp, this, FileHotterDesc_1.HotReloadEnum.demandload);
835
+ let m = this.demandInstanceMap.get(fp);
836
+ if (!m) {
837
+ m = new DataMap_1.default();
838
+ this.demandInstanceMap.set(fp, m);
839
+ }
840
+ let methods = m.get(key);
841
+ if (!methods) {
842
+ methods = new Set();
843
+ m.set(key, methods);
844
+ }
845
+ methods.add(instance);
846
+ }
847
+ deleteDemandInstance(instance) {
848
+ let fp = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.HotterFilePath, instance);
849
+ if (fp) {
850
+ let m = this.demandInstanceMap.get(fp);
851
+ if (m) {
852
+ let key = instance.constructor.name;
853
+ if (key) {
854
+ let instances = m.get(key);
855
+ if (instances && instances?.size > 0) {
856
+ instances.delete(instance);
857
+ }
858
+ if (instances?.size == 0) {
859
+ m.delete(key);
860
+ }
861
+ if (m.size == 0) {
862
+ this.demandInstanceMap.delete(fp);
863
+ }
864
+ }
865
+ }
866
+ }
867
+ }
800
868
  };
801
869
  __decorate([
802
870
  (0, Log_1.default)("sys"),
@@ -5,7 +5,7 @@ const ClassUtils_1 = require("../utils/ClassUtils");
5
5
  const TypeUtil_1 = require("../utils/TypeUtil");
6
6
  //基础服务的应用
7
7
  function Application(target) {
8
- return new Proxy(target, {
8
+ const proxy = new Proxy(target, {
9
9
  construct: (target, args, newTarget) => {
10
10
  const FastCarApplication = require("../FastCarApplication").default;
11
11
  let app = new FastCarApplication();
@@ -43,4 +43,6 @@ function Application(target) {
43
43
  return appProxy;
44
44
  },
45
45
  });
46
+ ClassUtils_1.default.cloneMetadata(target, proxy);
47
+ return proxy;
46
48
  }
@@ -3,14 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = DemandInjection;
4
4
  //延迟注入作用用于类上,用于没有初始时的依赖注入
5
5
  const CommonConstant_1 = require("../../constant/CommonConstant");
6
+ const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
7
+ const ClassUtils_1 = require("../../utils/ClassUtils");
6
8
  function DemandInjection(Target) {
7
- return new Proxy(Target, {
9
+ const proxy = new Proxy(Target, {
8
10
  construct: (Target, args, newTarget) => {
9
11
  let c = Reflect.construct(Target, args, newTarget);
10
12
  let app = Reflect.get(global, CommonConstant_1.CommonConstant.FastcarApp);
11
13
  app?.loadInjectionService(c);
12
14
  app?.loadLoggerIOC(c);
15
+ let hotter = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.HotterFilePath, Target.prototype);
16
+ if (!!hotter) {
17
+ let fp = Reflect.getMetadata(FastCarMetaData_1.FastCarMetaData.HotterFilePath, Target.prototype);
18
+ if (!!fp) {
19
+ //启用监听
20
+ app?.addClassHot(fp, c, Target.name);
21
+ }
22
+ }
13
23
  return c;
14
24
  },
15
25
  });
26
+ ClassUtils_1.default.cloneMetadata(Target, proxy);
27
+ return proxy;
16
28
  }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = HotterDemand;
4
+ require("reflect-metadata");
5
+ const Hotter_1 = require("./Hotter");
6
+ const FastCarMetaData_1 = require("../../constant/FastCarMetaData");
7
+ function HotterDemand(fp) {
8
+ return function (target) {
9
+ (0, Hotter_1.default)(target);
10
+ Reflect.defineMetadata(FastCarMetaData_1.FastCarMetaData.HotterFilePath, fp, target.prototype);
11
+ };
12
+ }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SqlSession = exports.Entity = exports.Table = exports.PrimaryKey = exports.Field = exports.DBType = exports.DSIndex = exports.DS = exports.AppEnv = exports.Value = exports.CustomType = exports.ResourcePath = exports.Rule = exports.ValidForm = exports.ValidCustom = exports.Type = exports.Size = exports.NotNull = exports.DefaultVal = exports.AddChildValid = exports.AddRequireModule = exports.Log = exports.Readonly = exports.Override = exports.NotImplemented = exports.Deprecate = exports.ExceptionMonitor = exports.AliasInjection = exports.DemandInjection = exports.CallDependency = exports.Autowired = exports.Application = exports.Injection = exports.Repository = exports.Service = exports.Controller = exports.Configure = exports.BeanName = exports.HotterCallBack = exports.Hotter = exports.ComponentScanMust = exports.ComponentInjection = exports.Component = exports.ComponentScanExclusion = exports.ComponentScan = exports.ApplicationDestory = exports.ApplicationInit = exports.ApplicationRunner = exports.ApplicationStop = exports.ApplicationStart = void 0;
4
- exports.ApplicationSetting = exports.BaseName = exports.BasePath = exports.BaseFilePath = exports.ENV = exports.IsSerial = exports.Transactional = void 0;
3
+ exports.Entity = exports.Table = exports.PrimaryKey = exports.Field = exports.DBType = exports.DSIndex = exports.DS = exports.HotterDemand = exports.AppEnv = exports.Value = exports.CustomType = exports.ResourcePath = exports.Rule = exports.ValidForm = exports.ValidCustom = exports.Type = exports.Size = exports.NotNull = exports.DefaultVal = exports.AddChildValid = exports.AddRequireModule = exports.Log = exports.Readonly = exports.Override = exports.NotImplemented = exports.Deprecate = exports.ExceptionMonitor = exports.AliasInjection = exports.DemandInjection = exports.CallDependency = exports.Autowired = exports.Application = exports.Injection = exports.Repository = exports.Service = exports.Controller = exports.Configure = exports.BeanName = exports.HotterCallBack = exports.Hotter = exports.ComponentScanMust = exports.ComponentInjection = exports.Component = exports.ComponentScanExclusion = exports.ComponentScan = exports.ApplicationDestory = exports.ApplicationInit = exports.ApplicationRunner = exports.ApplicationStop = exports.ApplicationStart = void 0;
4
+ exports.ApplicationSetting = exports.BaseName = exports.BasePath = exports.BaseFilePath = exports.ENV = exports.IsSerial = exports.Transactional = exports.SqlSession = void 0;
5
5
  const Application_1 = require("./annotation/Application");
6
6
  exports.Application = Application_1.default;
7
7
  const Autowired_1 = require("./annotation/bind/Autowired");
@@ -116,3 +116,5 @@ const HotterCallBack_1 = require("./annotation/scan/HotterCallBack");
116
116
  exports.HotterCallBack = HotterCallBack_1.default;
117
117
  const IsSerial_1 = require("./annotation/data/IsSerial");
118
118
  exports.IsSerial = IsSerial_1.default;
119
+ const HotterDemand_1 = require("./annotation/scan/HotterDemand");
120
+ exports.HotterDemand = HotterDemand_1.default;
@@ -23,6 +23,7 @@ var FastCarMetaData;
23
23
  FastCarMetaData["ValidCustom"] = "valid:custom";
24
24
  FastCarMetaData["Hotter"] = "hotter";
25
25
  FastCarMetaData["HotterCallback"] = "HotterCallback";
26
+ FastCarMetaData["HotterFilePath"] = "HotterFilePath";
26
27
  FastCarMetaData["InjectionUniqueKey"] = "injection_uniqueKey";
27
28
  FastCarMetaData["Alias"] = "alias";
28
29
  FastCarMetaData["LoggerModule"] = "LoggerModule";
@@ -6,4 +6,5 @@ var HotReloadEnum;
6
6
  HotReloadEnum["reload"] = "reload";
7
7
  HotReloadEnum["sysReload"] = "sysReload";
8
8
  HotReloadEnum["configReload"] = "configReload";
9
+ HotReloadEnum["demandload"] = "demandload";
9
10
  })(HotReloadEnum || (exports.HotReloadEnum = HotReloadEnum = {}));
@@ -31,5 +31,13 @@ class ClassUtils {
31
31
  }
32
32
  return ClassUtils.getProtoDesc(parentObj, key);
33
33
  }
34
+ //拷贝元数据
35
+ static cloneMetadata(src, dst) {
36
+ const keys = Reflect.getMetadataKeys(src);
37
+ for (const k of keys) {
38
+ const val = Reflect.getMetadata(k, src);
39
+ Reflect.defineMetadata(k, val, dst);
40
+ }
41
+ }
34
42
  }
35
43
  exports.default = ClassUtils;
@@ -0,0 +1,13 @@
1
+ {"timestamp":"2025-12-19 21:21:28.981","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 21:21:29.391","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 21:21:29.394","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 21:21:29.397","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 21:21:29.398","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-22 10:39:59.247","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
+ {"timestamp":"2025-12-22 10:39:59.456","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
+ {"timestamp":"2025-12-22 10:39:59.458","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
+ {"timestamp":"2025-12-22 10:39:59.459","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
+ {"timestamp":"2025-12-22 10:39:59.460","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
11
+ {"timestamp":"2025-12-22 10:40:06.361","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\DemandService.ts"}
12
+ {"timestamp":"2025-12-22 10:40:16.525","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\DemandService.ts"}
13
+ {"timestamp":"2025-12-22 10:40:22.659","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\DemandService.ts"}
@@ -0,0 +1,6 @@
1
+ {"timestamp":"2025-12-22 10:51:51.390","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-22 10:51:51.705","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-22 10:51:51.707","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-22 10:51:51.709","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-22 10:51:51.710","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-22 13:36:16.367","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\DemandService.ts"}
@@ -0,0 +1,8 @@
1
+ {"timestamp":"2025-12-19 18:15:28.442","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 18:15:28.770","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 18:15:28.772","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 18:15:28.775","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 18:15:28.776","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-19 18:16:18.714","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
7
+ {"timestamp":"2025-12-19 18:16:22.788","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
8
+ {"timestamp":"2025-12-19 18:17:24.98","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
@@ -0,0 +1,13 @@
1
+ {"timestamp":"2025-12-19 18:27:17.488","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 18:27:17.806","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 18:27:17.809","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 18:27:17.812","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 18:27:17.813","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-19 18:27:26.754","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
7
+ {"timestamp":"2025-12-19 20:44:06.736","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
8
+ {"timestamp":"2025-12-19 20:44:07.58","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
9
+ {"timestamp":"2025-12-19 20:44:07.61","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
10
+ {"timestamp":"2025-12-19 20:44:07.63","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
11
+ {"timestamp":"2025-12-19 20:44:07.64","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
12
+ {"timestamp":"2025-12-19 20:44:13.987","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
13
+ {"timestamp":"2025-12-19 20:44:24.128","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
@@ -0,0 +1,8 @@
1
+ {"timestamp":"2025-12-19 20:44:32.225","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
2
+ {"timestamp":"2025-12-19 20:47:55.391","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
3
+ {"timestamp":"2025-12-19 20:48:23.98","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
4
+ {"timestamp":"2025-12-19 20:48:23.100","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
5
+ {"timestamp":"2025-12-19 20:48:23.101","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
6
+ {"timestamp":"2025-12-19 20:48:23.102","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
7
+ {"timestamp":"2025-12-19 20:48:33.510","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
8
+ {"timestamp":"2025-12-19 20:49:02.65","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
@@ -0,0 +1,11 @@
1
+ {"timestamp":"2025-12-19 20:52:16.382","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 20:52:16.677","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 20:52:16.679","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 20:52:16.681","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 20:52:16.682","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-19 20:52:57.780","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
+ {"timestamp":"2025-12-19 20:53:03.147","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
+ {"timestamp":"2025-12-19 20:53:03.151","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
+ {"timestamp":"2025-12-19 20:53:03.154","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
+ {"timestamp":"2025-12-19 20:53:03.155","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
11
+ {"timestamp":"2025-12-19 20:53:09.189","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
@@ -0,0 +1,8 @@
1
+ {"timestamp":"2025-12-19 20:57:10.393","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 20:57:16.223","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 20:57:16.226","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 20:57:16.228","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 20:57:16.229","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-19 20:57:35.203","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
7
+ {"timestamp":"2025-12-19 20:58:00.455","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
8
+ {"timestamp":"2025-12-19 20:58:33.286","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
@@ -0,0 +1,11 @@
1
+ {"timestamp":"2025-12-19 21:07:20.424","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 21:07:20.799","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 21:07:20.801","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 21:07:20.804","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 21:07:20.804","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-19 21:07:35.194","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
+ {"timestamp":"2025-12-19 21:07:35.517","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
+ {"timestamp":"2025-12-19 21:07:35.519","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
+ {"timestamp":"2025-12-19 21:07:35.522","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
+ {"timestamp":"2025-12-19 21:07:35.523","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
11
+ {"timestamp":"2025-12-19 21:07:45.358","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\TestValue.ts"}
@@ -0,0 +1,10 @@
1
+ {"timestamp":"2025-12-19 21:16:15.816","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 21:16:16.153","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 21:16:16.156","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 21:16:16.159","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 21:16:16.160","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-19 21:16:25.652","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
7
+ {"timestamp":"2025-12-19 21:16:25.982","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
8
+ {"timestamp":"2025-12-19 21:16:25.984","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
9
+ {"timestamp":"2025-12-19 21:16:25.987","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
10
+ {"timestamp":"2025-12-19 21:16:25.987","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
@@ -0,0 +1,12 @@
1
+ {"timestamp":"2025-12-19 21:16:43.564","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 21:16:43.879","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 21:16:43.884","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 21:16:43.889","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 21:16:43.891","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
6
+ {"timestamp":"2025-12-19 21:16:49.701","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\DemandService.ts"}
7
+ {"timestamp":"2025-12-19 21:16:53.792","level":"INFO","label":"fastcar-server.sys","message":"hot update----D:\\code\\fast-car\\fastcar-core\\test\\example\\simple\\service\\DemandService.ts"}
8
+ {"timestamp":"2025-12-19 21:20:57.674","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
9
+ {"timestamp":"2025-12-19 21:20:58.151","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
10
+ {"timestamp":"2025-12-19 21:20:58.154","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
11
+ {"timestamp":"2025-12-19 21:20:58.158","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
12
+ {"timestamp":"2025-12-19 21:20:58.159","level":"INFO","label":"fastcar-server.sys","message":"version 1.0.0"}
@@ -4,3 +4,8 @@
4
4
  {"timestamp":"2025-11-14 18:38:45.780","level":"INFO","label":"other-server.sys","message":"start server app is run"}
5
5
  {"timestamp":"2025-11-14 18:38:45.781","level":"INFO","label":"other-server.sys","message":"version 1.0.0"}
6
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"}
7
+ {"timestamp":"2025-12-19 17:39:27.744","level":"INFO","label":"other-server.sys","message":"Start scanning component"}
8
+ {"timestamp":"2025-12-19 17:39:28.279","level":"INFO","label":"other-server.sys","message":"Complete component scan"}
9
+ {"timestamp":"2025-12-19 17:39:28.280","level":"INFO","label":"other-server.sys","message":"Call application initialization method"}
10
+ {"timestamp":"2025-12-19 17:39:28.282","level":"INFO","label":"other-server.sys","message":"start server app is run"}
11
+ {"timestamp":"2025-12-19 17:39:28.282","level":"INFO","label":"other-server.sys","message":"version 1.0.0"}
@@ -0,0 +1,5 @@
1
+ {"timestamp":"2025-12-19 17:39:42.932","level":"INFO","label":"other-server.sys","message":"Start scanning component"}
2
+ {"timestamp":"2025-12-19 17:39:43.725","level":"INFO","label":"other-server.sys","message":"Complete component scan"}
3
+ {"timestamp":"2025-12-19 17:39:43.728","level":"INFO","label":"other-server.sys","message":"Call application initialization method"}
4
+ {"timestamp":"2025-12-19 17:39:43.731","level":"INFO","label":"other-server.sys","message":"start server app is run"}
5
+ {"timestamp":"2025-12-19 17:39:43.732","level":"INFO","label":"other-server.sys","message":"version 1.0.0"}
@@ -54,6 +54,7 @@ import NotFoundController from "./controller/NotFoundController";
54
54
  import HotConfig from "./config/HotConfig";
55
55
  import HelloConfig from "./config/HelloConfig";
56
56
  import TestValue from "./service/TestValue";
57
+ import DemandService from "./service/DemandService";
57
58
 
58
59
  describe("程序应用测试", () => {
59
60
  it("获取配置", () => {
@@ -118,4 +119,17 @@ describe("程序应用测试", () => {
118
119
  console.log(testValue.env);
119
120
  console.log(testValue.hello_c);
120
121
  });
122
+
123
+ it("按需服务测试", () => {
124
+ let testValue = new DemandService();
125
+ // let testValue2 = new DemandService();
126
+ setInterval(() => {
127
+ console.log(testValue.sayHello());
128
+ // console.log(testValue2.sayHello());
129
+ }, 1000);
130
+
131
+ // setTimeout(() => {
132
+ // appInsatcne.app.deleteDemandInstance(testValue);
133
+ // }, 3000);
134
+ });
121
135
  });
@@ -0,0 +1,10 @@
1
+ import DemandInjection from "../../../../src/annotation/bind/DemandInjection";
2
+ import HotterDemand from "../../../../src/annotation/scan/HotterDemand";
3
+
4
+ @HotterDemand(__filename)
5
+ @DemandInjection
6
+ export default class DemandService {
7
+ sayHello() {
8
+ return "hello";
9
+ }
10
+ }
@@ -1,12 +0,0 @@
1
- {"timestamp":"2025-08-25 15:08:20.393","level":"INFO","label":"fastcar-server.sys","message":"Start scanning component"}
2
- {"timestamp":"2025-08-25 15:08:20.821","level":"INFO","label":"fastcar-server.sys","message":"Complete component scan"}
3
- {"timestamp":"2025-08-25 15:08:20.824","level":"INFO","label":"fastcar-server.sys","message":"Call application initialization method"}
4
- {"timestamp":"2025-08-25 15:08:20.828","level":"INFO","label":"fastcar-server.sys","message":"start server app is run"}
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"}
@@ -1,2 +0,0 @@
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"}