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