zenweb 2.9.0 → 3.0.0
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/README.md +41 -61
- package/dist/index.d.ts +2 -3
- package/dist/index.js +9 -18
- package/dist/types.d.ts +4 -5
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -13,66 +13,44 @@ package.json
|
|
|
13
13
|
"private": true,
|
|
14
14
|
"main": "app/index.js",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"dev": "cross-env DEBUG=* NODE_ENV=development
|
|
16
|
+
"dev": "cross-env DEBUG=* NODE_ENV=development ts-node src/index.ts",
|
|
17
17
|
"build": "tsc",
|
|
18
18
|
"start": "node app"
|
|
19
|
-
},
|
|
20
|
-
"nodemonConfig": {
|
|
21
|
-
"ignore": [
|
|
22
|
-
"**/typings/**"
|
|
23
|
-
]
|
|
24
19
|
}
|
|
25
20
|
}
|
|
26
21
|
```
|
|
27
22
|
|
|
28
23
|
```bash
|
|
29
24
|
$ npm i zenweb
|
|
30
|
-
$ npm i cross-env nodemon -D
|
|
31
25
|
```
|
|
32
26
|
|
|
33
|
-
|
|
27
|
+
src/index.ts
|
|
34
28
|
```ts
|
|
35
29
|
import { create } from 'zenweb';
|
|
36
30
|
|
|
37
|
-
const app = create(
|
|
38
|
-
// add optional module
|
|
39
|
-
// $ npm i @zenweb/sentry @zenweb/cors @zenweb/validation
|
|
40
|
-
sentry: { dsn: 'xxxxx' },
|
|
41
|
-
cors: { origin: '*' },
|
|
42
|
-
validation: {},
|
|
43
|
-
});
|
|
44
|
-
|
|
31
|
+
const app = create();
|
|
45
32
|
app.start();
|
|
46
33
|
```
|
|
47
34
|
|
|
48
|
-
|
|
35
|
+
src/controller/hello.ts
|
|
49
36
|
```ts
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
ctx
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
router.get('/error', ctx => {
|
|
66
|
-
ctx.fail('error info');
|
|
67
|
-
console.log('Will not output');
|
|
68
|
-
});
|
|
37
|
+
import { Context, inject, mapping } from 'zenweb';
|
|
38
|
+
import { HelloService } from '../service/hello_service';
|
|
39
|
+
|
|
40
|
+
export class Index {
|
|
41
|
+
@inject
|
|
42
|
+
hello: HelloService;
|
|
43
|
+
|
|
44
|
+
@mapping({ path: '/' })
|
|
45
|
+
index(ctx: Context) {
|
|
46
|
+
ctx.success(this.hello.say());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
69
49
|
```
|
|
70
50
|
|
|
71
|
-
|
|
51
|
+
src/service/hello_service.ts
|
|
72
52
|
```js
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export default class HelloService extends Service {
|
|
53
|
+
export class HelloService {
|
|
76
54
|
i = 0;
|
|
77
55
|
say() {
|
|
78
56
|
this.i++;
|
|
@@ -87,28 +65,30 @@ boot time: 2 ms
|
|
|
87
65
|
server on: 7001
|
|
88
66
|
```
|
|
89
67
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
7. [api](https://www.npmjs.com/package/@zenweb/api)
|
|
100
|
-
8. [helper](https://www.npmjs.com/package/@zenweb/helper)
|
|
68
|
+
## 内置模块
|
|
69
|
+
1. [meta](https://www.npmjs.com/package/@zenweb/meta) 运行基本信息,例如:请求耗时
|
|
70
|
+
2. [log](https://www.npmjs.com/package/@zenweb/log) 日志支持
|
|
71
|
+
3. [router](https://www.npmjs.com/package/@zenweb/router) 路由支持
|
|
72
|
+
4. [messagecode](https://www.npmjs.com/package/@zenweb/messagecode) 统一错误消息格式化
|
|
73
|
+
5. [body](https://www.npmjs.com/package/@zenweb/body) 表单提交,文件上传支持
|
|
74
|
+
6. [api](https://www.npmjs.com/package/@zenweb/api) 统一接口返回 ctx.success ctx.fail 方法
|
|
75
|
+
7. [helper](https://www.npmjs.com/package/@zenweb/helper) 输入数据验证
|
|
76
|
+
8. [inject](https://www.npmjs.com/package/@zenweb/inject) 注入支持
|
|
101
77
|
|
|
102
78
|
内置模块默认开启,可以通过设置配置项为 **false** 关闭
|
|
103
79
|
|
|
104
80
|
|
|
105
|
-
|
|
106
|
-
9. [cors](https://www.npmjs.com/package/@zenweb/cors)
|
|
107
|
-
10. [sentry](https://www.npmjs.com/package/@zenweb/sentry)
|
|
108
|
-
11. [metric](https://www.npmjs.com/package/@zenweb/metric)
|
|
109
|
-
12. [validation](https://www.npmjs.com/package/@zenweb/validation)
|
|
110
|
-
13. [mysql](https://www.npmjs.com/package/@zenweb/mysql)
|
|
111
|
-
14. [orm](https://www.npmjs.com/package/@zenweb/orm)
|
|
112
|
-
15. [view](https://www.npmjs.com/package/@zenweb/view)
|
|
113
|
-
16. [schedule](https://www.npmjs.com/package/@zenweb/schedule)
|
|
114
|
-
17. [form](https://www.npmjs.com/package/@zenweb/form)
|
|
81
|
+
## 可选模块
|
|
82
|
+
9. [cors](https://www.npmjs.com/package/@zenweb/cors) 跨域支持
|
|
83
|
+
10. [sentry](https://www.npmjs.com/package/@zenweb/sentry) sentry 错误收集
|
|
84
|
+
11. [metric](https://www.npmjs.com/package/@zenweb/metric) 生产运行健康信息收集
|
|
85
|
+
12. [validation](https://www.npmjs.com/package/@zenweb/validation) JSONSchema 验证
|
|
86
|
+
13. [mysql](https://www.npmjs.com/package/@zenweb/mysql) MySQL 数据库支持
|
|
87
|
+
14. [orm](https://www.npmjs.com/package/@zenweb/orm) ORM 支持
|
|
88
|
+
15. [view](https://www.npmjs.com/package/@zenweb/view) 视图模版渲染
|
|
89
|
+
16. [schedule](https://www.npmjs.com/package/@zenweb/schedule) 定时任务
|
|
90
|
+
17. [form](https://www.npmjs.com/package/@zenweb/form) 统一表单(多用于后台)
|
|
91
|
+
18. [grid](https://www.npmjs.com/package/@zenweb/grid) 统一表格(多用于后台)
|
|
92
|
+
|
|
93
|
+
## 废弃模块
|
|
94
|
+
1. [service](https://www.npmjs.com/package/@zenweb/service) 废弃,已被 3.0 注入技术替代
|
package/dist/index.d.ts
CHANGED
|
@@ -8,9 +8,8 @@ import { CreateOptions } from './types';
|
|
|
8
8
|
export { init, inject, singleton, Context } from '@zenweb/inject';
|
|
9
9
|
export { Router } from '@zenweb/router';
|
|
10
10
|
export { ApiFail } from '@zenweb/api';
|
|
11
|
-
export {
|
|
12
|
-
export
|
|
13
|
-
export { Core, SetupFunction, };
|
|
11
|
+
export { Controller, controller, mapping } from '@zenweb/controller';
|
|
12
|
+
export { Core, SetupFunction, CreateOptions, };
|
|
14
13
|
/**
|
|
15
14
|
* @param options 模块配置项
|
|
16
15
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.create = exports.Core = exports.
|
|
3
|
+
exports.create = exports.Core = exports.mapping = exports.controller = exports.Controller = exports.ApiFail = exports.Router = exports.Context = exports.singleton = exports.inject = exports.init = void 0;
|
|
14
4
|
require("@zenweb/meta");
|
|
15
5
|
require("@zenweb/log");
|
|
16
6
|
require("@zenweb/messagecode");
|
|
@@ -22,9 +12,9 @@ const log_1 = require("@zenweb/log");
|
|
|
22
12
|
const router_1 = require("@zenweb/router");
|
|
23
13
|
const messagecode_1 = require("@zenweb/messagecode");
|
|
24
14
|
const body_1 = require("@zenweb/body");
|
|
25
|
-
const service_1 = require("@zenweb/service");
|
|
26
15
|
const api_1 = require("@zenweb/api");
|
|
27
16
|
const helper_1 = require("@zenweb/helper");
|
|
17
|
+
const controller_1 = require("@zenweb/controller");
|
|
28
18
|
const core_1 = require("@zenweb/core");
|
|
29
19
|
Object.defineProperty(exports, "Core", { enumerable: true, get: function () { return core_1.Core; } });
|
|
30
20
|
var inject_2 = require("@zenweb/inject");
|
|
@@ -36,9 +26,10 @@ var router_2 = require("@zenweb/router");
|
|
|
36
26
|
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_2.Router; } });
|
|
37
27
|
var api_2 = require("@zenweb/api");
|
|
38
28
|
Object.defineProperty(exports, "ApiFail", { enumerable: true, get: function () { return api_2.ApiFail; } });
|
|
39
|
-
var
|
|
40
|
-
Object.defineProperty(exports, "
|
|
41
|
-
|
|
29
|
+
var controller_2 = require("@zenweb/controller");
|
|
30
|
+
Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return controller_2.Controller; } });
|
|
31
|
+
Object.defineProperty(exports, "controller", { enumerable: true, get: function () { return controller_2.controller; } });
|
|
32
|
+
Object.defineProperty(exports, "mapping", { enumerable: true, get: function () { return controller_2.mapping; } });
|
|
42
33
|
/**
|
|
43
34
|
* @param options 模块配置项
|
|
44
35
|
*/
|
|
@@ -52,17 +43,17 @@ function create(options) {
|
|
|
52
43
|
if (options.log !== false)
|
|
53
44
|
core.setup((0, log_1.default)(options.log));
|
|
54
45
|
if (options.router !== false)
|
|
55
|
-
core.setup((0, router_1.default)(
|
|
46
|
+
core.setup((0, router_1.default)());
|
|
56
47
|
if (options.messagecode !== false)
|
|
57
48
|
core.setup((0, messagecode_1.default)(options.messagecode));
|
|
58
49
|
if (options.body !== false)
|
|
59
50
|
core.setup((0, body_1.default)(options.body));
|
|
60
|
-
if (options.service !== false)
|
|
61
|
-
core.setup((0, service_1.default)(options.service));
|
|
62
51
|
if (options.api !== false)
|
|
63
52
|
core.setup((0, api_1.default)(options.api));
|
|
64
53
|
if (options.helper !== false)
|
|
65
54
|
core.setup((0, helper_1.default)(options.helper));
|
|
55
|
+
if (options.controller !== false)
|
|
56
|
+
core.setup((0, controller_1.default)(options.controller));
|
|
66
57
|
return core;
|
|
67
58
|
}
|
|
68
59
|
exports.create = create;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { CoreOption } from '@zenweb/core';
|
|
2
2
|
import { MetaOption } from '@zenweb/meta';
|
|
3
3
|
import { LogOption } from '@zenweb/log';
|
|
4
|
-
import { RouterOption } from '@zenweb/router';
|
|
5
4
|
import { MessageCodeOption } from '@zenweb/messagecode';
|
|
6
5
|
import { BodyOption } from '@zenweb/body';
|
|
7
|
-
import { ServiceOption } from '@zenweb/service';
|
|
8
6
|
import { ApiOption } from '@zenweb/api';
|
|
9
7
|
import { HelperOption } from '@zenweb/helper';
|
|
8
|
+
import { ControllerOption } from '@zenweb/controller';
|
|
10
9
|
export interface CreateOptions {
|
|
11
|
-
[key: string]: any;
|
|
12
10
|
core?: CoreOption;
|
|
11
|
+
inject?: false;
|
|
13
12
|
meta?: MetaOption | false;
|
|
14
13
|
log?: LogOption | false;
|
|
15
|
-
router?:
|
|
14
|
+
router?: false;
|
|
16
15
|
messagecode?: MessageCodeOption | false;
|
|
17
16
|
body?: BodyOption | false;
|
|
18
|
-
service?: ServiceOption | false;
|
|
19
17
|
api?: ApiOption | false;
|
|
20
18
|
helper?: HelperOption | false;
|
|
19
|
+
controller?: ControllerOption | false;
|
|
21
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zenweb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Modular lightweight web framework based on Koa",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
11
|
"prepublishOnly": "rimraf dist && tsc",
|
|
12
|
-
"dev": "cd example &&
|
|
12
|
+
"dev": "cd example && cross-env DEBUG=* NODE_ENV=development ts-node src"
|
|
13
13
|
},
|
|
14
14
|
"author": {
|
|
15
15
|
"name": "YeFei",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@zenweb/api": "^2.3.4",
|
|
35
35
|
"@zenweb/body": "^2.4.2",
|
|
36
|
+
"@zenweb/controller": "^3.2.1",
|
|
36
37
|
"@zenweb/core": "^2.4.1",
|
|
37
38
|
"@zenweb/helper": "^2.8.2",
|
|
38
|
-
"@zenweb/inject": "^1.0
|
|
39
|
+
"@zenweb/inject": "^3.1.0",
|
|
39
40
|
"@zenweb/log": "^2.3.0",
|
|
40
41
|
"@zenweb/messagecode": "^2.3.0",
|
|
41
42
|
"@zenweb/meta": "^2.3.2",
|
|
42
|
-
"@zenweb/router": "^
|
|
43
|
-
"@zenweb/service": "^2.4.9"
|
|
43
|
+
"@zenweb/router": "^3.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"cross-env": "^7.0.3",
|