typespeed 2.5.2 → 2.6.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  typespeed 版本演进记录。本文件 2026-09-06 从 git 历史反推建立;git 最早提交 2022-09-18(ch01)。
4
4
 
5
+ ## 2.6.x
6
+
7
+ - **2.6.2**:框架内建健康检查——新增 `HealthFactory`(abstract `ready()`)+ `HealthDefault`(默认恒就绪);`ExpressServer` 内建 `GET /health`(liveness)与 `GET /ready`(readiness,读 HealthFactory,200/503),路径可经 config 覆盖(2026-09-07)
8
+ - **2.6.1**:Node/TS 升级——TypeScript 4.9 → 5.9.3(legacy 装饰器零改动兼容,标准装饰器双轨同步验证);`@types/node` 对齐 22;声明 `engines`(node >=18)(2026-09-07)
9
+
5
10
  ## 2.5.x
6
11
 
7
12
  - **2.5.2**:README 重写(专业丰富版:30+ 装饰器分类、书籍体系突出)+ 新增英文版 `README.en.md`(中英切换,默认中文)(2026-09-07)
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBindMapping = exports.bind = void 0;
3
+ exports.bind = bind;
4
+ exports.getBindMapping = getBindMapping;
4
5
  const decorator_utils_1 = require("./decorator-utils");
5
6
  /**
6
7
  * 方法级参数绑定注册表:key = `[className, methodName]`,value = 绑定声明。
@@ -42,9 +43,7 @@ function bind(mapping) {
42
43
  bindParamMap.set([target.constructor.name, propertyKey].toString(), mapping);
43
44
  };
44
45
  }
45
- exports.bind = bind;
46
46
  /** 读取某方法上的 @bind 声明(route/database 内部使用) */
47
47
  function getBindMapping(className, methodName) {
48
48
  return bindParamMap.get([className, methodName].toString());
49
49
  }
50
- exports.getBindMapping = getBindMapping;
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.schedule = exports.getComponent = exports.getBean = exports.autoware = exports.error = exports.logx = exports.log = exports.resource = exports.bean = exports.component = void 0;
3
+ exports.component = component;
4
+ exports.bean = bean;
5
+ exports.resource = resource;
6
+ exports.log = log;
7
+ exports.logx = logx;
8
+ exports.error = error;
9
+ exports.autoware = autoware;
10
+ exports.getBean = getBean;
11
+ exports.getComponent = getComponent;
12
+ exports.schedule = schedule;
4
13
  require("reflect-metadata");
5
14
  const cron = require("cron");
6
15
  const log_factory_class_1 = require("./factory/log-factory.class");
@@ -19,11 +28,9 @@ function component(...args) {
19
28
  const constructorFunction = args[0];
20
29
  objectMapper.set(constructorFunction.name, new constructorFunction());
21
30
  }
22
- exports.component = component;
23
31
  function getComponent(constructorFunction) {
24
32
  return objectMapper.get(constructorFunction.name);
25
33
  }
26
- exports.getComponent = getComponent;
27
34
  function bean(...args) {
28
35
  if (args.length >= 2) {
29
36
  // 直接装饰器形式:@bean(无 token,走 legacy design:returntype)
@@ -32,7 +39,6 @@ function bean(...args) {
32
39
  // 工厂形式:@bean(Token)(显式返回类型 token,标准模式必需)
33
40
  return beanWithToken(args[0]);
34
41
  }
35
- exports.bean = bean;
36
42
  function beanWithToken(token) {
37
43
  return function (...args) {
38
44
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -59,7 +65,6 @@ function getBean(mappingClass) {
59
65
  const bean = beanMapper.get(mappingClass.name);
60
66
  return bean["factory"];
61
67
  }
62
- exports.getBean = getBean;
63
68
  function autoware(...args) {
64
69
  if (args.length >= 2) {
65
70
  // 直接装饰器形式:@autoware(无 token,走 legacy design:type)
@@ -68,7 +73,6 @@ function autoware(...args) {
68
73
  // 工厂形式:@autoware(Token)(显式 token,标准模式必需)
69
74
  return autowareWithToken(args[0]);
70
75
  }
71
- exports.autoware = autoware;
72
76
  function autowareWithToken(token) {
73
77
  return function (...args) {
74
78
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -138,7 +142,6 @@ function resource(...args) {
138
142
  });
139
143
  };
140
144
  }
141
- exports.resource = resource;
142
145
  function log(message, ...optionalParams) {
143
146
  const logObject = beanMapper.get(log_factory_class_1.default.name);
144
147
  if (logObject) {
@@ -148,7 +151,6 @@ function log(message, ...optionalParams) {
148
151
  console.log(message, ...optionalParams);
149
152
  }
150
153
  }
151
- exports.log = log;
152
154
  function logx(message) {
153
155
  message = JSON.stringify(message);
154
156
  const logObject = beanMapper.get(log_factory_class_1.default.name);
@@ -159,7 +161,6 @@ function logx(message) {
159
161
  console.log(message);
160
162
  }
161
163
  }
162
- exports.logx = logx;
163
164
  function error(message, ...optionalParams) {
164
165
  const logObject = beanMapper.get(log_factory_class_1.default.name);
165
166
  if (logObject) {
@@ -169,7 +170,6 @@ function error(message, ...optionalParams) {
169
170
  console.error(message, ...optionalParams);
170
171
  }
171
172
  }
172
- exports.error = error;
173
173
  function schedule(cronTime) {
174
174
  return (...args) => {
175
175
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -184,4 +184,3 @@ function schedule(cronTime) {
184
184
  new cron.CronJob(cronTime, target[propertyKey]).start();
185
185
  };
186
186
  }
187
- exports.schedule = schedule;
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Model = exports.cache = exports.resultType = exports.param = exports.select = exports.remove = exports.update = exports.insert = void 0;
3
+ exports.Model = void 0;
4
+ exports.insert = insert;
5
+ exports.update = update;
6
+ exports.remove = remove;
7
+ exports.select = select;
8
+ exports.param = param;
9
+ exports.resultType = resultType;
10
+ exports.cache = cache;
4
11
  const core_decorator_1 = require("./core.decorator");
5
12
  const decorator_utils_1 = require("./decorator-utils");
6
13
  const bind_decorator_1 = require("./bind.decorator");
@@ -38,7 +45,6 @@ function insert(sql) {
38
45
  };
39
46
  };
40
47
  }
41
- exports.insert = insert;
42
48
  function update(sql) {
43
49
  return (...args) => {
44
50
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -66,7 +72,6 @@ function update(sql) {
66
72
  };
67
73
  };
68
74
  }
69
- exports.update = update;
70
75
  function remove(sql) {
71
76
  return (...args) => {
72
77
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -94,7 +99,6 @@ function remove(sql) {
94
99
  };
95
100
  };
96
101
  }
97
- exports.remove = remove;
98
102
  function select(sql) {
99
103
  return (...args) => {
100
104
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -144,7 +148,6 @@ function select(sql) {
144
148
  };
145
149
  };
146
150
  }
147
- exports.select = select;
148
151
  function resultType(dataClass) {
149
152
  return function (...args) {
150
153
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -160,7 +163,6 @@ function resultType(dataClass) {
160
163
  //never return
161
164
  };
162
165
  }
163
- exports.resultType = resultType;
164
166
  function param(name) {
165
167
  return function (target, propertyKey, parameterIndex) {
166
168
  const existingParameters = Reflect.getOwnMetadata(paramMetadataKey, target, propertyKey) || [];
@@ -168,7 +170,6 @@ function param(name) {
168
170
  Reflect.defineMetadata(paramMetadataKey, existingParameters, target, propertyKey);
169
171
  };
170
172
  }
171
- exports.param = param;
172
173
  async function queryForExecute(sql, args, target, propertyKey) {
173
174
  const [newSql, sqlValues] = convertSQLParams(sql, target, propertyKey, args);
174
175
  return actionExecute(newSql, sqlValues);
@@ -255,7 +256,6 @@ function cache(ttl) {
255
256
  }
256
257
  };
257
258
  }
258
- exports.cache = cache;
259
259
  function getTableAndVersion(name, sql) {
260
260
  const regExpMap = {
261
261
  insert: /insert\sinto\s+([\w`\'\"]+)/i,
@@ -12,7 +12,8 @@
12
12
  * 因此库可以单份源码、运行时按签名形态分流:legacy 分支逻辑与 2.4.x 逐字一致,标准分支为新增。
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getStdArgs = exports.isStd = void 0;
15
+ exports.isStd = isStd;
16
+ exports.getStdArgs = getStdArgs;
16
17
  /**
17
18
  * 判断装饰器收到的运行时参数是否为标准装饰器签名 (value, context)。
18
19
  *
@@ -31,7 +32,6 @@ function isStd(args) {
31
32
  && args[1] !== null
32
33
  && typeof args[1].kind === "string";
33
34
  }
34
- exports.isStd = isStd;
35
35
  /**
36
36
  * 从标准装饰器参数中解出 (value, context)。
37
37
  * 仅应在 isStd(args) 为 true 时调用。
@@ -39,4 +39,3 @@ exports.isStd = isStd;
39
39
  function getStdArgs(args) {
40
40
  return [args[0], args[1]];
41
41
  }
42
- exports.getStdArgs = getStdArgs;
@@ -16,10 +16,10 @@ class DefaultAuthentication extends authentication_factory_class_1.default {
16
16
  return new DefaultAuthentication();
17
17
  }
18
18
  }
19
+ exports.default = DefaultAuthentication;
19
20
  __decorate([
20
21
  core_decorator_1.bean,
21
22
  __metadata("design:type", Function),
22
23
  __metadata("design:paramtypes", []),
23
24
  __metadata("design:returntype", authentication_factory_class_1.default)
24
25
  ], DefaultAuthentication.prototype, "getAuthentication", null);
25
- exports.default = DefaultAuthentication;
@@ -22,6 +22,7 @@ const route_decorator_1 = require("../route.decorator");
22
22
  const socket_io_class_1 = require("../default/socket-io.class");
23
23
  const typespeed_1 = require("../typespeed");
24
24
  const core_decorator_1 = require("../core.decorator");
25
+ const health_factory_class_1 = require("../factory/health-factory.class");
25
26
  const redis_class_1 = require("./redis.class");
26
27
  const authentication_factory_class_1 = require("../factory/authentication-factory.class");
27
28
  class ExpressServer extends server_factory_class_1.default {
@@ -83,6 +84,23 @@ class ExpressServer extends server_factory_class_1.default {
83
84
  }
84
85
  (0, route_decorator_1.setRouter)(this.app);
85
86
  this.app.use(this.authentication.afterCompletion);
87
+ // 健康检查(k8s liveness / readiness 探针)
88
+ const healthConfig = (0, typespeed_1.config)("health") || {};
89
+ const livenessPath = healthConfig["liveness"] || "/health";
90
+ const readinessPath = healthConfig["readiness"] || "/ready";
91
+ this.app.get(livenessPath, (req, res) => {
92
+ res.status(200).json({ status: "up" });
93
+ });
94
+ this.app.get(readinessPath, (req, res) => {
95
+ let ready = true;
96
+ try {
97
+ ready = (0, core_decorator_1.getBean)(health_factory_class_1.default).ready();
98
+ }
99
+ catch (e) {
100
+ ready = false;
101
+ }
102
+ res.status(ready ? 200 : 503).json({ status: ready ? "ready" : "not-ready" });
103
+ });
86
104
  const errorPageDir = __dirname + "/pages";
87
105
  this.app.use((req, res) => {
88
106
  (0, core_decorator_1.error)("404 not found, for page: " + req.url);
@@ -115,6 +133,7 @@ class ExpressServer extends server_factory_class_1.default {
115
133
  });
116
134
  }
117
135
  }
136
+ exports.default = ExpressServer;
118
137
  __decorate([
119
138
  (0, typespeed_1.value)("view"),
120
139
  __metadata("design:type", String)
@@ -165,4 +184,3 @@ __decorate([
165
184
  __metadata("design:paramtypes", []),
166
185
  __metadata("design:returntype", server_factory_class_1.default)
167
186
  ], ExpressServer.prototype, "getSever", null);
168
- exports.default = ExpressServer;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const core_decorator_1 = require("../core.decorator");
13
+ const health_factory_class_1 = require("../factory/health-factory.class");
14
+ /**
15
+ * 健康检查默认实现:恒为就绪。
16
+ * 应用继承 HealthFactory 并用 @bean 注册自定义实现,即可覆盖默认行为(如接入数据库/Redis 连通性检查)。
17
+ */
18
+ class HealthDefault extends health_factory_class_1.default {
19
+ createHealth() {
20
+ return new HealthDefault();
21
+ }
22
+ ready() {
23
+ return true;
24
+ }
25
+ }
26
+ exports.default = HealthDefault;
27
+ __decorate([
28
+ core_decorator_1.bean,
29
+ __metadata("design:type", Function),
30
+ __metadata("design:paramtypes", []),
31
+ __metadata("design:returntype", health_factory_class_1.default)
32
+ ], HealthDefault.prototype, "createHealth", null);
@@ -16,10 +16,10 @@ class LogDefault extends log_factory_class_1.default {
16
16
  return new LogDefault();
17
17
  }
18
18
  }
19
+ exports.default = LogDefault;
19
20
  __decorate([
20
21
  core_decorator_1.bean,
21
22
  __metadata("design:type", Function),
22
23
  __metadata("design:paramtypes", []),
23
24
  __metadata("design:returntype", log_factory_class_1.default)
24
25
  ], LogDefault.prototype, "createLog", null);
25
- exports.default = LogDefault;
@@ -38,6 +38,7 @@ class NodeCache extends cache_factory_class_1.default {
38
38
  this.NodeCache.flushAll();
39
39
  }
40
40
  }
41
+ exports.default = NodeCache;
41
42
  __decorate([
42
43
  (0, typespeed_1.value)("cache"),
43
44
  __metadata("design:type", Object)
@@ -48,4 +49,3 @@ __decorate([
48
49
  __metadata("design:paramtypes", []),
49
50
  __metadata("design:returntype", cache_factory_class_1.default)
50
51
  ], NodeCache.prototype, "getNodeCache", null);
51
- exports.default = NodeCache;
@@ -9,7 +9,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.rabbitListener = exports.RabbitMQ = void 0;
12
+ exports.RabbitMQ = void 0;
13
+ exports.rabbitListener = rabbitListener;
13
14
  const core_decorator_1 = require("../core.decorator");
14
15
  const typespeed_1 = require("../typespeed");
15
16
  const amqplib_1 = require("amqplib");
@@ -41,13 +42,13 @@ class RabbitMQ {
41
42
  await this.sendMessageToQueue(queue, message);
42
43
  }
43
44
  }
45
+ exports.RabbitMQ = RabbitMQ;
44
46
  __decorate([
45
47
  core_decorator_1.bean,
46
48
  __metadata("design:type", Function),
47
49
  __metadata("design:paramtypes", []),
48
50
  __metadata("design:returntype", RabbitMQ)
49
51
  ], RabbitMQ.prototype, "getRabbitMQ", null);
50
- exports.RabbitMQ = RabbitMQ;
51
52
  async function getChannel() {
52
53
  if (rabbitConnection === null) {
53
54
  rabbitConnection = await (0, amqplib_1.connect)((0, typespeed_1.config)("rabbitmq"));
@@ -84,4 +85,3 @@ function rabbitListener(queue) {
84
85
  }());
85
86
  };
86
87
  }
87
- exports.rabbitListener = rabbitListener;
@@ -57,10 +57,10 @@ class ReadWriteDb extends data_source_factory_class_1.default {
57
57
  return this.writeSession;
58
58
  }
59
59
  }
60
+ exports.default = ReadWriteDb;
60
61
  __decorate([
61
62
  core_decorator_1.bean,
62
63
  __metadata("design:type", Function),
63
64
  __metadata("design:paramtypes", []),
64
65
  __metadata("design:returntype", data_source_factory_class_1.default)
65
66
  ], ReadWriteDb.prototype, "getDataSource", null);
66
- exports.default = ReadWriteDb;
@@ -9,7 +9,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.redisSubscriber = exports.Redis = void 0;
12
+ exports.Redis = void 0;
13
+ exports.redisSubscriber = redisSubscriber;
13
14
  const core_decorator_1 = require("../core.decorator");
14
15
  const ioredis_1 = require("ioredis");
15
16
  const typespeed_1 = require("../typespeed");
@@ -57,6 +58,7 @@ class Redis extends ioredis_1.default {
57
58
  }
58
59
  }
59
60
  }
61
+ exports.Redis = Redis;
60
62
  Redis.pubObj = null;
61
63
  Redis.subObj = null;
62
64
  __decorate([
@@ -65,7 +67,6 @@ __decorate([
65
67
  __metadata("design:paramtypes", []),
66
68
  __metadata("design:returntype", Redis)
67
69
  ], Redis.prototype, "getRedis", null);
68
- exports.Redis = Redis;
69
70
  function redisSubscriber(channel) {
70
71
  if (!(0, typespeed_1.config)("redis"))
71
72
  return function () {
@@ -95,7 +96,6 @@ function redisSubscriber(channel) {
95
96
  };
96
97
  };
97
98
  }
98
- exports.redisSubscriber = redisSubscriber;
99
99
  if ((0, typespeed_1.config)("redis")) {
100
100
  Redis.getInstanceOfRedis("sub").on("message", async function (channel, message) {
101
101
  await (0, core_decorator_1.getComponent)(redisSubscribers[channel].target.constructor)[redisSubscribers[channel].propertyKey](message);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 健康检查工厂(抽象)。
5
+ * 实现 ready() 自定义「就绪检查」(readiness)——如检查数据库/Redis/MQ 连通性。
6
+ * 应用继承此类并用 @bean 注册自定义实现;默认实现见 HealthDefault(恒就绪)。
7
+ */
8
+ class HealthFactory {
9
+ }
10
+ exports.default = HealthFactory;
@@ -1,6 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jwt = exports.upload = exports.setRouter = exports.requestMapping = exports.postMapping = exports.getMapping = exports.after = exports.before = exports.response = exports.res = exports.request = exports.req = exports.reqParam = exports.reqForm = exports.reqQuery = exports.reqBody = exports.next = void 0;
3
+ exports.requestMapping = exports.postMapping = exports.getMapping = void 0;
4
+ exports.next = next;
5
+ exports.reqBody = reqBody;
6
+ exports.reqQuery = reqQuery;
7
+ exports.reqForm = reqForm;
8
+ exports.reqParam = reqParam;
9
+ exports.req = req;
10
+ exports.request = req;
11
+ exports.res = res;
12
+ exports.response = res;
13
+ exports.before = before;
14
+ exports.after = after;
15
+ exports.setRouter = setRouter;
16
+ exports.upload = upload;
17
+ exports.jwt = jwt;
4
18
  const multiparty = require("multiparty");
5
19
  const express_jwt_1 = require("express-jwt");
6
20
  const core_decorator_1 = require("./core.decorator");
@@ -28,7 +42,6 @@ function setRouter(app) {
28
42
  }
29
43
  });
30
44
  }
31
- exports.setRouter = setRouter;
32
45
  function mapperFunction(method, value) {
33
46
  return (...args) => {
34
47
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -137,7 +150,6 @@ function upload(...args) {
137
150
  routerMiddleware[key] = [uploadMiddleware];
138
151
  }
139
152
  }
140
- exports.upload = upload;
141
153
  function uploadMiddleware(req, res, next) {
142
154
  const form = new multiparty.Form();
143
155
  form.parse(req, (err, fields, files) => {
@@ -171,7 +183,6 @@ function jwt(jwtConfig) {
171
183
  }
172
184
  };
173
185
  }
174
- exports.jwt = jwt;
175
186
  function before(constructorFunction, methodName) {
176
187
  const targetBean = (0, core_decorator_1.getComponent)(constructorFunction);
177
188
  return function (...args) {
@@ -206,7 +217,6 @@ function before(constructorFunction, methodName) {
206
217
  });
207
218
  };
208
219
  }
209
- exports.before = before;
210
220
  function after(constructorFunction, methodName) {
211
221
  const targetBean = (0, core_decorator_1.getComponent)(constructorFunction);
212
222
  return function (...args) {
@@ -243,35 +253,27 @@ function after(constructorFunction, methodName) {
243
253
  });
244
254
  };
245
255
  }
246
- exports.after = after;
247
256
  function req(target, propertyKey, parameterIndex) {
248
257
  const key = [target.constructor.name, propertyKey, parameterIndex].toString();
249
258
  routerParams[key] = (req, res, next) => req;
250
259
  }
251
- exports.req = req;
252
- exports.request = req;
253
260
  function res(target, propertyKey, parameterIndex) {
254
261
  const key = [target.constructor.name, propertyKey, parameterIndex].toString();
255
262
  routerParams[key] = (req, res, next) => res;
256
263
  }
257
- exports.res = res;
258
- exports.response = res;
259
264
  function next(target, propertyKey, parameterIndex) {
260
265
  const key = [target.constructor.name, propertyKey, parameterIndex].toString();
261
266
  routerParams[key] = (req, res, next) => next;
262
267
  }
263
- exports.next = next;
264
268
  function reqBody(target, propertyKey, parameterIndex) {
265
269
  const key = [target.constructor.name, propertyKey, parameterIndex].toString();
266
270
  routerParams[key] = (req, res, next) => req.body;
267
271
  }
268
- exports.reqBody = reqBody;
269
272
  function reqParam(target, propertyKey, parameterIndex) {
270
273
  const key = [target.constructor.name, propertyKey, parameterIndex].toString();
271
274
  const paramName = getParamInFunction(target[propertyKey], parameterIndex);
272
275
  routerParams[key] = (req, res, next) => req.params[paramName];
273
276
  }
274
- exports.reqParam = reqParam;
275
277
  function getParamInFunction(fn, index) {
276
278
  const code = fn.toString().replace(/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg, '').replace(/=>.*$/mg, '').replace(/=[^,]+/mg, '');
277
279
  const result = code.slice(code.indexOf('(') + 1, code.indexOf(')')).match(/([^\s,]+)/g);
@@ -330,14 +332,12 @@ function reqQuery(target, propertyKey, parameterIndex) {
330
332
  const paramName = getParamInFunction(target[propertyKey], parameterIndex);
331
333
  routerParams[key] = (req, res, next) => req.query[paramName];
332
334
  }
333
- exports.reqQuery = reqQuery;
334
335
  function reqForm(paramName) {
335
336
  return (target, propertyKey, parameterIndex) => {
336
337
  const key = [target.constructor.name, propertyKey, parameterIndex].toString();
337
338
  routerParams[key] = (req, res, next) => req.body[paramName];
338
339
  };
339
340
  }
340
- exports.reqForm = reqForm;
341
341
  const getMapping = (value) => mapperFunction("get", value);
342
342
  exports.getMapping = getMapping;
343
343
  const postMapping = (value) => mapperFunction("post", value);
@@ -280,6 +280,14 @@ declare abstract class AuthenticationFactory {
280
280
  */
281
281
  afterCompletion(req: express.Request, res: express.Response, next: express.NextFunction): void;
282
282
  }
283
+ /**健康检查工厂类,实现 ready() 自定义就绪检查(readiness) */
284
+ declare abstract class HealthFactory {
285
+ abstract ready(): boolean;
286
+ }
287
+ /**健康检查默认实现类,默认恒为就绪 */
288
+ declare class HealthDefault extends HealthFactory {
289
+ ready(): boolean;
290
+ }
283
291
  /**Redis 操作类 */
284
292
  declare class Redis extends IoRedis {
285
293
  /**获取 Redis 实例 */
@@ -400,4 +408,4 @@ declare class SocketIo {
400
408
  /**Socket IO 服务实现类 */
401
409
  declare const io: IoServer;
402
410
 
403
- export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, redisSubscriber, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, component, bean, resource, log, logx, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, bind, resultType, cache, Model, SocketIo, io };
411
+ export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, redisSubscriber, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, HealthFactory, HealthDefault, next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, component, bean, resource, log, logx, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, bind, resultType, cache, Model, SocketIo, io };
package/dist/typespeed.js CHANGED
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ReadWriteDb = exports.redisSubscriber = exports.Redis = exports.NodeCache = exports.LogDefault = exports.ExpressServer = exports.AuthenticationFactory = exports.ServerFactory = exports.DataSourceFactory = exports.CacheFactory = exports.LogFactory = exports.config = exports.value = exports.app = void 0;
17
+ exports.ReadWriteDb = exports.redisSubscriber = exports.Redis = exports.NodeCache = exports.HealthDefault = exports.LogDefault = exports.ExpressServer = exports.HealthFactory = exports.AuthenticationFactory = exports.ServerFactory = exports.DataSourceFactory = exports.CacheFactory = exports.LogFactory = void 0;
18
+ exports.app = app;
19
+ exports.value = value;
20
+ exports.config = config;
18
21
  require("reflect-metadata");
19
22
  const fs = require("fs");
20
23
  const path = require("path");
@@ -44,20 +47,18 @@ function app(...args) {
44
47
  }
45
48
  startApp(args[0]);
46
49
  }
47
- exports.app = app;
48
50
  function startApp(constructor) {
49
51
  const coreFiles = walkSync(corePath, { globs: ['**/*.ts'], ignore: ['**/*.d.ts', 'scaffold/**'] });
50
52
  const mainFiles = walkSync(mainPath, { globs: ['**/*.ts'] });
51
53
  (async function () {
52
- var _a, _b;
53
54
  try {
54
55
  for (let p of coreFiles) {
55
56
  let moduleName = p.replace(".d.ts", "").replace(".ts", "");
56
- await (_a = corePath + "/" + moduleName, Promise.resolve().then(() => require(_a)));
57
+ await Promise.resolve(`${corePath + "/" + moduleName}`).then(s => require(s));
57
58
  }
58
59
  for (let p of mainFiles) {
59
60
  let moduleName = p.replace(".d.ts", "").replace(".ts", "");
60
- await (_b = mainPath + "/" + moduleName, Promise.resolve().then(() => require(_b)));
61
+ await Promise.resolve(`${mainPath + "/" + moduleName}`).then(s => require(s));
61
62
  }
62
63
  }
63
64
  catch (err) {
@@ -71,7 +72,6 @@ function startApp(constructor) {
71
72
  function config(node) {
72
73
  return globalConfig[node] || null;
73
74
  }
74
- exports.config = config;
75
75
  function value(configPath) {
76
76
  return function (...args) {
77
77
  if ((0, decorator_utils_1.isStd)(args)) {
@@ -111,7 +111,6 @@ function value(configPath) {
111
111
  }
112
112
  };
113
113
  }
114
- exports.value = value;
115
114
  function getRootPath(lines) {
116
115
  // 兼容新旧 Node 栈帧(Node<22: "Function.Module._load" / Node22+: "Function._load")、
117
116
  // mocha(ts-node) 下 "Context.<anonymous>" 与中间可能插入的 "wrapModuleLoad" 帧:
@@ -146,10 +145,14 @@ var server_factory_class_1 = require("./factory/server-factory.class");
146
145
  Object.defineProperty(exports, "ServerFactory", { enumerable: true, get: function () { return server_factory_class_1.default; } });
147
146
  var authentication_factory_class_1 = require("./factory/authentication-factory.class");
148
147
  Object.defineProperty(exports, "AuthenticationFactory", { enumerable: true, get: function () { return authentication_factory_class_1.default; } });
148
+ var health_factory_class_1 = require("./factory/health-factory.class");
149
+ Object.defineProperty(exports, "HealthFactory", { enumerable: true, get: function () { return health_factory_class_1.default; } });
149
150
  var express_server_class_1 = require("./default/express-server.class");
150
151
  Object.defineProperty(exports, "ExpressServer", { enumerable: true, get: function () { return express_server_class_1.default; } });
151
152
  var log_default_class_1 = require("./default/log-default.class");
152
153
  Object.defineProperty(exports, "LogDefault", { enumerable: true, get: function () { return log_default_class_1.default; } });
154
+ var health_default_class_1 = require("./default/health-default.class");
155
+ Object.defineProperty(exports, "HealthDefault", { enumerable: true, get: function () { return health_default_class_1.default; } });
153
156
  var node_cache_class_1 = require("./default/node-cache.class");
154
157
  Object.defineProperty(exports, "NodeCache", { enumerable: true, get: function () { return node_cache_class_1.default; } });
155
158
  var redis_class_1 = require("./default/redis.class");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.5.2",
3
+ "version": "2.6.2",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -13,6 +13,9 @@
13
13
  "prebuild": "rm -rf dist"
14
14
  },
15
15
  "main": "dist/typespeed.js",
16
+ "engines": {
17
+ "node": ">=18"
18
+ },
16
19
  "files": [
17
20
  "dist",
18
21
  "CHANGELOG.md",
@@ -62,13 +65,13 @@
62
65
  "devDependencies": {
63
66
  "@types/express": "^4.17.13",
64
67
  "@types/mocha": "^10.0.1",
65
- "@types/node": "^18.19.3",
68
+ "@types/node": "^22.0.0",
66
69
  "chai": "4.3.7",
67
70
  "chai-http": "^4.4.0",
68
71
  "mocha": "10.2.0",
69
72
  "nyc": "^15.1.0",
70
73
  "socket.io-client": "4.7.1",
71
74
  "ts-node": "^10.9.1",
72
- "typescript": "^4.9.5"
75
+ "typescript": "^5.9.3"
73
76
  }
74
77
  }