typespeed 2.5.0 → 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.
- package/CHANGELOG.md +1 -0
- 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 +6 -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
|
@@ -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
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { SocketIo, getMapping, component, io } from "../../src/typespeed";
|
|
2
|
-
|
|
3
|
-
@component
|
|
4
|
-
export default class TestSocket {
|
|
5
|
-
|
|
6
|
-
static names = ["LiLei", "HanMeiMei"];
|
|
7
|
-
|
|
8
|
-
static loginUsers: Map<string, string> = new Map<string, string>();
|
|
9
|
-
|
|
10
|
-
@SocketIo.onConnected
|
|
11
|
-
public connected(socket, next) {
|
|
12
|
-
// 从 names 里面取出一个名字
|
|
13
|
-
let name = TestSocket.names.pop();
|
|
14
|
-
TestSocket.loginUsers.set(socket.id, name);
|
|
15
|
-
//io.sockets.emit("all", "We have a new member: " + name);
|
|
16
|
-
//console.log(socket.handshake);
|
|
17
|
-
//console.log(socket.id);
|
|
18
|
-
//next(new Error("test-error"));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@SocketIo.onDisconnect
|
|
22
|
-
public disconnet(socket, reason) {
|
|
23
|
-
io.sockets.emit("all", "We lost a member by: " + reason);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@SocketIo.onEvent("test-error")
|
|
27
|
-
public testError(socket, message) {
|
|
28
|
-
throw new Error("test-error");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@SocketIo.onError
|
|
32
|
-
public error(socket, err) {
|
|
33
|
-
io.sockets.emit("all", "We have a problem!");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@SocketIo.onEvent("say")
|
|
37
|
-
public say(socket, message) {
|
|
38
|
-
io.sockets.emit("all", TestSocket.loginUsers.get(socket.id) + " said: " + message);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@SocketIo.onEvent("join")
|
|
42
|
-
public join(socket, message) {
|
|
43
|
-
socket.join("private-room");
|
|
44
|
-
io.to("private-room").emit("all", TestSocket.loginUsers.get(socket.id) + " joined private-room");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@SocketIo.onEvent("say-inroom")
|
|
48
|
-
public sayInRoom(socket, message) {
|
|
49
|
-
io.to("private-room").emit("all", TestSocket.loginUsers.get(socket.id) + " said in Room: " + message);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@getMapping("/socketIo")
|
|
53
|
-
public socketIoPage(req, res) {
|
|
54
|
-
res.render("socket");
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { log, Model } from "../../src/typespeed";
|
|
2
|
-
import UserDto from "./entities/user-dto.class";
|
|
3
|
-
|
|
4
|
-
export default class UserModel extends Model {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
async getUsers() {
|
|
8
|
-
const users = await this.findAll({
|
|
9
|
-
id: { $lt: 10, $lte: 20 }, "name": { $like: "%a%" },
|
|
10
|
-
$or: [{ id: 1 }, { id: 2 }]
|
|
11
|
-
}, "id asc", "*", { page: 1, pageSize: 10 });
|
|
12
|
-
log("users", users);
|
|
13
|
-
return "getUsers";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async getUser(id: number) {
|
|
17
|
-
const user = await this.find({ id: id }, "id asc", "*");
|
|
18
|
-
log("user", user);
|
|
19
|
-
return "getUser";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async newUsers() {
|
|
23
|
-
const newId = this.random(1000, 2000);
|
|
24
|
-
await this.create([
|
|
25
|
-
new UserDto(newId, "UserDto " + newId),
|
|
26
|
-
new UserDto(newId+1, "UserDto " + (newId+1)),
|
|
27
|
-
{ id: newId+2, name: "UserDto " + (newId+2) },
|
|
28
|
-
]);
|
|
29
|
-
return newId;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async remove(id: number) {
|
|
33
|
-
const result = await this.delete({ id: id });
|
|
34
|
-
return "remove rows: " + result;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async count():Promise<number> {
|
|
38
|
-
const result = await this.findCount("1");
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async editUser(id: number, name: string) {
|
|
43
|
-
const effectRows = await this.update({ id: id }, { name: name });
|
|
44
|
-
return effectRows;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private random(min, max) {
|
|
48
|
-
return Math.round(Math.random() * (max - min)) + min;
|
|
49
|
-
}
|
|
50
|
-
}
|
package/app/src/views/index.html
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Hello {{ name }}!
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<title>Socket Test</title>
|
|
5
|
-
<script src="https://cdn.socket.io/4.7.1/socket.io.min.js"></script>
|
|
6
|
-
<script>
|
|
7
|
-
var socket = io('http://localhost:8081');
|
|
8
|
-
socket.on('connect', function() {
|
|
9
|
-
console.log('connected');
|
|
10
|
-
});
|
|
11
|
-
socket.on('all', function(data) {
|
|
12
|
-
console.log(data);
|
|
13
|
-
});
|
|
14
|
-
</script>
|
|
15
|
-
</head>
|
|
16
|
-
<body>
|
|
17
|
-
<button onclick="socket.emit('say', 'I say some thing')">TestSay</button>
|
|
18
|
-
<button onclick="socket.emit('join', 'I want to join the room')">Join</button>
|
|
19
|
-
<button onclick="socket.emit('say-inroom', 'say some in room')">InRoom</button>
|
|
20
|
-
<button onclick="socket.emit('test-error', 'this is a error')">Test Error</button>
|
|
21
|
-
<button onclick="socket.close()">Close</button>
|
|
22
|
-
</body>
|
|
23
|
-
</html>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
</head>
|
|
5
|
-
|
|
6
|
-
<body>
|
|
7
|
-
<form action="/upload" enctype="multipart/form-data" method="post">
|
|
8
|
-
<input type="text" name="title"><br>
|
|
9
|
-
<input type="file" name="upload" multiple="multiple"><br>
|
|
10
|
-
<input type="submit" value="Upload">
|
|
11
|
-
</form>
|
|
12
|
-
</body>
|
|
13
|
-
|
|
14
|
-
</html>
|
package/app/static/favicon.ico
DELETED
|
Binary file
|
package/app/static/k.jpg
DELETED
|
Binary file
|
package/app/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "CommonJS",
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"emitDecoratorMetadata": true,
|
|
6
|
-
"experimentalDecorators": true,
|
|
7
|
-
"allowSyntheticDefaultImports": true,
|
|
8
|
-
"forceConsistentCasingInFileNames": true,
|
|
9
|
-
"target": "ES2017",
|
|
10
|
-
"sourceMap": true,
|
|
11
|
-
"outDir": "./dist",
|
|
12
|
-
"baseUrl": "./",
|
|
13
|
-
"typeRoots": [
|
|
14
|
-
"node_modules/@types"
|
|
15
|
-
],
|
|
16
|
-
},
|
|
17
|
-
"include": [
|
|
18
|
-
"./src/**/*.ts"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
@atClassWithArgs(1, 2, 3)
|
|
4
|
-
class SecondClass {}
|
|
5
|
-
|
|
6
|
-
@atClass
|
|
7
|
-
export default class FirstClass {
|
|
8
|
-
|
|
9
|
-
@atPropertyWithArgs("Li", "Mei")
|
|
10
|
-
private name: string;
|
|
11
|
-
|
|
12
|
-
@atProperty
|
|
13
|
-
private age: number;
|
|
14
|
-
|
|
15
|
-
@atAccessor
|
|
16
|
-
get newname(): string {
|
|
17
|
-
return this.name;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@atMethod
|
|
21
|
-
changeName(name: string): SecondClass {
|
|
22
|
-
this.name = name;
|
|
23
|
-
return new SecondClass();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@atMethodWithArgs("New", "Type")
|
|
27
|
-
change(name: string, @atParameter age: number): void {
|
|
28
|
-
this.age = age;
|
|
29
|
-
this.name = name;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getName(): string {
|
|
33
|
-
return this.name;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const obj = new FirstClass();
|
|
38
|
-
|
|
39
|
-
console.log("FirstClass对象调用getName()取得装饰器赋值:", obj.getName());
|
|
40
|
-
|
|
41
|
-
// 类装饰器
|
|
42
|
-
function atClass(target: any) {
|
|
43
|
-
console.log("类装饰器,类名是:", target.name);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 类装饰器,带参数
|
|
47
|
-
function atClassWithArgs(...args: any[]) {
|
|
48
|
-
return function (target: any) {
|
|
49
|
-
console.log("类装饰器有参数,参数值:", args.join(","));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 方法装饰器
|
|
54
|
-
function atMethod(target: any, propertyKey: string) {
|
|
55
|
-
const returnType: any = Reflect.getMetadata("design:returntype", target, propertyKey);
|
|
56
|
-
console.log("方法装饰器,获得返回类型:", returnType.name);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 方法装饰器,带参数
|
|
60
|
-
function atMethodWithArgs(...args: any[]) {
|
|
61
|
-
return function (target: any, propertyKey: string) {
|
|
62
|
-
console.log("方法装饰器有参数,参数值:", args.join(","));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 成员变量装饰器
|
|
67
|
-
function atProperty(target: any, propertyKey: string) {
|
|
68
|
-
const propertyType: any = Reflect.getMetadata("design:type", target, propertyKey);
|
|
69
|
-
console.log("变量装饰器,获得变量类型:", propertyType.name);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 成员变量装饰器,带参数
|
|
73
|
-
function atPropertyWithArgs(...args: any[]) {
|
|
74
|
-
return function (target: any, propertyKey: string) {
|
|
75
|
-
console.log("变量装饰器有参数,参数值:", args.join(","));
|
|
76
|
-
Object.defineProperty(target, propertyKey, {
|
|
77
|
-
get: () => {
|
|
78
|
-
return args;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// 访问器装饰器
|
|
85
|
-
function atAccessor(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
86
|
-
const returnType: any = Reflect.getMetadata("design:type", target, propertyKey);
|
|
87
|
-
console.log("访问器装饰器,访问器类型是:", returnType, ",值是:", target[propertyKey]);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 访问器装饰器,带参数
|
|
91
|
-
function atAccessorWithArgs(...args: any[]) {
|
|
92
|
-
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
93
|
-
console.log("访问器装饰器,参数值:", args.join(","));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// 参数装饰器
|
|
98
|
-
function atParameter(target: any, propertyKey: string, parameterIndex: number) {
|
|
99
|
-
const parameterType: any = Reflect.getMetadata("design:paramtypes", target, propertyKey);
|
|
100
|
-
console.log("参数装饰器,参数位置在:", parameterIndex, "参数类型是:", parameterType[parameterIndex].name);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// 参数装饰器,带参数
|
|
104
|
-
function atParameterWithArgs(...args: any[]) {
|
|
105
|
-
return function (target: any, propertyKey: string, parameterIndex: number) {
|
|
106
|
-
console.log("参数装饰器有参数,参数值:", args.join(","));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import("./example-import.class");
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
class MainReflect {
|
|
4
|
-
@injectAge(10)
|
|
5
|
-
private age: number;
|
|
6
|
-
|
|
7
|
-
@findReturn
|
|
8
|
-
getAge(): Number {
|
|
9
|
-
return this.age;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const mainReflect = new MainReflect();
|
|
14
|
-
console.log("获得Age值:", mainReflect.getAge());
|
|
15
|
-
|
|
16
|
-
function injectAge(arg: Number) {
|
|
17
|
-
return function (target: any, propertyKey: string) {
|
|
18
|
-
Object.defineProperty(target, propertyKey, {get: () => {return arg;}});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function findReturn(target: any, propertyKey: string) {
|
|
23
|
-
const returnType: any = Reflect.getMetadata("design:returntype", target, propertyKey);
|
|
24
|
-
console.log(target[propertyKey].name, "的返回类型是:", returnType.name);
|
|
25
|
-
}
|