typespeed 2.4.11 → 2.5.1

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 (90) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/dist/bind.decorator.js +50 -0
  3. package/dist/core.decorator.js +113 -26
  4. package/dist/database.decorator.js +122 -16
  5. package/dist/decorator-utils.js +42 -0
  6. package/dist/default/rabbitmq.class.js +18 -1
  7. package/dist/default/redis.class.js +14 -1
  8. package/dist/default/socket-io.class.js +53 -4
  9. package/dist/route.decorator.js +175 -10
  10. package/dist/typespeed.d.ts +35 -31
  11. package/dist/typespeed.js +31 -3
  12. package/package.json +6 -2
  13. package/.github/workflows/test.yml +0 -50
  14. package/app/nodemon.json +0 -5
  15. package/app/package.json +0 -17
  16. package/app/src/aop-test.class.ts +0 -29
  17. package/app/src/config-development.json +0 -26
  18. package/app/src/config-production.json +0 -15
  19. package/app/src/config.json +0 -50
  20. package/app/src/custom-log.class.ts +0 -33
  21. package/app/src/entities/mutil-users.class.ts +0 -5
  22. package/app/src/entities/user-dto.class.ts +0 -3
  23. package/app/src/first-page.class.ts +0 -46
  24. package/app/src/jwt-authentication.class.ts +0 -30
  25. package/app/src/main.ts +0 -24
  26. package/app/src/second-page.class.ts +0 -43
  27. package/app/src/test-database.class.ts +0 -81
  28. package/app/src/test-log.class.ts +0 -11
  29. package/app/src/test-mq.class.ts +0 -21
  30. package/app/src/test-orm.class.ts +0 -63
  31. package/app/src/test-redis.class.ts +0 -45
  32. package/app/src/test-request.class.ts +0 -37
  33. package/app/src/test-socket.class.ts +0 -56
  34. package/app/src/user-model.class.ts +0 -50
  35. package/app/src/views/index.html +0 -1
  36. package/app/src/views/socket.html +0 -23
  37. package/app/src/views/upload.html +0 -14
  38. package/app/static/favicon.ico +0 -0
  39. package/app/static/k.jpg +0 -0
  40. package/app/tsconfig.json +0 -20
  41. package/introduction/decorator/example-import.class.ts +0 -6
  42. package/introduction/decorator/main-app.ts +0 -6
  43. package/introduction/decorator/main-decorator.ts +0 -108
  44. package/introduction/decorator/main-import.ts +0 -1
  45. package/introduction/decorator/main-reflect.ts +0 -25
  46. package/introduction/tsconfig.json +0 -20
  47. package/introduction/web-services/db-init.ts +0 -39
  48. package/introduction/web-services/db-singleton.ts +0 -59
  49. package/introduction/web-services/http-if.ts +0 -10
  50. package/introduction/web-services/http-init.ts +0 -6
  51. package/introduction/web-services/http-router.ts +0 -28
  52. package/src/core.decorator.ts +0 -98
  53. package/src/database.decorator.ts +0 -342
  54. package/src/default/default-authentication.class.ts +0 -10
  55. package/src/default/express-server.class.ts +0 -150
  56. package/src/default/log-default.class.ts +0 -9
  57. package/src/default/node-cache.class.ts +0 -40
  58. package/src/default/pages/404.html +0 -226
  59. package/src/default/pages/500.html +0 -713
  60. package/src/default/rabbitmq.class.ts +0 -61
  61. package/src/default/read-write-db.class.ts +0 -53
  62. package/src/default/redis.class.ts +0 -79
  63. package/src/default/socket-io.class.ts +0 -81
  64. package/src/factory/authentication-factory.class.ts +0 -9
  65. package/src/factory/cache-factory.class.ts +0 -7
  66. package/src/factory/data-source-factory.class.ts +0 -4
  67. package/src/factory/log-factory.class.ts +0 -8
  68. package/src/factory/server-factory.class.ts +0 -6
  69. package/src/route.decorator.ts +0 -175
  70. package/src/scaffold/command.ts +0 -40
  71. package/src/scaffold/templates/front-page.class.ts.tpl +0 -12
  72. package/src/scaffold/templates/main.ts.tpl +0 -13
  73. package/src/scaffold/templates/nodemon.json.tpl +0 -7
  74. package/src/scaffold/templates/package.json.tpl +0 -16
  75. package/src/scaffold/templates/tsconfig.json.tpl +0 -17
  76. package/src/typespeed.d.ts +0 -399
  77. package/src/typespeed.ts +0 -110
  78. package/test/database.test.ts +0 -76
  79. package/test/first-page.test.ts +0 -42
  80. package/test/hooks.ts +0 -13
  81. package/test/mq.test.ts +0 -17
  82. package/test/orm.test.ts +0 -66
  83. package/test/redis.test.ts +0 -48
  84. package/test/request.test.ts +0 -51
  85. package/test/second-page.test.ts +0 -50
  86. package/test/socket.test.ts +0 -60
  87. package/test-env/docker-compose.test.yml +0 -31
  88. package/test-env/mysql-init/init.sql +0 -8
  89. package/test-env//346/234/254/345/234/260Docker/346/265/213/350/257/225/346/226/271/346/241/210.md +0 -69
  90. package/tsconfig.json +0 -25
@@ -1,399 +0,0 @@
1
- import * as express from "express";
2
- import { Redis as IoRedis, RedisKey } from "ioredis";
3
- import { Server as IoServer } from "socket.io";
4
- import "reflect-metadata";
5
-
6
- /**设置路由中间件 */
7
- declare function setRouter(app: express.Application): void;
8
- /**上传文件装饰器,装饰页面具备解析上传文件的能力 */
9
- declare function upload(target: any, propertyKey: string): void;
10
- /**
11
- * 页面支持 JWT 鉴权能力
12
- * @param jwtConfig jwt 配置
13
- */
14
- declare function jwt(jwtConfig: any): (target: any, propertyKey: string) => void;
15
- /**
16
- * GET 请求装饰器
17
- * @param value 请求路径
18
- */
19
- declare const getMapping: (value: string) => (target: any, propertyKey: string) => void;
20
- /**
21
- * POST 请求装饰器
22
- * @param value 请求路径
23
- */
24
- declare const postMapping: (value: string) => (target: any, propertyKey: string) => void;
25
- /**
26
- * 请求装饰器,不区分请求类型
27
- * @param value 请求路径
28
- */
29
- declare const requestMapping: (value: string) => (target: any, propertyKey: string) => void;
30
- /**
31
- * INSERT 装饰器
32
- * 将方法作为 INSERT SQL 使用
33
- * @param sql INSERT SQL 语句
34
- */
35
- declare function insert(sql: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
36
- /**
37
- * UPDATE 装饰器
38
- * 将方法作为 UPDATE SQL 使用
39
- * @param sql UPDATE SQL 语句
40
- */
41
- declare function update(sql: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
42
- /**
43
- * DELETE 装饰器
44
- * 将方法作为 DELETE SQL 使用
45
- * @param sql DELETE SQL 语句
46
- */
47
- declare function remove(sql: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
48
- /**
49
- * SELECT 装饰器
50
- * 将方法作为 SELECT SQL 使用
51
- * @param sql SELECT SQL 语句
52
- */
53
- declare function select(sql: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
54
- /**
55
- * SELECT 结果类型装饰器,和 @select 配合使用
56
- * @param dataClass 结果类型
57
- */
58
- declare function resultType(dataClass: any): (target: any, propertyKey: string) => void;
59
- /**
60
- * SQL 参数装饰器,标注 SQL 语句的绑定参数值,和 @select @insert @update @remove 配合使用
61
- * @param name 参数在 SQL 语句内的标记值
62
- */
63
- declare function param(name: string): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
64
- /**
65
- * SELECT 缓存装饰器,自动缓存 SELECT 查询结果,和 @select 配合使用
66
- * 当执行 @insert @update @remove 时,会自动清除缓存。
67
- * @param ttl 缓存时间,单位秒
68
- */
69
- declare function cache(ttl: number): (target: any, propertyKey: string) => void;
70
- /**模型数据操作类 */
71
- declare class Model {
72
- /**分页数据 */
73
- page: any;
74
- private table;
75
- constructor(table?: string);
76
- /**
77
- * 查询多条数据
78
- * @param conditions 查询条件,支持对象和字符串
79
- * @param sort 排序字段
80
- * @param fields 定义返回字段
81
- * @param limit 限制返回数据条数
82
- */
83
- findAll<T>(conditions: object | string, sort?: string | object, fields?: string | [string], limit?: number | object): Promise<T[]>;
84
- /**
85
- * 插入数据,支持单条或多条数据同时插入
86
- * @param rows 插入数据,支持对象和数组;对象为单条数据,数组为多条数据。
87
- */
88
- create(rows: any): Promise<number>;
89
- /**
90
- * 查询单条数据
91
- * @param conditions 查询条件,支持对象和字符串
92
- * @param sort 排序字段
93
- * @param fields 定义返回字段
94
- */
95
- find<T>(conditions: any, sort: any, fields?: string): Promise<T>;
96
- /**
97
- * 更新数据
98
- * @param conditions 更新条件,支持对象和字符串,符合条件的数据将被更新
99
- * @param fieldToValues 更新字段和值
100
- */
101
- update(conditions: any, fieldToValues: any): Promise<number>;
102
- /**
103
- * 删除数据
104
- * @param conditions 删除条件,支持对象和字符串,符合条件的数据将被删除
105
- */
106
- delete(conditions: any): Promise<number>;
107
- /**
108
- * 查询数据条数,返回符合条件的记录条数
109
- * @param conditions 查询条件,支持对象和字符串
110
- */
111
- findCount(conditions: any): Promise<number>;
112
- /**
113
- * 增加字段值
114
- * @param conditions 查询条件,支持对象和字符串,符合条件的数据将被增加
115
- * @param field 需要增加的字段
116
- * @param optval 增加数量值,默认为 1
117
- */
118
- incr(conditions: any, field: any, optval?: number): Promise<number>;
119
- /**
120
- * 减少字段值
121
- * @param conditions 查询条件,支持对象和字符串,符合条件的数据将被减少
122
- * @param field 需要减少的字段
123
- * @param optval 减少数量值,默认为 1
124
- */
125
- decr(conditions: any, field: any, optval?: number): Promise<number>;
126
- /**
127
- * 计算分页数据
128
- * @param page 当前页码
129
- * @param total 记录总条数
130
- * @param pageSize 每页显示条数
131
- * @param scope 分页显示页码数量
132
- */
133
- pager(page: any, total: any, pageSize?: number, scope?: number): any;
134
- private where;
135
- private range;
136
- }
137
- /**
138
- * 应用程序入口装饰器
139
- *
140
- * 被装饰的类将作为应用程序入口,框架将启动该类的 main 方法
141
- */
142
- declare function app<T extends {
143
- new(...args: any[]): {};
144
- }>(constructor: T): void;
145
- /**获取配置文件中的配置项 */
146
- declare function config(node: string): any;
147
- /**组件装饰器,被装饰的类可以通过 @autoware 取得实例 */
148
- declare function component(constructorFunction: any): void;
149
- /**获取组件实例函数,返回结果同 @autoware */
150
- declare function getComponent(constructorFunction: any): any;
151
- /**提供对象装饰器,框架将使用 @bean 装饰的方法来获取对象实例 */
152
- declare function bean(target: any, propertyKey: string): void;
153
- /**获取对象实例函数,返回结果由 @bean 装饰的方法提供 */
154
- declare function getBean(mappingClass: Function): any;
155
- /**配置装饰器,装饰类成员变量值,获取配置文件中的配置项 */
156
- declare function value(configPath: string): any;
157
- /**自动装配装饰器,无参数版本,被装饰的类成员变量将自动注入实例 */
158
- declare function autoware(target: any, propertyKey: string): void;
159
- /**自动装配装饰器,带参数版本,可输入参数作为实例初始化参数,被装饰的类成员变量将自动注入实例 */
160
- declare function resource(...args: any[]): any;
161
- /**日志函数,输出打印日志 */
162
- declare function log(message?: any, ...optionalParams: any[]): void;
163
- /**日志函数,输出JSON日志 */
164
- declare function logx(message: any): void;
165
- /**错误日志函数,输出打印错误日志 */
166
- declare function error(message?: any, ...optionalParams: any[]): void;
167
- /**路由页面前置执行装饰器,参数指向路由页面方法,被装饰的方法将在路由页面之前执行 */
168
- declare function before(constructorFunction: any, methodName: string): (target: any, propertyKey: string) => void;
169
- /**路由页面后置执行装饰器,参数指向路由页面方法,被装饰的方法将在路由页面之后执行 */
170
- declare function after(constructorFunction: any, methodName: string): (target: any, propertyKey: string) => void;
171
- /**定时程序装饰器,参数支持 crontab 格式字符串,可根据参数定时执行被装饰的方法 */
172
- declare function schedule(cronTime: string | Date): (target: any, propertyKey: string) => void;
173
- /**RabbitMQ 监听装饰器,参数是监听的队列名称,当接受到消息时将执行被装饰方法 */
174
- declare function rabbitListener(queue: string): (target: any, propertyKey: string) => void;
175
- /**Redis 监听装饰器,参数是监听的队列名称,当接受到消息时将执行被装饰方法 */
176
- declare function redisSubscriber(target: any, propertyKey: string): void;
177
- /** request 对象装饰器,作为路由页面方法参数,获取 request 对象 */
178
- declare function req(target: any, propertyKey: string, parameterIndex: number): void;
179
- /** response 对象装饰器,作为路由页面方法参数,获取 response 对象 */
180
- declare function res(target: any, propertyKey: string, parameterIndex: number): void;
181
- /** next 函数装饰器,作为路由页面方法参数,获取 next 函数 */
182
- declare function next(target: any, propertyKey: string, parameterIndex: number): void;
183
- /** request.body 对象装饰器,作为路由页面方法参数,获取 request.body 对象 */
184
- declare function reqBody(target: any, propertyKey: string, parameterIndex: number): void;
185
- /** request.param 值装饰器,作为路由页面方法参数,获取 request.params 内容 */
186
- declare function reqParam(target: any, propertyKey: string, parameterIndex: number): void;
187
- /** request.query 值装饰器,作为路由页面方法参数,获取 request.query 内容 */
188
- declare function reqQuery(target: any, propertyKey: string, parameterIndex: number): void;
189
- /** request 表单值装饰器,作为路由页面方法参数,获取 request.body 表单内容 */
190
- declare function reqForm(paramName: string): (target: any, propertyKey: string, parameterIndex: number) => void;
191
-
192
- /**框架 Web 服务工厂类 */
193
- declare abstract class ServerFactory {
194
- /**Web 服务实例 */
195
- app: any;
196
- /**中间件列表 */
197
- protected middlewareList: Array<any>;
198
- /**
199
- * 设置一个中间件
200
- * @param middleware 中间件
201
- */
202
- abstract setMiddleware(middleware: any): any;
203
- /**
204
- * 启动 Web 服务
205
- * @param port 端口号
206
- */
207
- abstract start(port: number, callback?: Function): any;
208
- }
209
- /**日志工厂类 */
210
- declare abstract class LogFactory {
211
- /**
212
- * 日志打印方法
213
- * @param message 日志内容
214
- */
215
- log(message?: any, ...optionalParams: any[]): void;
216
- /**
217
- * 错误日志打印方法
218
- * @param message 日志内容
219
- */
220
- error(message?: any, ...optionalParams: any[]): void;
221
- /**
222
- * 调试日志打印方法
223
- * @param message 日志内容
224
- */
225
- debug(message?: any, ...optionalParams: any[]): void;
226
- }
227
- /**数据源工厂类 */
228
- declare abstract class DataSourceFactory {
229
- /**获取读库连接 */
230
- abstract readConnection(): any;
231
- /**获取写库连接 */
232
- abstract writeConnection(): any;
233
- }
234
- /**缓存工厂类 */
235
- declare abstract class CacheFactory {
236
- /**
237
- * 获取缓存
238
- * @param key 缓存键
239
- */
240
- abstract get(key: string): any;
241
- /**
242
- * 设置缓存
243
- * @param key 缓存键
244
- * @param value 缓存值
245
- * @param expire 过期时间,单位秒
246
- */
247
- abstract set(key: string, value: any, expire?: number): void;
248
- /**
249
- * 删除缓存
250
- * @param key 缓存键
251
- */
252
- abstract del(key: string): void;
253
- /**
254
- * 判断缓存是否存在
255
- * @param key 缓存键
256
- * @returns 是否存在
257
- */
258
- abstract has(key: string): boolean;
259
- /**清空缓存 */
260
- abstract flush(): void;
261
- }
262
- /**认证类 */
263
- declare abstract class AuthenticationFactory {
264
- /**
265
- * 路由页面执行前认证
266
- * @param req 请求对象
267
- * @param res 响应对象
268
- * @param next 下一步函数
269
- */
270
- preHandle(req: express.Request, res: express.Response, next: express.NextFunction): void;
271
- /**
272
- * 开始执行中间件前认证
273
- * @param req 请求对象
274
- * @param res 响应对象
275
- * @param next 下一步函数
276
- */
277
- afterCompletion(req: express.Request, res: express.Response, next: express.NextFunction): void;
278
- }
279
- /**Redis 操作类 */
280
- declare class Redis extends IoRedis {
281
- /**获取 Redis 实例 */
282
- getRedis(): Redis;
283
- /**
284
- * 获取有序集合(sorted set),按照分数从大到小排序,返回 Map 对象
285
- * @param key 键
286
- * @param start 开始位置,0 表示第一个元素,-1 表示最后一个元素
287
- * @param stop 结束位置,0 表示第一个元素,-1 表示最后一个元素
288
- * @returns Map 对象,key 为有序集合的成员,value 为成员的分数
289
- */
290
- zrevranking(key: RedisKey, start: number | string, stop: number | string): Promise<Map<string, number>>;
291
- /**
292
- * 获取有序集合(sorted set),按照分数从小到大排序,返回 Map 对象
293
- * @param key 键
294
- * @param start 开始位置,0 表示第一个元素,-1 表示最后一个元素
295
- * @param stop 结束位置,0 表示第一个元素,-1 表示最后一个元素
296
- * @returns Map 对象,key 为有序集合的成员,value 为成员的分数
297
- */
298
- zranking(key: RedisKey, start: number | string, stop: number | string): Promise<Map<string, number>>;
299
- }
300
- /**读写数据源实现类 */
301
- declare class ReadWriteDb extends DataSourceFactory {
302
- private readonly readSession;
303
- private readonly writeSession;
304
- /**获取数据源实例 */
305
- getDataSource(): DataSourceFactory;
306
- constructor();
307
- private getConnectionByConfig;
308
- readConnection(): any;
309
- writeConnection(): any;
310
- }
311
- /**RabbitMQ 操作类 */
312
- declare class RabbitMQ {
313
- /**获取 RabbitMQ 实例 */
314
- getRabbitMQ(): RabbitMQ;
315
- /**
316
- * 发送消息到交换机
317
- * @alias publish
318
- * @param exchange 交换机名称
319
- * @param routingKey 交换机路由名称,默认为 ''
320
- * @param message 发送的消息
321
- */
322
- publishMessageToExchange(exchange: string, routingKey: string, message: string): Promise<void>;
323
- /**
324
- * 发送消息到队列
325
- * @alias send
326
- * @param queue 队列名称
327
- * @param message 发送的消息
328
- */
329
- sendMessageToQueue(queue: string, message: string): Promise<void>;
330
- /**
331
- * 发送消息到交换机
332
- * @param exchange 交换机名称
333
- * @param routingKey 交换机路由名称,默认为 ''
334
- * @param message 发送的消息
335
- */
336
- publish(exchange: string, routingKey: string, message: string): Promise<void>;
337
- /**
338
- * 发送消息到队列
339
- * @param queue 队列名称
340
- * @param message 发送的消息
341
- */
342
- send(queue: string, message: string): Promise<void>;
343
- }
344
- /**缓存实现类 */
345
- declare class NodeCache extends CacheFactory {
346
- private NodeCache;
347
- private nodeCacheOptions;
348
- private config;
349
- constructor();
350
- /**获取缓存对象 */
351
- getNodeCache(): CacheFactory;
352
- get(key: string): any;
353
- set(key: string, value: any, expire?: number): void;
354
- del(key: string): void;
355
- has(key: string): boolean;
356
- flush(): void;
357
- }
358
- /**日志实现类 */
359
- declare class LogDefault extends LogFactory {
360
- /**获取日志实例 */
361
- createLog(): LogFactory;
362
- log(message?: any, ...optionalParams: any[]): void;
363
- error(message?: any, ...optionalParams: any[]): void;
364
- }
365
- /**Web 服务实现类,使用 ExpressJS 提供 Web 服务 */
366
- declare class ExpressServer extends ServerFactory {
367
- view: string;
368
- private static;
369
- private favicon;
370
- private compression;
371
- private cookieConfig;
372
- private session;
373
- private redisConfig;
374
- private redisClient;
375
- /**获取 Web 服务实例 */
376
- getSever(): ServerFactory;
377
- setMiddleware(middleware: any): void;
378
- start(port: number): void;
379
- private setDefaultMiddleware;
380
- }
381
- /**Socket IO 装饰器类 */
382
- declare class SocketIo {
383
- public static setIoServer(app, ioSocketConfig);
384
- /**
385
- * Socket IO 事件装饰器
386
- * @param event 事件名称
387
- */
388
- public static onEvent(event: string): (target: any, propertyKey: string) => void;
389
- /**Socket IO 错误捕获装饰器 */
390
- public static onError(target: any, propertyKey: string): void;
391
- /**Socket IO 客户端断开连接事件装饰器 */
392
- public static onDisconnect(target: any, propertyKey: string): void;
393
- /**Socket IO 客户端连接成功事件装饰器 */
394
- public static onConnected(target: any, propertyKey: string): void;
395
- }
396
- /**Socket IO 服务实现类 */
397
- declare const io: IoServer;
398
-
399
- 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, resultType, cache, Model, SocketIo, io };
package/src/typespeed.ts DELETED
@@ -1,110 +0,0 @@
1
- import "reflect-metadata";
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import * as walkSync from "walk-sync";
5
-
6
- let globalConfig = {};
7
- const corePath = __dirname;
8
- const mainPath = path.dirname(getRootPath(new Error().stack.split("\n")) || process.argv[1]);
9
- const configFile = mainPath + "/config.json";
10
- if (fs.existsSync(configFile)) {
11
- globalConfig = JSON.parse(fs.readFileSync(configFile, "utf-8"));
12
- const nodeEnv = process.env.NODE_ENV || "development";
13
- const envConfigFile = mainPath + "/config-" + nodeEnv + ".json";
14
- if (fs.existsSync(envConfigFile)) {
15
- globalConfig = Object.assign(globalConfig, JSON.parse(fs.readFileSync(envConfigFile, "utf-8")));
16
- }
17
- }
18
- globalConfig["MAIN_PATH"] = mainPath;
19
- globalConfig["CORE_PATH"] = corePath;
20
-
21
- function app<T extends { new(...args: any[]): {} }>(constructor: T) {
22
- const coreFiles = walkSync(corePath, { globs: ['**/*.ts'], ignore: ['**/*.d.ts', 'scaffold/**'] });
23
- const mainFiles = walkSync(mainPath, { globs: ['**/*.ts'] });
24
-
25
- (async function () {
26
- try {
27
- for (let p of coreFiles) {
28
- let moduleName = p.replace(".d.ts", "").replace(".ts", "");
29
- await import(corePath + "/" + moduleName);
30
- }
31
-
32
- for (let p of mainFiles) {
33
- let moduleName = p.replace(".d.ts", "").replace(".ts", "");
34
- await import(mainPath + "/" + moduleName);
35
- }
36
- } catch (err) {
37
- console.error(err);
38
- }
39
- //log("main start")
40
- const main = new constructor();
41
- main["main"]();
42
- }());
43
- }
44
-
45
- function config(node: string) {
46
- return globalConfig[node] || null;
47
- }
48
-
49
- function value(configPath: string): any {
50
- return function (target: any, propertyKey: string) {
51
- if (globalConfig === undefined) {
52
- Object.defineProperty(target, propertyKey, {
53
- get: () => {
54
- return undefined;
55
- }
56
- });
57
- } else {
58
- let pathNodes = configPath.split(".");
59
- let nodeValue = globalConfig;
60
- for (let i = 0; i < pathNodes.length; i++) {
61
- nodeValue = nodeValue[pathNodes[i]];
62
- }
63
- Object.defineProperty(target, propertyKey, {
64
- get: () => {
65
- return nodeValue;
66
- }
67
- });
68
- }
69
- };
70
- }
71
-
72
- function getRootPath(lines: string[]) {
73
- // 兼容新旧 Node 栈帧(Node<22: "Function.Module._load" / Node22+: "Function._load")、
74
- // mocha(ts-node) 下 "Context.<anonymous>" 与中间可能插入的 "wrapModuleLoad" 帧:
75
- // 按顺序出现匹配(不要求严格相邻),提高在各种加载器下的容错。
76
- const macths = [/at Function(\.Module)?\._load/, "at Module.require", /at require\b/, /at (Object|Context)\.<anonymous>/];
77
- let matchIndex = 0;
78
- for (let line of lines) {
79
- const matcher = macths[matchIndex];
80
- if (matcher instanceof RegExp ? matcher.test(line) : line.includes(matcher)) {
81
- if (matchIndex === macths.length - 1) {
82
- let arr = line.split("(")[1].split(":")
83
- arr.pop()
84
- arr.pop()
85
- return arr.join(':')
86
- }
87
- matchIndex++;
88
- }
89
- }
90
- return undefined;
91
- }
92
-
93
- export { app, value, config };
94
- export * from "./core.decorator";
95
- export * from "./route.decorator";
96
- export * from "./database.decorator";
97
-
98
- export { default as LogFactory} from "./factory/log-factory.class";
99
- export { default as CacheFactory} from "./factory/cache-factory.class";
100
- export { default as DataSourceFactory} from "./factory/data-source-factory.class";
101
- export { default as ServerFactory} from "./factory/server-factory.class";
102
- export { default as AuthenticationFactory} from "./factory/authentication-factory.class";
103
-
104
- export { default as ExpressServer} from "./default/express-server.class";
105
- export { default as LogDefault} from "./default/log-default.class";
106
- export { default as NodeCache} from "./default/node-cache.class";
107
- export { Redis, redisSubscriber } from "./default/redis.class";
108
- export { default as ReadWriteDb} from "./default/read-write-db.class";
109
- export * from "./default/rabbitmq.class";
110
- export * from "./default/socket-io.class";
@@ -1,76 +0,0 @@
1
-
2
- const chaiObj = require('chai');
3
- chaiObj.use(require("chai-http"));
4
- const expect = chaiObj.expect;
5
- describe("Test Database", () => {
6
- const randomId = random(3000, 5000);
7
- const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
8
- const testDatabase = [
9
- {
10
- "url": "/db/insert?id=" + randomId,
11
- "expect": "Insert success: " + randomId,
12
- },
13
- {
14
- "url": "/db/insert2?id=" + (randomId + 1),
15
- "expect": "Insert success: " + (randomId + 1),
16
- },
17
- {
18
- "url": "/db/update?id=" + randomId,
19
- "expect": "update success: 1",
20
- },
21
- {
22
- "url": "/db/set-cache?value=zzz",
23
- "expect": "set cache success",
24
- },
25
- {
26
- "url": "/db/get-cache",
27
- "expect": "zzz",
28
- }
29
- ]
30
- testDatabase.forEach((testRequest) => {
31
- it(testRequest.url, (done) => {
32
- chaiObj.request(testAddr).get(testRequest.url).end((err, res) => {
33
- chaiObj.assert.equal(testRequest.expect, res.text);
34
- return done();
35
- });
36
- });
37
- });
38
- it("/db/select-row", (done) => {
39
- chaiObj.request(testAddr).get("/db/select-row?id=" + randomId).end((err, res) => {
40
- const dataList = JSON.parse(res.text);
41
- expect(dataList).to.be.an('array');
42
- expect(dataList[0]).to.have.property("id").which.is.a("number").equal(randomId);
43
- done();
44
- });
45
- });
46
- it("/db/select-row twice", (done) => {
47
- chaiObj.request(testAddr).get("/db/select-row?id=" + randomId).end((err, res) => {
48
- const dataList = JSON.parse(res.text);
49
- expect(dataList).to.be.an('array');
50
- expect(dataList[0]).to.have.property("id").which.is.a("number").equal(randomId);
51
- done();
52
- });
53
- });
54
- it("/db/select", (done) => {
55
- chaiObj.request(testAddr).get("/db/select").end((err, res) => {
56
- const dataList = JSON.parse(res.text);
57
- expect(dataList).to.be.an('array');
58
- expect(dataList[0]).to.have.property('id');
59
- done();
60
- });
61
- });
62
- it("/db/select-user", (done) => {
63
- chaiObj.request(testAddr).get("/db/select-user").end((err, res) => {
64
- const dataList = JSON.parse(res.text);
65
- expect(dataList).to.be.an('array');
66
- expect(dataList[0]).to.have.property('id');
67
- done();
68
- });
69
- });
70
- });
71
-
72
- function random(min, max) {
73
- return Math.round(Math.random() * (max - min)) + min;
74
- }
75
-
76
- export {};
@@ -1,42 +0,0 @@
1
- const chaiObj = require('chai');
2
- chaiObj.use(require("chai-http"));
3
-
4
- describe("Test First page", () => {
5
- const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
6
- const firstPageRequests = [
7
- {
8
- "url": "/first",
9
- "expect": "FirstPage index running",
10
- },
11
- {
12
- "url": "/first/sendJson",
13
- "expect": JSON.stringify({
14
- "from": "sendJson",
15
- "to": "Browser"
16
- }),
17
- },
18
- {
19
- "url": "/first/sendResult",
20
- "expect": "sendResult",
21
- },
22
- {
23
- "url": "/first/renderTest",
24
- "expect": "Hello zzz!",
25
- },
26
- {
27
- "url": "/test/error",
28
- "expect": "This is a error log",
29
- }
30
- ]
31
- firstPageRequests.forEach((testRequest) => {
32
- it(testRequest.url, (done) => {
33
- chaiObj.request(testAddr).get(testRequest.url).end((err, res) => {
34
- chaiObj.assert.equal(testRequest.expect, res.text);
35
- return done();
36
- });
37
- });
38
- });
39
-
40
- });
41
-
42
- export {};
package/test/hooks.ts DELETED
@@ -1,13 +0,0 @@
1
- let appClose;
2
- before(function () {
3
- this.timeout(50000);
4
- process.env["LOG"] = "CLOSE";
5
- appClose = require("../app/src/main");
6
- });
7
-
8
- after((done) => {
9
- if(appClose != null){
10
- appClose.default();
11
- }
12
- done();
13
- });
package/test/mq.test.ts DELETED
@@ -1,17 +0,0 @@
1
- const chaiObj = require('chai');
2
-
3
- chaiObj.use(require("chai-http"));
4
-
5
- const expect = chaiObj.expect;
6
-
7
- describe("Test RabbitMQ", () => {
8
- const testAddr = `http://${process.env.LOCAL_HOST || "localhost"}:8081`;
9
- it("/mq/sendByMQClass", (done) => {
10
- chaiObj.request(testAddr).get("/mq/sendByMQClass").end((err, res) => {
11
- expect(res.text).to.be.equal("Sent by MQClass");
12
- done();
13
- });
14
- });
15
- });
16
-
17
- export { };