zenweb 2.1.0 → 2.4.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 CHANGED
@@ -1,89 +1,112 @@
1
- # ZenWeb
2
- Modular lightweight web framework based on Koa
3
-
4
- ## Quick start
5
-
6
- package.json
7
- ```json
8
- {
9
- "name": "app",
10
- "type": "module",
11
- "private": true,
12
- "main": "app/index.js",
13
- "scripts": {
14
- "dev": "cross-env DEBUG=*,-zenweb:metric NODE_ENV=development nodemon app",
15
- "start": "node app"
16
- },
17
- "nodemonConfig": {
18
- "ignore": [
19
- "**/typings/**"
20
- ]
21
- }
22
- }
23
- ```
24
-
25
- ```bash
26
- $ npm i zenweb
27
- $ npm i cross-env nodemon -D
28
- ```
29
-
30
- app/index.js
31
- ```js
32
- import { create } from 'zenweb';
33
-
34
- const app = create({
35
- // add optional module
36
- // $ npm i @zenweb/sentry @zenweb/cors @zenweb/validation
37
- sentry: { dsn: 'xxxxx' },
38
- cors: { origin: '*' },
39
- validation: {},
40
- });
41
-
42
- app.start();
43
- ```
44
-
45
- app/controller/hello.js
46
- ```js
47
- import { Router } from 'zenweb';
48
- export const router = Router();
49
-
50
- router.get('/', ctx => {
51
- ctx.success('Hello');
52
- });
53
-
54
- router.get('/hello', ctx => {
55
- ctx.success({
56
- say1: ctx.service.helloService.say(),
57
- say2: ctx.service.helloService.say(),
58
- say3: ctx.service.helloService.say(),
59
- });
60
- });
61
-
62
- router.get('/error', ctx => {
63
- ctx.fail('error info');
64
- console.log('Will not output');
65
- });
66
- ```
67
-
68
- app/service/hello_service.js
69
- ```js
70
- import { Service } from 'zenweb';
71
-
72
- export default class HelloService extends Service {
73
- constructor(ctx) {
74
- super(ctx);
75
- this.i = 0;
76
- }
77
-
78
- say() {
79
- this.i++;
80
- return `Hello: ${this.ctx.path}, ${this.i}`;
81
- }
82
- }
83
- ```
84
-
85
- ```bash
86
- $ npm run dev
87
- boot time: 2 ms
88
- server on: 7001
89
- ```
1
+ # ZenWeb
2
+ 基于 Koa 的模块化轻量级 Web 开发框架。
3
+ 本框架全部由 typescript 编写
4
+
5
+ ## 快速开始
6
+
7
+ 推荐使用 typescript 创建项目
8
+
9
+ package.json
10
+ ```json
11
+ {
12
+ "name": "app",
13
+ "private": true,
14
+ "main": "app/index.js",
15
+ "scripts": {
16
+ "dev": "cross-env DEBUG=* NODE_ENV=development nodemon app.ts",
17
+ "build": "tsc",
18
+ "start": "node app"
19
+ },
20
+ "nodemonConfig": {
21
+ "ignore": [
22
+ "**/typings/**"
23
+ ]
24
+ }
25
+ }
26
+ ```
27
+
28
+ ```bash
29
+ $ npm i zenweb
30
+ $ npm i cross-env nodemon -D
31
+ ```
32
+
33
+ app/index.ts
34
+ ```ts
35
+ import { create } from 'zenweb';
36
+
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
+
45
+ app.start();
46
+ ```
47
+
48
+ app/controller/hello.ts
49
+ ```ts
50
+ import { Router } from 'zenweb';
51
+ export const router = new Router();
52
+
53
+ router.get('/', ctx => {
54
+ ctx.success('Hello');
55
+ });
56
+
57
+ router.get('/hello', ctx => {
58
+ ctx.success({
59
+ say1: ctx.service.helloService.say(),
60
+ say2: ctx.service.helloService.say(),
61
+ say3: ctx.service.helloService.say(),
62
+ });
63
+ });
64
+
65
+ router.get('/error', ctx => {
66
+ ctx.fail('error info');
67
+ console.log('Will not output');
68
+ });
69
+ ```
70
+
71
+ app/service/hello_service.ts
72
+ ```js
73
+ import { Service } from 'zenweb';
74
+
75
+ export default class HelloService extends Service {
76
+ i = 0;
77
+ say() {
78
+ this.i++;
79
+ return `Hello: ${this.ctx.path}, ${this.i}`;
80
+ }
81
+ }
82
+ ```
83
+
84
+ ```bash
85
+ $ npm run dev
86
+ boot time: 2 ms
87
+ server on: 7001
88
+ ```
89
+
90
+ ### 内置模块
91
+ - [meta](https://www.npmjs.com/package/@zenweb/meta)
92
+ - [log](https://www.npmjs.com/package/@zenweb/log)
93
+ - [router](https://www.npmjs.com/package/@zenweb/router)
94
+ - [messagecode](https://www.npmjs.com/package/@zenweb/messagecode)
95
+ - [body](https://www.npmjs.com/package/@zenweb/body)
96
+ - [service](https://www.npmjs.com/package/@zenweb/service)
97
+ - [api](https://www.npmjs.com/package/@zenweb/api)
98
+ - [helper](https://www.npmjs.com/package/@zenweb/helper)
99
+
100
+ 内置模块默认开启,可以通过设置配置项为 **false** 关闭
101
+
102
+
103
+ ### 可选模块
104
+ - [cors](https://www.npmjs.com/package/@zenweb/cors)
105
+ - [sentry](https://www.npmjs.com/package/@zenweb/sentry)
106
+ - [metric](https://www.npmjs.com/package/@zenweb/metric)
107
+ - [validation](https://www.npmjs.com/package/@zenweb/validation)
108
+ - [mysql](https://www.npmjs.com/package/@zenweb/mysql)
109
+ - [orm](https://www.npmjs.com/package/@zenweb/orm)
110
+ - [view](https://www.npmjs.com/package/@zenweb/view)
111
+ - [schedule](https://www.npmjs.com/package/@zenweb/schedule)
112
+ - [form](https://www.npmjs.com/package/@zenweb/form)
@@ -0,0 +1,10 @@
1
+ import { Core } from '@zenweb/core';
2
+ import { CreateOptions } from './types';
3
+ export { Router } from '@zenweb/router';
4
+ export { ApiFail } from '@zenweb/api';
5
+ export { Service } from '@zenweb/service';
6
+ export * from './types';
7
+ /**
8
+ * @param options 模块配置项
9
+ */
10
+ export declare function create(options: CreateOptions): Core;
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.create = exports.Service = exports.ApiFail = exports.Router = void 0;
14
+ const meta_1 = require("@zenweb/meta");
15
+ const log_1 = require("@zenweb/log");
16
+ const router_1 = require("@zenweb/router");
17
+ const messagecode_1 = require("@zenweb/messagecode");
18
+ const body_1 = require("@zenweb/body");
19
+ const service_1 = require("@zenweb/service");
20
+ const api_1 = require("@zenweb/api");
21
+ const helper_1 = require("@zenweb/helper");
22
+ const core_1 = require("@zenweb/core");
23
+ var router_2 = require("@zenweb/router");
24
+ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_2.Router; } });
25
+ var api_2 = require("@zenweb/api");
26
+ Object.defineProperty(exports, "ApiFail", { enumerable: true, get: function () { return api_2.ApiFail; } });
27
+ var service_2 = require("@zenweb/service");
28
+ Object.defineProperty(exports, "Service", { enumerable: true, get: function () { return service_2.Service; } });
29
+ __exportStar(require("./types"), exports);
30
+ /**
31
+ * @param options 模块配置项
32
+ */
33
+ function create(options) {
34
+ options = options || {};
35
+ const core = new core_1.Core(options.core);
36
+ if (options.meta !== false)
37
+ core.setup((0, meta_1.default)(options.meta));
38
+ if (options.log !== false)
39
+ core.setup((0, log_1.default)(options.log));
40
+ if (options.router !== false)
41
+ core.setup((0, router_1.default)(options.router));
42
+ if (options.messagecode !== false)
43
+ core.setup((0, messagecode_1.default)(options.messagecode));
44
+ if (options.body !== false)
45
+ core.setup((0, body_1.default)(options.body));
46
+ if (options.service !== false)
47
+ core.setup((0, service_1.default)(options.service));
48
+ if (options.api !== false)
49
+ core.setup((0, api_1.default)(options.api));
50
+ if (options.helper !== false)
51
+ core.setup((0, helper_1.default)());
52
+ return core;
53
+ }
54
+ exports.create = create;
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.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,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK;QAAE,IAAI,CAAC,KAAK,CAAC,IAAA,aAAG,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACxD,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK;QAAE,IAAI,CAAC,KAAK,CAAC,IAAA,gBAAM,GAAE,CAAC,CAAC;IACnD,OAAO,IAAI,CAAC;AACd,CAAC;AAZD,wBAYC"}
@@ -0,0 +1,20 @@
1
+ import { CoreOption } from '@zenweb/core';
2
+ import { MetaOption } from '@zenweb/meta';
3
+ import { LogOption } from '@zenweb/log';
4
+ import { RouterOption } from '@zenweb/router';
5
+ import { MessageCodeOption } from '@zenweb/messagecode';
6
+ import { BodyOption } from '@zenweb/body';
7
+ import { ServiceOption } from '@zenweb/service';
8
+ import { ApiOption } from '@zenweb/api';
9
+ export interface CreateOptions {
10
+ [key: string]: any;
11
+ core?: CoreOption;
12
+ meta?: MetaOption | false;
13
+ log?: LogOption | false;
14
+ router?: RouterOption | false;
15
+ messagecode?: MessageCodeOption | false;
16
+ body?: BodyOption | false;
17
+ service?: ServiceOption | false;
18
+ api?: ApiOption | false;
19
+ helper?: boolean;
20
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,63 +1,47 @@
1
- {
2
- "name": "zenweb",
3
- "version": "2.1.0",
4
- "description": "Modular lightweight web framework based on Koa",
5
- "type": "module",
6
- "exports": "./index.js",
7
- "engines": {
8
- "node": ">=16.0.0"
9
- },
10
- "typings": "index.d.ts",
11
- "files": [
12
- "index.js",
13
- "index.d.ts"
14
- ],
15
- "scripts": {
16
- "dev": "cd example && cross-env DEBUG=* NODE_ENV=development node app"
17
- },
18
- "author": {
19
- "name": "YeFei",
20
- "email": "316606233@qq.com"
21
- },
22
- "keywords": [
23
- "web",
24
- "app",
25
- "http",
26
- "framework",
27
- "koa"
28
- ],
29
- "license": "MIT",
30
- "repository": {
31
- "type": "git",
32
- "url": "git+https://github.com/yefei/zenweb.git"
33
- },
34
- "bugs": {
35
- "url": "https://github.com/yefei/zenweb/issues"
36
- },
37
- "optionalDependencies": {
38
- "@zenweb/cors": "^2.0.0",
39
- "@zenweb/form": "^2.0.0",
40
- "@zenweb/metric": "^1.3.2",
41
- "@zenweb/mysql": "^1.2.1",
42
- "@zenweb/orm": "^1.0.0",
43
- "@zenweb/schedule": "^1.0.0",
44
- "@zenweb/sentry": "^1.2.1",
45
- "@zenweb/validation": "^1.2.0",
46
- "@zenweb/view": "^1.3.0",
47
- "eslint": "^7.16.0"
48
- },
49
- "dependencies": {
50
- "@zenweb/api": "^2.0.0",
51
- "@zenweb/body": "^1.1.0",
52
- "@zenweb/core": "^2.0.1",
53
- "@zenweb/helper": "^1.2.0",
54
- "@zenweb/log": "^2.0.1",
55
- "@zenweb/messagecode": "^1.0.1",
56
- "@zenweb/meta": "^2.0.0",
57
- "@zenweb/router": "^2.1.0",
58
- "@zenweb/service": "^2.0.0"
59
- },
60
- "devDependencies": {
61
- "cross-env": "^7.0.3"
62
- }
63
- }
1
+ {
2
+ "name": "zenweb",
3
+ "version": "2.4.0",
4
+ "description": "Modular lightweight web framework based on Koa",
5
+ "main": "dist/index.js",
6
+ "typings": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "prepublishOnly": "tsc --build --clean && tsc",
12
+ "dev": "cd example && zenweb-service-types && cross-env DEBUG=* NODE_ENV=development ts-node app"
13
+ },
14
+ "author": {
15
+ "name": "YeFei",
16
+ "email": "316606233@qq.com"
17
+ },
18
+ "keywords": [
19
+ "web",
20
+ "app",
21
+ "http",
22
+ "framework",
23
+ "koa"
24
+ ],
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/yefei/zenweb.git"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/yefei/zenweb/issues"
32
+ },
33
+ "dependencies": {
34
+ "@zenweb/api": "^2.3.2",
35
+ "@zenweb/body": "^2.3.1",
36
+ "@zenweb/core": "^2.3.2",
37
+ "@zenweb/helper": "^2.3.0",
38
+ "@zenweb/log": "^2.3.0",
39
+ "@zenweb/messagecode": "^2.3.0",
40
+ "@zenweb/meta": "^2.3.0",
41
+ "@zenweb/router": "^2.3.0",
42
+ "@zenweb/service": "^2.4.2"
43
+ },
44
+ "devDependencies": {
45
+ "cross-env": "^7.0.3"
46
+ }
47
+ }
package/index.d.ts DELETED
@@ -1,42 +0,0 @@
1
- import '@zenweb/log';
2
- import '@zenweb/router';
3
- import '@zenweb/helper';
4
- import '@zenweb/service';
5
- import { CoreOptions } from '@zenweb/core';
6
- import { ServiceOptions } from '@zenweb/service';
7
- import { ApiOptions } from '@zenweb/api';
8
- import { Core } from '@zenweb/core';
9
- import { IKoaBodyOptions as BodyOptions } from '@zenweb/body';
10
- import { RouterOptions } from '@zenweb/router';
11
- import { SentryOptions } from '@zenweb/sentry';
12
- import { MetricOptions } from '@zenweb/metric';
13
- import { CorsOptions } from '@zenweb/cors';
14
- import { ValidationOptions } from '@zenweb/validation';
15
- import { MySQLOptions } from '@zenweb/mysql';
16
- import { ViewOptions } from '@zenweb/view';
17
- import { ScheduleOptions } from '@zenweb/schedule';
18
- import { MessageCodeOption } from '@zenweb/messagecode';
19
- import { FormOption } from '@zenweb/form';
20
- export { Router } from '@zenweb/router';
21
- export { ApiFail } from '@zenweb/api';
22
- export { Service } from '@zenweb/service';
23
-
24
- interface CreateOptions {
25
- core?: CoreOptions;
26
- api?: ApiOptions;
27
- body?: BodyOptions;
28
- router?: RouterOptions;
29
- service?: ServiceOptions;
30
- // optional
31
- sentry?: SentryOptions;
32
- metric?: MetricOptions;
33
- cors?: CorsOptions;
34
- validation?: ValidationOptions;
35
- mysql?: MySQLOptions;
36
- view?: ViewOptions;
37
- schedule?: ScheduleOptions;
38
- messageCode?: MessageCodeOption;
39
- form?: FormOption;
40
- }
41
-
42
- export declare function create(options?: CreateOptions): Core;
package/index.js DELETED
@@ -1,45 +0,0 @@
1
- import { Core } from '@zenweb/core';
2
- export { Router } from '@zenweb/router';
3
- export { ApiFail } from '@zenweb/api';
4
- export { Service } from '@zenweb/service';
5
-
6
- // 可选模块
7
- const OPTIONAL_MODULES = {
8
- sentry: '@zenweb/sentry',
9
- metric: '@zenweb/metric',
10
- cors: '@zenweb/cors',
11
- validation: '@zenweb/validation',
12
- mysql: '@zenweb/mysql',
13
- view: '@zenweb/view',
14
- schedule: '@zenweb/schedule',
15
- form: '@zenweb/form',
16
- orm: '@zenweb/orm',
17
- };
18
-
19
- /**
20
- * @param {object} [options] 配置项
21
- * @returns {Core}
22
- */
23
- export function create(options) {
24
- options = options || {};
25
- const core = new Core(options.core);
26
- core.setup('@zenweb/meta');
27
- core.setup('@zenweb/log');
28
- core.setup('@zenweb/router', options.router);
29
- core.setup('@zenweb/api', options.api);
30
- core.setup('@zenweb/messagecode', options.messageCode);
31
- core.setup('@zenweb/helper');
32
- core.setup('@zenweb/body', Object.assign({
33
- onError(error, ctx) {
34
- ctx.log.warn('request body error: %s', error);
35
- ctx.fail('request body error: ' + error.message);
36
- },
37
- }, options.body));
38
- core.setup('@zenweb/service', options.service);
39
- for (const [name, mod] of Object.entries(OPTIONAL_MODULES)) {
40
- if (options[name]) {
41
- core.setup(mod, options[name]);
42
- }
43
- }
44
- return core;
45
- }