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.
Files changed (94) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/dist/default/rabbitmq.class.js +18 -1
  3. package/dist/default/redis.class.js +14 -1
  4. package/dist/default/socket-io.class.js +53 -4
  5. package/dist/typespeed.d.ts +7 -7
  6. package/package.json +6 -2
  7. package/.github/workflows/test.yml +0 -50
  8. package/app/nodemon.json +0 -5
  9. package/app/package.json +0 -17
  10. package/app/src/aop-test.class.ts +0 -29
  11. package/app/src/config-development.json +0 -26
  12. package/app/src/config-production.json +0 -15
  13. package/app/src/config.json +0 -50
  14. package/app/src/custom-log.class.ts +0 -33
  15. package/app/src/entities/mutil-users.class.ts +0 -5
  16. package/app/src/entities/user-dto.class.ts +0 -3
  17. package/app/src/first-page.class.ts +0 -46
  18. package/app/src/jwt-authentication.class.ts +0 -30
  19. package/app/src/main.ts +0 -24
  20. package/app/src/second-page.class.ts +0 -43
  21. package/app/src/test-bind.class.ts +0 -41
  22. package/app/src/test-database.class.ts +0 -81
  23. package/app/src/test-log.class.ts +0 -11
  24. package/app/src/test-mq.class.ts +0 -21
  25. package/app/src/test-orm.class.ts +0 -63
  26. package/app/src/test-redis.class.ts +0 -45
  27. package/app/src/test-request.class.ts +0 -37
  28. package/app/src/test-socket.class.ts +0 -56
  29. package/app/src/user-model.class.ts +0 -50
  30. package/app/src/views/index.html +0 -1
  31. package/app/src/views/socket.html +0 -23
  32. package/app/src/views/upload.html +0 -14
  33. package/app/static/favicon.ico +0 -0
  34. package/app/static/k.jpg +0 -0
  35. package/app/tsconfig.json +0 -20
  36. package/introduction/decorator/example-import.class.ts +0 -6
  37. package/introduction/decorator/main-app.ts +0 -6
  38. package/introduction/decorator/main-decorator.ts +0 -108
  39. package/introduction/decorator/main-import.ts +0 -1
  40. package/introduction/decorator/main-reflect.ts +0 -25
  41. package/introduction/decorator-next/dist/main.js +0 -116
  42. package/introduction/decorator-next/package.json +0 -14
  43. package/introduction/decorator-next/src/main.ts +0 -64
  44. package/introduction/decorator-next/tsconfig.json +0 -17
  45. package/introduction/decorator-next//346/225/231/347/250/213.md +0 -384
  46. package/introduction/tsconfig.json +0 -23
  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/bind.decorator.ts +0 -50
  53. package/src/core.decorator.ts +0 -184
  54. package/src/database.decorator.ts +0 -446
  55. package/src/decorator-utils.ts +0 -53
  56. package/src/default/default-authentication.class.ts +0 -10
  57. package/src/default/express-server.class.ts +0 -150
  58. package/src/default/log-default.class.ts +0 -9
  59. package/src/default/node-cache.class.ts +0 -40
  60. package/src/default/pages/404.html +0 -226
  61. package/src/default/pages/500.html +0 -713
  62. package/src/default/rabbitmq.class.ts +0 -61
  63. package/src/default/read-write-db.class.ts +0 -53
  64. package/src/default/redis.class.ts +0 -79
  65. package/src/default/socket-io.class.ts +0 -81
  66. package/src/factory/authentication-factory.class.ts +0 -9
  67. package/src/factory/cache-factory.class.ts +0 -7
  68. package/src/factory/data-source-factory.class.ts +0 -4
  69. package/src/factory/log-factory.class.ts +0 -8
  70. package/src/factory/server-factory.class.ts +0 -6
  71. package/src/route.decorator.ts +0 -334
  72. package/src/scaffold/command.ts +0 -40
  73. package/src/scaffold/templates/front-page.class.ts.tpl +0 -12
  74. package/src/scaffold/templates/main.ts.tpl +0 -13
  75. package/src/scaffold/templates/nodemon.json.tpl +0 -7
  76. package/src/scaffold/templates/package.json.tpl +0 -16
  77. package/src/scaffold/templates/tsconfig.json.tpl +0 -17
  78. package/src/typespeed.d.ts +0 -403
  79. package/src/typespeed.ts +0 -139
  80. package/test/bind.test.ts +0 -28
  81. package/test/database.test.ts +0 -76
  82. package/test/decorator-utils.test.ts +0 -42
  83. package/test/first-page.test.ts +0 -42
  84. package/test/hooks.ts +0 -13
  85. package/test/mq.test.ts +0 -17
  86. package/test/orm.test.ts +0 -66
  87. package/test/redis.test.ts +0 -48
  88. package/test/request.test.ts +0 -51
  89. package/test/second-page.test.ts +0 -50
  90. package/test/socket.test.ts +0 -60
  91. package/test-env/docker-compose.test.yml +0 -31
  92. package/test-env/mysql-init/init.sql +0 -8
  93. package/test-env//346/234/254/345/234/260Docker/346/265/213/350/257/225/346/226/271/346/241/210.md +0 -69
  94. package/tsconfig.json +0 -25
package/CHANGELOG.md CHANGED
@@ -4,6 +4,7 @@ typespeed 版本演进记录。本文件 2026-09-06 从 git 历史反推建立
4
4
 
5
5
  ## 2.5.x
6
6
 
7
+ - **2.5.1**:补全 `default/` 族装饰器双签名(`rabbitListener` / `redisSubscriber` / `SocketIo.onEvent`/`onError`/`onDisconnect`/`onConnected`);打包瘦身(`files` 白名单 108→31 文件);`npm pkg fix` 修正 bin 字段;修正 `redisSubscriber` 的 d.ts 签名(2026-09-07)
7
8
  - **2.5.0**:装饰器双轨——支持 TC39 标准装饰器(Stage 2.7),legacy 装饰器零破坏。单份源码运行时双签名感知(`isStd` 判据),覆盖 core/route/database 三族 + 入口 `app`/`value`;新增方法级 `@bind` 装饰器(route 参数名→来源、database 占位符→索引,替代标准模式删除的参数装饰器);`@autoware`/`@resource`/`@bean` 支持显式 token(标准模式无 `design:type`);类型声明宽松化;新增标准模式示例 `introduction/decorator-next/` + `isStd` 单测(2026-09-07)
8
9
 
9
10
  ## 2.4.x
@@ -13,6 +13,7 @@ exports.rabbitListener = exports.RabbitMQ = void 0;
13
13
  const core_decorator_1 = require("../core.decorator");
14
14
  const typespeed_1 = require("../typespeed");
15
15
  const amqplib_1 = require("amqplib");
16
+ const decorator_utils_1 = require("../decorator-utils");
16
17
  let rabbitConnection = null;
17
18
  class RabbitMQ {
18
19
  getRabbitMQ() {
@@ -58,7 +59,23 @@ async function getChannel() {
58
59
  return channel;
59
60
  }
60
61
  function rabbitListener(queue) {
61
- return (target, propertyKey) => {
62
+ return (...args) => {
63
+ if ((0, decorator_utils_1.isStd)(args)) {
64
+ const [, ctx] = (0, decorator_utils_1.getStdArgs)(args);
65
+ ctx.addInitializer(function () {
66
+ const targetConstructor = this.constructor;
67
+ const methodName = String(ctx.name);
68
+ (async function () {
69
+ const channel = await getChannel();
70
+ await channel.assertQueue(queue);
71
+ const targetBean = (0, core_decorator_1.getComponent)(targetConstructor);
72
+ await channel.consume(queue, targetBean[methodName], { noAck: true });
73
+ }());
74
+ });
75
+ return;
76
+ }
77
+ const target = args[0];
78
+ const propertyKey = args[1];
62
79
  (async function () {
63
80
  const channel = await getChannel();
64
81
  await channel.assertQueue(queue);
@@ -13,6 +13,7 @@ exports.redisSubscriber = exports.Redis = void 0;
13
13
  const core_decorator_1 = require("../core.decorator");
14
14
  const ioredis_1 = require("ioredis");
15
15
  const typespeed_1 = require("../typespeed");
16
+ const decorator_utils_1 = require("../decorator-utils");
16
17
  const redisSubscribers = {};
17
18
  class Redis extends ioredis_1.default {
18
19
  getRedis() {
@@ -75,7 +76,19 @@ function redisSubscriber(channel) {
75
76
  console.error(err);
76
77
  }
77
78
  });
78
- return function (target, propertyKey) {
79
+ return function (...args) {
80
+ if ((0, decorator_utils_1.isStd)(args)) {
81
+ const [, ctx] = (0, decorator_utils_1.getStdArgs)(args);
82
+ ctx.addInitializer(function () {
83
+ redisSubscribers[channel] = {
84
+ target: this,
85
+ propertyKey: String(ctx.name)
86
+ };
87
+ });
88
+ return;
89
+ }
90
+ const target = args[0];
91
+ const propertyKey = args[1];
79
92
  redisSubscribers[channel] = {
80
93
  target: target,
81
94
  propertyKey: propertyKey
@@ -4,6 +4,7 @@ exports.io = exports.SocketIo = void 0;
4
4
  const socket_io_1 = require("socket.io");
5
5
  const http_1 = require("http");
6
6
  const core_decorator_1 = require("../core.decorator");
7
+ const decorator_utils_1 = require("../decorator-utils");
7
8
  let io = null;
8
9
  exports.io = io;
9
10
  const listeners = { "event": [], "disconnect": null, "error": null, "connected": null };
@@ -48,26 +49,74 @@ class SocketIo {
48
49
  return httpServer;
49
50
  }
50
51
  static onEvent(event) {
51
- return (target, propertyKey) => {
52
+ return (...args) => {
53
+ if ((0, decorator_utils_1.isStd)(args)) {
54
+ const [, ctx] = (0, decorator_utils_1.getStdArgs)(args);
55
+ ctx.addInitializer(function () {
56
+ listeners["event"].push([{
57
+ target: this,
58
+ propertyKey: String(ctx.name)
59
+ }, event]);
60
+ });
61
+ return;
62
+ }
63
+ const target = args[0];
64
+ const propertyKey = args[1];
52
65
  listeners["event"].push([{
53
66
  target: target,
54
67
  propertyKey: propertyKey
55
68
  }, event]);
56
69
  };
57
70
  }
58
- static onError(target, propertyKey) {
71
+ static onError(...args) {
72
+ if ((0, decorator_utils_1.isStd)(args)) {
73
+ const [, ctx] = (0, decorator_utils_1.getStdArgs)(args);
74
+ ctx.addInitializer(function () {
75
+ listeners["error"] = {
76
+ target: this,
77
+ propertyKey: String(ctx.name)
78
+ };
79
+ });
80
+ return;
81
+ }
82
+ const target = args[0];
83
+ const propertyKey = args[1];
59
84
  listeners["error"] = {
60
85
  target: target,
61
86
  propertyKey: propertyKey
62
87
  };
63
88
  }
64
- static onDisconnect(target, propertyKey) {
89
+ static onDisconnect(...args) {
90
+ if ((0, decorator_utils_1.isStd)(args)) {
91
+ const [, ctx] = (0, decorator_utils_1.getStdArgs)(args);
92
+ ctx.addInitializer(function () {
93
+ listeners["disconnect"] = {
94
+ target: this,
95
+ propertyKey: String(ctx.name)
96
+ };
97
+ });
98
+ return;
99
+ }
100
+ const target = args[0];
101
+ const propertyKey = args[1];
65
102
  listeners["disconnect"] = {
66
103
  target: target,
67
104
  propertyKey: propertyKey
68
105
  };
69
106
  }
70
- static onConnected(target, propertyKey) {
107
+ static onConnected(...args) {
108
+ if ((0, decorator_utils_1.isStd)(args)) {
109
+ const [, ctx] = (0, decorator_utils_1.getStdArgs)(args);
110
+ ctx.addInitializer(function () {
111
+ listeners["connected"] = {
112
+ target: this,
113
+ propertyKey: String(ctx.name)
114
+ };
115
+ });
116
+ return;
117
+ }
118
+ const target = args[0];
119
+ const propertyKey = args[1];
71
120
  listeners["connected"] = {
72
121
  target: target,
73
122
  propertyKey: propertyKey
@@ -175,9 +175,9 @@ declare function after(constructorFunction: any, methodName: string): (...args:
175
175
  /**定时程序装饰器,参数支持 crontab 格式字符串,可根据参数定时执行被装饰的方法 */
176
176
  declare function schedule(cronTime: string | Date): (...args: any[]) => any;
177
177
  /**RabbitMQ 监听装饰器,参数是监听的队列名称,当接受到消息时将执行被装饰方法 */
178
- declare function rabbitListener(queue: string): (target: any, propertyKey: string) => void;
179
- /**Redis 监听装饰器,参数是监听的队列名称,当接受到消息时将执行被装饰方法 */
180
- declare function redisSubscriber(target: any, propertyKey: string): void;
178
+ declare function rabbitListener(queue: string): (...args: any[]) => any;
179
+ /**Redis 监听装饰器,参数是监听的频道名称,当接受到消息时将执行被装饰方法 */
180
+ declare function redisSubscriber(channel: string): (...args: any[]) => any;
181
181
  /** request 对象装饰器,作为路由页面方法参数,获取 request 对象 */
182
182
  declare function req(target: any, propertyKey: string, parameterIndex: number): void;
183
183
  /** response 对象装饰器,作为路由页面方法参数,获取 response 对象 */
@@ -389,13 +389,13 @@ declare class SocketIo {
389
389
  * Socket IO 事件装饰器
390
390
  * @param event 事件名称
391
391
  */
392
- public static onEvent(event: string): (target: any, propertyKey: string) => void;
392
+ public static onEvent(event: string): (...args: any[]) => any;
393
393
  /**Socket IO 错误捕获装饰器 */
394
- public static onError(target: any, propertyKey: string): void;
394
+ public static onError(...args: any[]): any;
395
395
  /**Socket IO 客户端断开连接事件装饰器 */
396
- public static onDisconnect(target: any, propertyKey: string): void;
396
+ public static onDisconnect(...args: any[]): any;
397
397
  /**Socket IO 客户端连接成功事件装饰器 */
398
- public static onConnected(target: any, propertyKey: string): void;
398
+ public static onConnected(...args: any[]): any;
399
399
  }
400
400
  /**Socket IO 服务实现类 */
401
401
  declare const io: IoServer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -13,8 +13,12 @@
13
13
  "prebuild": "rm -rf dist"
14
14
  },
15
15
  "main": "dist/typespeed.js",
16
+ "files": [
17
+ "dist",
18
+ "CHANGELOG.md"
19
+ ],
16
20
  "bin": {
17
- "typespeed": "./dist/scaffold/command.js"
21
+ "typespeed": "dist/scaffold/command.js"
18
22
  },
19
23
  "homepage": "https://github.com/speedphp/typespeed#readme",
20
24
  "repository": {
@@ -1,50 +0,0 @@
1
- name: Tests
2
- 'on':
3
- push:
4
- branches:
5
- - main
6
-
7
- jobs:
8
- test:
9
- name: 'Test TypeSpeed'
10
- runs-on: ubuntu-latest
11
- services:
12
- redis:
13
- image: redis
14
- ports:
15
- - 6379:6379
16
- rabbitmq:
17
- image: rabbitmq:3.8
18
- env:
19
- RABBITMQ_DEFAULT_USER: guest
20
- RABBITMQ_DEFAULT_PASS: guest
21
- ports:
22
- - 5672
23
- steps:
24
- - uses: actions/checkout@v4
25
- - uses: actions/setup-node@v4
26
- with:
27
- node-version: 22
28
- - name: Setup MySQL
29
- run: |
30
- sudo /etc/init.d/mysql start
31
- mysql -e 'CREATE DATABASE test;USE test; \
32
- CREATE TABLE `user` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(100) DEFAULT NULL,PRIMARY KEY (`id`)) \
33
- ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;SHOW TABLES;' -uroot -proot
34
- - name: 'Cache node_modules'
35
- uses: actions/cache@v4
36
- with:
37
- path: ~/.npm
38
- key: ${{ runner.os }}-node-v22-${{ hashFiles('**/package.json') }}
39
- restore-keys: |
40
- ${{ runner.os }}-node-v22-
41
- - name: Install Dependencies
42
- run: npm install
43
- - name: Run Tests with Coverage
44
- run: npm run test-with-coverage
45
- env:
46
- LOCAL_HOST: localhost
47
- - name: Upload coverage reports to Codecov
48
- uses: codecov/codecov-action@v3
49
- env:
50
- CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
package/app/nodemon.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "watch": ["src", "../dist", "../src", "../test"],
3
- "ext": "ts,json",
4
- "exec": "npm test"
5
- }
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
- }
@@ -1,15 +0,0 @@
1
- {
2
- "server": {
3
- "port": "8081"
4
- },
5
- "database": {
6
- "host": "localhost",
7
- "port": "27017",
8
- "name": "test"
9
- },
10
- "view": {
11
- "engine": "mustache",
12
- "path": "./views",
13
- "suffix": "html"
14
- }
15
- }
@@ -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,5 +0,0 @@
1
- import UserDto from "./user-dto.class";
2
-
3
- export default class MutilUsers {
4
- constructor(public group: string, public users: UserDto[]){}
5
- }
@@ -1,3 +0,0 @@
1
- export default class UserDto {
2
- constructor(public id: number, public name: string){}
3
- }
@@ -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
- }