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/app/package.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "test-typespeed",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"watch": "nodemon",
|
|
7
|
-
"test": "ts-node src/main.ts",
|
|
8
|
-
"build": "tsc -p ."
|
|
9
|
-
},
|
|
10
|
-
"author": "",
|
|
11
|
-
"license": "ISC",
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"@types/node": "^18.0.6",
|
|
14
|
-
"tracer": "^1.1.6"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { before, log, component, after } from "../../src/typespeed";
|
|
2
|
-
import FirstPage from "./first-page.class";
|
|
3
|
-
|
|
4
|
-
@component
|
|
5
|
-
export default class AopTest {
|
|
6
|
-
|
|
7
|
-
@before(FirstPage, "index")
|
|
8
|
-
public FirstIndex() {
|
|
9
|
-
log("Before FirstPage index run, at AopTest FirstIndex.");
|
|
10
|
-
log("AopTest FirstIndex run over." + this.getWordsFromAopTest());
|
|
11
|
-
return "FirstIndex";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public getWordsFromAopTest() {
|
|
15
|
-
return "getWordsFromAopTest";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@before(FirstPage, "getTestFromFirstPage")
|
|
19
|
-
public testGetTestFromFirstPage() {
|
|
20
|
-
log("AopTest testGetTestFromFirstPage run over.");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@after(FirstPage, "index")
|
|
24
|
-
public testFirstIndexAfter(result) {
|
|
25
|
-
log("AopTest testFirstIndexAfter run over, result: " + result);
|
|
26
|
-
log(result);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"view": {
|
|
3
|
-
"engine": "mustache",
|
|
4
|
-
"path": "/views/",
|
|
5
|
-
"suffix": "html"
|
|
6
|
-
},
|
|
7
|
-
"mysql": {
|
|
8
|
-
"host": "127.0.0.1",
|
|
9
|
-
"user": "root",
|
|
10
|
-
"password": "root",
|
|
11
|
-
"database": "test"
|
|
12
|
-
},
|
|
13
|
-
"redis": {
|
|
14
|
-
"host": "127.0.0.1",
|
|
15
|
-
"port": "6379",
|
|
16
|
-
"db": 0
|
|
17
|
-
},
|
|
18
|
-
"rabbitmq": {
|
|
19
|
-
"protocol": "amqp",
|
|
20
|
-
"hostname": "127.0.0.1",
|
|
21
|
-
"port": 5672,
|
|
22
|
-
"username": "guest",
|
|
23
|
-
"password": "guest"
|
|
24
|
-
},
|
|
25
|
-
"socket":{}
|
|
26
|
-
}
|
package/app/src/config.json
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"view": {
|
|
3
|
-
"engine": "mustache",
|
|
4
|
-
"path": "./src/views",
|
|
5
|
-
"suffix": "html"
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
"compression": {
|
|
9
|
-
"level": 9
|
|
10
|
-
},
|
|
11
|
-
"cookie": {
|
|
12
|
-
"secret": "catme",
|
|
13
|
-
"options": {}
|
|
14
|
-
},
|
|
15
|
-
"session": {
|
|
16
|
-
"trust proxy": false,
|
|
17
|
-
"secret": "keyboard cat",
|
|
18
|
-
"resave": false,
|
|
19
|
-
"saveUninitialized": true,
|
|
20
|
-
"cookie": {
|
|
21
|
-
"secure": false
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"mysql": {
|
|
25
|
-
"master": {
|
|
26
|
-
"host": "localhost",
|
|
27
|
-
"user": "root",
|
|
28
|
-
"password": "123456",
|
|
29
|
-
"database": "test"
|
|
30
|
-
},
|
|
31
|
-
"slave": [
|
|
32
|
-
{
|
|
33
|
-
"host": "localhost",
|
|
34
|
-
"user": "root",
|
|
35
|
-
"password": "123456",
|
|
36
|
-
"database": "test"
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
},
|
|
40
|
-
"redis": {
|
|
41
|
-
"host": "localhost",
|
|
42
|
-
"port": "6379",
|
|
43
|
-
"db": 0
|
|
44
|
-
},
|
|
45
|
-
"jwt" : {
|
|
46
|
-
"secret": "shhhhhhared-secret",
|
|
47
|
-
"algorithms": ["HS256"],
|
|
48
|
-
"ignore": ["/first", "/second/testSession"]
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as tracer from "tracer";
|
|
2
|
-
import { bean, LogFactory } from "../../src/typespeed";
|
|
3
|
-
|
|
4
|
-
export default class CustomLog extends LogFactory {
|
|
5
|
-
private logger = tracer.console({
|
|
6
|
-
format: "[{{title}}] {{timestamp}} {{file}}:{{line}} ({{method}}) {{message}}",
|
|
7
|
-
dateformat: "yyyy-mm-dd HH:MM:ss",
|
|
8
|
-
stackIndex: 2,
|
|
9
|
-
preprocess: function (data) {
|
|
10
|
-
data.title = data.title.toUpperCase();
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
@bean
|
|
15
|
-
public createLog(): LogFactory {
|
|
16
|
-
return new CustomLog();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public log(message?: any, ...optionalParams: any[]) : void{
|
|
20
|
-
if(process.env.LOG === "CLOSE") return;
|
|
21
|
-
this.logger.log(message, ...optionalParams);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public error(message?: any, ...optionalParams: any[]) : void {
|
|
25
|
-
this.logger.error(message, ...optionalParams);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public debug(message?: any, ...optionalParams: any[]) : void {
|
|
29
|
-
if(process.env.NODE_ENV === "development"){
|
|
30
|
-
this.logger.debug(message, ...optionalParams);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
//import * as jwttoken from "jsonwebtoken";
|
|
2
|
-
import { log, component, getMapping } from "../../src/typespeed";
|
|
3
|
-
|
|
4
|
-
@component
|
|
5
|
-
export default class FirstPage {
|
|
6
|
-
|
|
7
|
-
@getMapping("/first")
|
|
8
|
-
public index(req: any, res: any) {
|
|
9
|
-
log("FirstPage index running" + this.getTestFromFirstPage());
|
|
10
|
-
res.send("FirstPage index running");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@getMapping("/first/sendJson")
|
|
14
|
-
public sendJson() {
|
|
15
|
-
log("FirstPage sendJson running");
|
|
16
|
-
return {
|
|
17
|
-
"from": "sendJson",
|
|
18
|
-
"to": "Browser"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@getMapping("/first/sendResult")
|
|
23
|
-
public sendResult() {
|
|
24
|
-
log("FirstPage sendResult running");
|
|
25
|
-
return "sendResult";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@getMapping("/first/renderTest")
|
|
29
|
-
public renderTest(req: any, res: any) {
|
|
30
|
-
res.render("index", { name: "zzz" });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// @getMapping("/login")
|
|
34
|
-
// login() {
|
|
35
|
-
// const token = jwttoken.sign({ foo: 'bar' }, 'shhhhhhared-secret');
|
|
36
|
-
// /**
|
|
37
|
-
// * 将这里获得的token,放到header的Authorization中。
|
|
38
|
-
// * 值是:Bearer + token
|
|
39
|
-
// */
|
|
40
|
-
// return token;
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
public getTestFromFirstPage() {
|
|
44
|
-
return "getTestFromFirstPage";
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { AuthenticationFactory, bean, config } from "../../src/typespeed";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import { expressjwt, GetVerificationKey } from "express-jwt";
|
|
4
|
-
import * as jwt from 'jsonwebtoken';
|
|
5
|
-
|
|
6
|
-
const jwtConfig: {
|
|
7
|
-
secret: jwt.Secret | GetVerificationKey;
|
|
8
|
-
algorithms: jwt.Algorithm[];
|
|
9
|
-
ignore: string[];
|
|
10
|
-
} = config("jwt");
|
|
11
|
-
|
|
12
|
-
export default class JwtAuthentication extends AuthenticationFactory {
|
|
13
|
-
|
|
14
|
-
@bean
|
|
15
|
-
public getJwtAuthentication(): AuthenticationFactory {
|
|
16
|
-
return new JwtAuthentication();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public preHandle(req: express.Request, res: express.Response, next: express.NextFunction): void {
|
|
20
|
-
if(!jwtConfig.ignore.includes(req.path)) {
|
|
21
|
-
const jwtMiddleware = expressjwt(jwtConfig);
|
|
22
|
-
jwtMiddleware(req, res, (err) => {
|
|
23
|
-
if (err) {
|
|
24
|
-
//next(err);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
next();
|
|
29
|
-
}
|
|
30
|
-
}
|
package/app/src/main.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { app, log, autoware, ServerFactory } from "../../src/typespeed";
|
|
2
|
-
//import * as basicAuth from "express-basic-auth"
|
|
3
|
-
let appServer = null;
|
|
4
|
-
|
|
5
|
-
@app
|
|
6
|
-
class Main {
|
|
7
|
-
|
|
8
|
-
@autoware
|
|
9
|
-
public server : ServerFactory;
|
|
10
|
-
|
|
11
|
-
public main(){
|
|
12
|
-
// this.server.setMiddleware(basicAuth({
|
|
13
|
-
// users: { 'admin': 'supersecret' }
|
|
14
|
-
// }));
|
|
15
|
-
appServer = this.server.start(8081);
|
|
16
|
-
log('start application');
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default () => {
|
|
21
|
-
if (appServer != null) {
|
|
22
|
-
appServer.close();
|
|
23
|
-
}
|
|
24
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { getMapping, postMapping, upload, jwt, log, component } from "../../src/typespeed";
|
|
2
|
-
|
|
3
|
-
@component
|
|
4
|
-
export default class SecondPage {
|
|
5
|
-
|
|
6
|
-
@getMapping("/second/setCookie")
|
|
7
|
-
setCookiePage(req, res) {
|
|
8
|
-
res.cookie("name", "zzz");
|
|
9
|
-
return "setCookie";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@getMapping("/second/getCookie")
|
|
13
|
-
getCookiePage(req, res) {
|
|
14
|
-
const cookieName = req.cookies.name;
|
|
15
|
-
return "getCookie: " + cookieName;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@getMapping("/second/testSession")
|
|
19
|
-
testForSession(req, res) {
|
|
20
|
-
req.session.view = req.session.view ? req.session.view + 1 : 1;
|
|
21
|
-
return "testForSession: " + req.session.view;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@postMapping("/upload")
|
|
25
|
-
@upload
|
|
26
|
-
public upload(req, res) {
|
|
27
|
-
const files = req.files;
|
|
28
|
-
log(files);
|
|
29
|
-
log("uploaded");
|
|
30
|
-
res.send("upload success");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@jwt({ secret: "shhhhhhared-secret", algorithms: ["HS256"] })
|
|
34
|
-
@postMapping("/form")
|
|
35
|
-
form(req, res) {
|
|
36
|
-
res.render("upload");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@getMapping("/second/testError")
|
|
40
|
-
testError(req, res) {
|
|
41
|
-
throw new Error('Test Error');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { component, getMapping, bind, resource, autoware, bean, insert } from "../../src/typespeed";
|
|
2
|
-
import UserModel from "./user-model.class";
|
|
3
|
-
|
|
4
|
-
class TestBean {
|
|
5
|
-
name = "test-bean";
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
@component
|
|
9
|
-
export default class TestBind {
|
|
10
|
-
|
|
11
|
-
@bean(TestBean)
|
|
12
|
-
getBeanInstance() { return new TestBean(); }
|
|
13
|
-
|
|
14
|
-
@autoware(TestBean)
|
|
15
|
-
private autowired: TestBean;
|
|
16
|
-
|
|
17
|
-
@resource(UserModel, "user")
|
|
18
|
-
private userModel: UserModel;
|
|
19
|
-
|
|
20
|
-
@getMapping("/bind/param/:id")
|
|
21
|
-
@bind({ id: "reqParam", name: "reqQuery" })
|
|
22
|
-
async bindParam(id: string, name: string) {
|
|
23
|
-
return { id, name };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@getMapping("/bind/token")
|
|
27
|
-
async bindToken(req, res) {
|
|
28
|
-
res.send(this.autowired.name + "|" + (this.userModel ? "model-ok" : "model-null"));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@getMapping("/bind/db")
|
|
32
|
-
async bindDb(req, res) {
|
|
33
|
-
const id = req.query.id || 1;
|
|
34
|
-
const newId = await this.addRowByBind("bind name " + id, id);
|
|
35
|
-
res.send("bind insert: " + newId);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@insert("Insert into `user` (id, name) values (#{id}, #{name})")
|
|
39
|
-
@bind({ name: 0, id: 1 })
|
|
40
|
-
private async addRowByBind(newName: string, id: number) { }
|
|
41
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { insert, update, select, param, resultType, cache, CacheFactory, getMapping, component, log, autoware } from "../../src/typespeed";
|
|
2
|
-
import UserDto from "./entities/user-dto.class";
|
|
3
|
-
|
|
4
|
-
@component
|
|
5
|
-
export default class TestDatabase {
|
|
6
|
-
|
|
7
|
-
@autoware
|
|
8
|
-
private cacheBean: CacheFactory;
|
|
9
|
-
|
|
10
|
-
@getMapping("/db/insert")
|
|
11
|
-
async insert(req, res) {
|
|
12
|
-
const id = req.query.id || 1;
|
|
13
|
-
const newId = await this.addRow("new name " + id, id);
|
|
14
|
-
res.send("Insert success: " + newId);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@getMapping("/db/insert2")
|
|
18
|
-
async insertByObject(req, res) {
|
|
19
|
-
const newId = await this.addRowByObject({
|
|
20
|
-
"id": req.query.id, "name": "new name " + req.query.id
|
|
21
|
-
});
|
|
22
|
-
res.send("Insert success: " + newId);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@getMapping("/db/update")
|
|
26
|
-
async update(req, res) {
|
|
27
|
-
const affectedRows = await this.editRow(req.query.id);
|
|
28
|
-
log("Update rows: " + affectedRows);
|
|
29
|
-
res.send("update success: " + affectedRows);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@getMapping("/db/select")
|
|
33
|
-
async select(req, res) {
|
|
34
|
-
const rows = await this.selectRow();
|
|
35
|
-
log("select rows: " + rows);
|
|
36
|
-
res.send(rows);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@getMapping("/db/select-row")
|
|
40
|
-
async selectById(req, res) {
|
|
41
|
-
const row = await this.findRow(req.query.id);
|
|
42
|
-
res.send(row);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@getMapping("/db/select-user")
|
|
46
|
-
async selectUser(req, res) {
|
|
47
|
-
const users: UserDto[] = await this.findUsers();
|
|
48
|
-
res.send(users);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
@getMapping("/db/set-cache")
|
|
52
|
-
testCache(req, res) {
|
|
53
|
-
this.cacheBean.set("test", req.query.value || "test");
|
|
54
|
-
res.send("set cache success");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@getMapping("/db/get-cache")
|
|
58
|
-
displayCache(req, res) {
|
|
59
|
-
res.send(this.cacheBean.get("test"));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
@insert("Insert into `user` (id, name) values (#{id}, #{name})")
|
|
63
|
-
private async addRow(@param("name") newName: string, @param("id") id: number) { }
|
|
64
|
-
|
|
65
|
-
@insert("Insert into `user` (id, name) values (#{id}, #{name})")
|
|
66
|
-
private async addRowByObject(myParams: object) { }
|
|
67
|
-
|
|
68
|
-
@update("Update `user` set `name` = 'test5' where id = #{id}")
|
|
69
|
-
private async editRow(@param("id") id: number) { }
|
|
70
|
-
|
|
71
|
-
@select("Select * from `user`")
|
|
72
|
-
private async selectRow() { }
|
|
73
|
-
|
|
74
|
-
@cache(1800)
|
|
75
|
-
@select("Select * from `user` where id = #{id}")
|
|
76
|
-
private async findRow(@param("id") id: number) { }
|
|
77
|
-
|
|
78
|
-
@resultType(UserDto)
|
|
79
|
-
@select("Select * from `user`")
|
|
80
|
-
private findUsers(): UserDto[] { return; }
|
|
81
|
-
}
|
package/app/src/test-mq.class.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { component, getMapping, autoware, log, RabbitMQ, rabbitListener } from "../../src/typespeed";
|
|
2
|
-
import { connect } from "amqplib";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@component
|
|
6
|
-
export default class TestMq {
|
|
7
|
-
|
|
8
|
-
@autoware
|
|
9
|
-
private rabbitMQ: RabbitMQ;
|
|
10
|
-
|
|
11
|
-
@rabbitListener("myqueues")
|
|
12
|
-
public async listen(message) {
|
|
13
|
-
log(" Received by Decorator '%s'", message.content.toString());
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@getMapping("/mq/sendByMQClass")
|
|
17
|
-
async sendByMQClass() {
|
|
18
|
-
this.rabbitMQ.send("myqueues", "hello world, by MQClass");
|
|
19
|
-
return "Sent by MQClass";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { resource, component, log, autoware, schedule, getMapping, postMapping, Redis } from "../../src/typespeed";
|
|
2
|
-
import UserModel from "./user-model.class";
|
|
3
|
-
|
|
4
|
-
@component
|
|
5
|
-
export default class TestOrm {
|
|
6
|
-
|
|
7
|
-
@resource("user")
|
|
8
|
-
private userModel: UserModel;
|
|
9
|
-
|
|
10
|
-
@getMapping("/orm/first")
|
|
11
|
-
async firstTest(req, res) {
|
|
12
|
-
const results = await this.userModel.getUsers();
|
|
13
|
-
res.send("first test, to " + results);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@getMapping("/orm/one")
|
|
17
|
-
async findOneTest(req, res) {
|
|
18
|
-
const results = await this.userModel.getUser(req.query.id || 0);
|
|
19
|
-
res.send("find one test, to " + results);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@getMapping("/orm/delete")
|
|
23
|
-
async deleteTest(req, res) {
|
|
24
|
-
const results = await this.userModel.remove(req.query.id || 0);
|
|
25
|
-
res.send("remove user, results: " + results);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@getMapping("/orm/count")
|
|
29
|
-
async countTest(req, res) {
|
|
30
|
-
const total = await this.userModel.count();
|
|
31
|
-
res.send({"count": total});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@getMapping("/orm/new")
|
|
35
|
-
async newUserTest(req, res) {
|
|
36
|
-
const newId = await this.userModel.newUsers();
|
|
37
|
-
res.send({"newId": newId});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@getMapping("/orm/page/calculate")
|
|
41
|
-
async calculatePage(req, res) {
|
|
42
|
-
const pages = this.userModel.pager(15, 376);
|
|
43
|
-
res.json(pages);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@getMapping("/orm/pages/:id")
|
|
47
|
-
async findPage(req, res) {
|
|
48
|
-
const results = await this.userModel.findAll("1", { id: -1 }, "*", { page: req.params.id, pageSize: 3 });
|
|
49
|
-
log(this.userModel.page);
|
|
50
|
-
res.json(results);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@postMapping("/orm/edit")
|
|
54
|
-
async updateTest(req, res) {
|
|
55
|
-
const effectRows = await this.userModel.editUser(req.body.id, req.body.name);
|
|
56
|
-
res.send({"effectRows": effectRows});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//@schedule("* * * * * *")
|
|
60
|
-
myTimer() {
|
|
61
|
-
log("myTimer running");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Redis, component, redisSubscriber, autoware, getMapping, log, reqQuery } from "../../src/typespeed";
|
|
2
|
-
|
|
3
|
-
@component
|
|
4
|
-
export default class TestRedis {
|
|
5
|
-
@autoware
|
|
6
|
-
private redisObj: Redis;
|
|
7
|
-
|
|
8
|
-
@redisSubscriber("mychannel")
|
|
9
|
-
public listen(message) {
|
|
10
|
-
log("Received by Decorator '%s'", message);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
@getMapping("/redis/publish")
|
|
14
|
-
async redisPublish() {
|
|
15
|
-
await this.redisObj.publish("mychannel", "Hello World");
|
|
16
|
-
return "Published!";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@getMapping("/redis")
|
|
20
|
-
async redisString() {
|
|
21
|
-
await this.redisObj.set("redisKey", "Hello World");
|
|
22
|
-
const value = await this.redisObj.get("redisKey");
|
|
23
|
-
return "get from redis: " + value;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@getMapping("/redis/add")
|
|
27
|
-
async addZset(@reqQuery name: string, @reqQuery score: number) {
|
|
28
|
-
log("add zset: %s, %s", name, score)
|
|
29
|
-
await this.redisObj.zadd("scoreSet", score, name);
|
|
30
|
-
return "add zset success";
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@getMapping("/redis/ranking")
|
|
34
|
-
async listRanking() {
|
|
35
|
-
const list = await this.redisObj.zrevranking("scoreSet", 0, -1);
|
|
36
|
-
return Object.fromEntries(list);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
@getMapping("/redis/list")
|
|
40
|
-
async listZset() {
|
|
41
|
-
const list = await this.redisObj.zranking("scoreSet", 0, -1);
|
|
42
|
-
log("list zset: %s", JSON.stringify(Object.fromEntries(list)));
|
|
43
|
-
return Object.fromEntries(list);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { component, getMapping, postMapping, log, req, res, reqQuery, reqBody, reqForm, reqParam } from "../../src/typespeed";
|
|
2
|
-
import MutilUsers from "./entities/mutil-users.class";
|
|
3
|
-
import UserDto from "./entities/user-dto.class";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@component
|
|
7
|
-
export default class TestRequest {
|
|
8
|
-
|
|
9
|
-
@getMapping("/request/res")
|
|
10
|
-
testRes(@req req, @res res) {
|
|
11
|
-
res.send("test res");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@getMapping("/request/query")
|
|
15
|
-
async testQuery(req, res, @reqQuery id: number): Promise<MutilUsers> {
|
|
16
|
-
log("id: " + id);
|
|
17
|
-
return Promise.resolve(new MutilUsers("group", [new UserDto(1, "name"), new UserDto(2, "name")]));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@postMapping("/request/body")
|
|
21
|
-
testBody(@res res, @reqBody body: UserDto):MutilUsers {
|
|
22
|
-
log("body: " + JSON.stringify(body));
|
|
23
|
-
return new MutilUsers("group", [body]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@postMapping("/request/form")
|
|
27
|
-
testForm(@res res, @reqForm("name") name: string) {
|
|
28
|
-
log("form: " + JSON.stringify(name));
|
|
29
|
-
res.send("Got name: " + name);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@getMapping("/request/param/:id")
|
|
33
|
-
testParam(@res res, @reqParam id: number) {
|
|
34
|
-
log("id: " + id);
|
|
35
|
-
res.send("test param: " + id);
|
|
36
|
-
}
|
|
37
|
-
}
|