zenweb 2.1.1 → 2.3.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,17 +1,20 @@
1
1
  # ZenWeb
2
- Modular lightweight web framework based on Koa
2
+ 基于 Koa 的模块化轻量级 Web 开发框架。
3
+ 本框架全部由 typescript 编写
3
4
 
4
- ## Quick start
5
+ ## 快速开始
6
+
7
+ 推荐使用 typescript 创建项目
5
8
 
6
9
  package.json
7
10
  ```json
8
11
  {
9
12
  "name": "app",
10
- "type": "module",
11
13
  "private": true,
12
14
  "main": "app/index.js",
13
15
  "scripts": {
14
- "dev": "cross-env DEBUG=*,-zenweb:metric NODE_ENV=development nodemon app",
16
+ "dev": "cross-env DEBUG=* NODE_ENV=development nodemon app.ts",
17
+ "build": "tsc",
15
18
  "start": "node app"
16
19
  },
17
20
  "nodemonConfig": {
@@ -27,8 +30,8 @@ $ npm i zenweb
27
30
  $ npm i cross-env nodemon -D
28
31
  ```
29
32
 
30
- app/index.js
31
- ```js
33
+ app/index.ts
34
+ ```ts
32
35
  import { create } from 'zenweb';
33
36
 
34
37
  const app = create({
@@ -42,10 +45,10 @@ const app = create({
42
45
  app.start();
43
46
  ```
44
47
 
45
- app/controller/hello.js
46
- ```js
48
+ app/controller/hello.ts
49
+ ```ts
47
50
  import { Router } from 'zenweb';
48
- export const router = Router();
51
+ export const router = new Router();
49
52
 
50
53
  router.get('/', ctx => {
51
54
  ctx.success('Hello');
@@ -65,16 +68,12 @@ router.get('/error', ctx => {
65
68
  });
66
69
  ```
67
70
 
68
- app/service/hello_service.js
71
+ app/service/hello_service.ts
69
72
  ```js
70
73
  import { Service } from 'zenweb';
71
74
 
72
75
  export default class HelloService extends Service {
73
- constructor(ctx) {
74
- super(ctx);
75
- this.i = 0;
76
- }
77
-
76
+ i = 0;
78
77
  say() {
79
78
  this.i++;
80
79
  return `Hello: ${this.ctx.path}, ${this.i}`;
@@ -87,3 +86,27 @@ $ npm run dev
87
86
  boot time: 2 ms
88
87
  server on: 7001
89
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.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C,IAAA,iBAAO,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACpE,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,19 +1,15 @@
1
1
  {
2
2
  "name": "zenweb",
3
- "version": "2.1.1",
3
+ "version": "2.3.0",
4
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",
5
+ "main": "dist/index.js",
6
+ "typings": "./dist/index.d.ts",
11
7
  "files": [
12
- "index.js",
13
- "index.d.ts"
8
+ "dist"
14
9
  ],
15
10
  "scripts": {
16
- "dev": "cd example && cross-env DEBUG=* NODE_ENV=development node app"
11
+ "prepublishOnly": "tsc --build --clean && tsc",
12
+ "dev": "cd example && zenweb-service-types && cross-env DEBUG=* NODE_ENV=development ts-node app"
17
13
  },
18
14
  "author": {
19
15
  "name": "YeFei",
@@ -35,27 +31,17 @@
35
31
  "url": "https://github.com/yefei/zenweb/issues"
36
32
  },
37
33
  "dependencies": {
38
- "@zenweb/api": "^2.0.0",
39
- "@zenweb/body": "^1.1.0",
40
- "@zenweb/core": "^2.0.1",
41
- "@zenweb/helper": "^1.2.0",
42
- "@zenweb/log": "^2.0.1",
43
- "@zenweb/messagecode": "^1.0.1",
44
- "@zenweb/meta": "^2.0.0",
45
- "@zenweb/router": "^2.1.0",
46
- "@zenweb/service": "^2.0.0"
34
+ "@zenweb/api": "^2.3.2",
35
+ "@zenweb/body": "^2.3.0",
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.3.2"
47
43
  },
48
44
  "devDependencies": {
49
- "@zenweb/cors": "^2.0.0",
50
- "@zenweb/form": "^2.0.0",
51
- "@zenweb/metric": "^1.3.2",
52
- "@zenweb/mysql": "^1.2.1",
53
- "@zenweb/orm": "^1.0.0",
54
- "@zenweb/schedule": "^1.0.0",
55
- "@zenweb/sentry": "^1.2.1",
56
- "@zenweb/validation": "^1.2.0",
57
- "@zenweb/view": "^1.3.0",
58
- "eslint": "^7.16.0",
59
45
  "cross-env": "^7.0.3"
60
46
  }
61
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
- }