@doracli/express 0.0.1 → 0.0.2
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/lib/cjs/index.js +36 -21
- package/lib/esm/index.js +36 -21
- package/lib/type/index.d.ts +15 -15
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -68,26 +68,6 @@ function _toPropertyKey(t) {
|
|
|
68
68
|
return "symbol" == typeof i ? i : i + "";
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
var Ctx = /*#__PURE__*/function () {
|
|
72
|
-
function Ctx(configCtx) {
|
|
73
|
-
_classCallCheck(this, Ctx);
|
|
74
|
-
_defineProperty(this, "configCtx", void 0);
|
|
75
|
-
_defineProperty(this, "envParams", {
|
|
76
|
-
scan: './',
|
|
77
|
-
workRootDir: filePro.getCwd()
|
|
78
|
-
});
|
|
79
|
-
/** 路由 -》文件夹/文件的映射 */
|
|
80
|
-
_defineProperty(this, "routePathMap", {});
|
|
81
|
-
this.configCtx = configCtx;
|
|
82
|
-
}
|
|
83
|
-
return _createClass(Ctx, [{
|
|
84
|
-
key: "updateEnvParams",
|
|
85
|
-
value: function updateEnvParams(params) {
|
|
86
|
-
this.envParams = _objectSpread2(_objectSpread2({}, this.envParams), params);
|
|
87
|
-
}
|
|
88
|
-
}]);
|
|
89
|
-
}();
|
|
90
|
-
|
|
91
71
|
var RouteManager = /*#__PURE__*/function () {
|
|
92
72
|
function RouteManager(app) {
|
|
93
73
|
_classCallCheck(this, RouteManager);
|
|
@@ -96,6 +76,11 @@ var RouteManager = /*#__PURE__*/function () {
|
|
|
96
76
|
this.app = app;
|
|
97
77
|
}
|
|
98
78
|
return _createClass(RouteManager, [{
|
|
79
|
+
key: "check",
|
|
80
|
+
value: function check(route) {
|
|
81
|
+
return !!this.routesMap[route];
|
|
82
|
+
}
|
|
83
|
+
}, {
|
|
99
84
|
key: "add",
|
|
100
85
|
value: function add(route, method, handler) {
|
|
101
86
|
this.updateMap(route, method, handler);
|
|
@@ -104,6 +89,10 @@ var RouteManager = /*#__PURE__*/function () {
|
|
|
104
89
|
}, {
|
|
105
90
|
key: "update",
|
|
106
91
|
value: function update(route, method, handler) {
|
|
92
|
+
if (!this.check(route)) {
|
|
93
|
+
this.add(route, method, handler);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
107
96
|
this.updateMap(route, method, handler, 'updated');
|
|
108
97
|
}
|
|
109
98
|
}, {
|
|
@@ -144,8 +133,34 @@ var RouteManager = /*#__PURE__*/function () {
|
|
|
144
133
|
}]);
|
|
145
134
|
}();
|
|
146
135
|
|
|
136
|
+
var Ctx = /*#__PURE__*/function () {
|
|
137
|
+
function Ctx(configCtx, app) {
|
|
138
|
+
_classCallCheck(this, Ctx);
|
|
139
|
+
_defineProperty(this, "app", void 0);
|
|
140
|
+
_defineProperty(this, "routeManager", void 0);
|
|
141
|
+
_defineProperty(this, "configCtx", void 0);
|
|
142
|
+
_defineProperty(this, "envParams", {
|
|
143
|
+
scan: './',
|
|
144
|
+
workRootDir: filePro.getCwd()
|
|
145
|
+
});
|
|
146
|
+
this.configCtx = configCtx;
|
|
147
|
+
this.app = app;
|
|
148
|
+
this.routeManager = new RouteManager(app);
|
|
149
|
+
}
|
|
150
|
+
return _createClass(Ctx, [{
|
|
151
|
+
key: "updateEnvParams",
|
|
152
|
+
value: function updateEnvParams(params) {
|
|
153
|
+
this.envParams = _objectSpread2(_objectSpread2({}, this.envParams), params);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// getServiceConfig() {
|
|
157
|
+
// return this.configCtx.getDoraConfig().serviceConfig!;
|
|
158
|
+
// }
|
|
159
|
+
}]);
|
|
160
|
+
}();
|
|
161
|
+
|
|
147
162
|
var loggerMiddleware = function loggerMiddleware(req, res, next) {
|
|
148
|
-
helper.cLog.log('ser', 'request', "
|
|
163
|
+
helper.cLog.log('ser', 'request', "[".concat(req.method, "] ").concat(req.url));
|
|
149
164
|
next();
|
|
150
165
|
};
|
|
151
166
|
|
package/lib/esm/index.js
CHANGED
|
@@ -66,26 +66,6 @@ function _toPropertyKey(t) {
|
|
|
66
66
|
return "symbol" == typeof i ? i : i + "";
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
var Ctx = /*#__PURE__*/function () {
|
|
70
|
-
function Ctx(configCtx) {
|
|
71
|
-
_classCallCheck(this, Ctx);
|
|
72
|
-
_defineProperty(this, "configCtx", void 0);
|
|
73
|
-
_defineProperty(this, "envParams", {
|
|
74
|
-
scan: './',
|
|
75
|
-
workRootDir: getCwd()
|
|
76
|
-
});
|
|
77
|
-
/** 路由 -》文件夹/文件的映射 */
|
|
78
|
-
_defineProperty(this, "routePathMap", {});
|
|
79
|
-
this.configCtx = configCtx;
|
|
80
|
-
}
|
|
81
|
-
return _createClass(Ctx, [{
|
|
82
|
-
key: "updateEnvParams",
|
|
83
|
-
value: function updateEnvParams(params) {
|
|
84
|
-
this.envParams = _objectSpread2(_objectSpread2({}, this.envParams), params);
|
|
85
|
-
}
|
|
86
|
-
}]);
|
|
87
|
-
}();
|
|
88
|
-
|
|
89
69
|
var RouteManager = /*#__PURE__*/function () {
|
|
90
70
|
function RouteManager(app) {
|
|
91
71
|
_classCallCheck(this, RouteManager);
|
|
@@ -94,6 +74,11 @@ var RouteManager = /*#__PURE__*/function () {
|
|
|
94
74
|
this.app = app;
|
|
95
75
|
}
|
|
96
76
|
return _createClass(RouteManager, [{
|
|
77
|
+
key: "check",
|
|
78
|
+
value: function check(route) {
|
|
79
|
+
return !!this.routesMap[route];
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
97
82
|
key: "add",
|
|
98
83
|
value: function add(route, method, handler) {
|
|
99
84
|
this.updateMap(route, method, handler);
|
|
@@ -102,6 +87,10 @@ var RouteManager = /*#__PURE__*/function () {
|
|
|
102
87
|
}, {
|
|
103
88
|
key: "update",
|
|
104
89
|
value: function update(route, method, handler) {
|
|
90
|
+
if (!this.check(route)) {
|
|
91
|
+
this.add(route, method, handler);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
105
94
|
this.updateMap(route, method, handler, 'updated');
|
|
106
95
|
}
|
|
107
96
|
}, {
|
|
@@ -142,8 +131,34 @@ var RouteManager = /*#__PURE__*/function () {
|
|
|
142
131
|
}]);
|
|
143
132
|
}();
|
|
144
133
|
|
|
134
|
+
var Ctx = /*#__PURE__*/function () {
|
|
135
|
+
function Ctx(configCtx, app) {
|
|
136
|
+
_classCallCheck(this, Ctx);
|
|
137
|
+
_defineProperty(this, "app", void 0);
|
|
138
|
+
_defineProperty(this, "routeManager", void 0);
|
|
139
|
+
_defineProperty(this, "configCtx", void 0);
|
|
140
|
+
_defineProperty(this, "envParams", {
|
|
141
|
+
scan: './',
|
|
142
|
+
workRootDir: getCwd()
|
|
143
|
+
});
|
|
144
|
+
this.configCtx = configCtx;
|
|
145
|
+
this.app = app;
|
|
146
|
+
this.routeManager = new RouteManager(app);
|
|
147
|
+
}
|
|
148
|
+
return _createClass(Ctx, [{
|
|
149
|
+
key: "updateEnvParams",
|
|
150
|
+
value: function updateEnvParams(params) {
|
|
151
|
+
this.envParams = _objectSpread2(_objectSpread2({}, this.envParams), params);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// getServiceConfig() {
|
|
155
|
+
// return this.configCtx.getDoraConfig().serviceConfig!;
|
|
156
|
+
// }
|
|
157
|
+
}]);
|
|
158
|
+
}();
|
|
159
|
+
|
|
145
160
|
var loggerMiddleware = function loggerMiddleware(req, res, next) {
|
|
146
|
-
cLog.log('ser', 'request', "
|
|
161
|
+
cLog.log('ser', 'request', "[".concat(req.method, "] ").concat(req.url));
|
|
147
162
|
next();
|
|
148
163
|
};
|
|
149
164
|
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Application } from 'express';
|
|
2
|
-
import { THandlerConfig, TMethod, TRouterHandlerFun, Request, Response } from '@doracli/define-server';
|
|
3
2
|
import { ConfigCtx } from '@doracli/helper';
|
|
3
|
+
import { TMethod, TControllerFun, Request, Response } from '@doracli/define-server';
|
|
4
4
|
import { TNoop } from '@cclr/lang';
|
|
5
5
|
|
|
6
6
|
declare const createServer: (config: {
|
|
@@ -14,34 +14,34 @@ type TEnvParams = {
|
|
|
14
14
|
workRootDir: string;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
declare class Ctx {
|
|
18
|
-
configCtx: ConfigCtx;
|
|
19
|
-
envParams: TEnvParams;
|
|
20
|
-
/** 路由 -》文件夹/文件的映射 */
|
|
21
|
-
routePathMap: Record<string, THandlerConfig>;
|
|
22
|
-
constructor(configCtx: ConfigCtx);
|
|
23
|
-
updateEnvParams(params: Partial<TEnvParams>): void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
17
|
declare class RouteManager {
|
|
27
18
|
private app;
|
|
28
19
|
private routesMap;
|
|
29
20
|
constructor(app: Application);
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
check(route: string): boolean;
|
|
22
|
+
add(route: string, method: TMethod, handler: TControllerFun): void;
|
|
23
|
+
update(route: string, method: TMethod, handler: TControllerFun): void;
|
|
32
24
|
remove(route: string, method: TMethod): void;
|
|
33
25
|
destroy(): void;
|
|
34
26
|
private updateMap;
|
|
35
27
|
private getProxyHandler;
|
|
36
28
|
}
|
|
37
29
|
|
|
30
|
+
declare class Ctx {
|
|
31
|
+
app: Application;
|
|
32
|
+
routeManager: RouteManager;
|
|
33
|
+
configCtx: ConfigCtx;
|
|
34
|
+
envParams: TEnvParams;
|
|
35
|
+
constructor(configCtx: ConfigCtx, app: Application);
|
|
36
|
+
updateEnvParams(params: Partial<TEnvParams>): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
38
39
|
declare const loggerMiddleware: (req: Request, res: Response, next: TNoop) => void;
|
|
39
40
|
|
|
40
41
|
type THandlerOpt = {
|
|
41
42
|
state: 'added' | 'updated' | 'removed';
|
|
42
|
-
handler:
|
|
43
|
+
handler: TControllerFun | null;
|
|
43
44
|
};
|
|
44
|
-
type TMethodHandlerMap = Partial<Record<TMethod, TRouterHandlerFun>>;
|
|
45
45
|
|
|
46
46
|
export { Ctx, RouteManager, createServer, loggerMiddleware };
|
|
47
|
-
export type { TEnvParams, THandlerOpt
|
|
47
|
+
export type { TEnvParams, THandlerOpt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doracli/express",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "use express",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"@cclr/lang": "^0.1.28",
|
|
30
30
|
"@cclr/utils": "^0.1.28",
|
|
31
31
|
"@dorabag/file-pro": "^1.0.10",
|
|
32
|
-
"@doracli/define-server": "0.0.
|
|
33
|
-
"@doracli/helper": "0.0.
|
|
34
|
-
"@doracli/type": "0.0.
|
|
35
|
-
"@types/express": "^5.0.
|
|
32
|
+
"@doracli/define-server": "0.0.2",
|
|
33
|
+
"@doracli/helper": "0.0.2",
|
|
34
|
+
"@doracli/type": "0.0.2",
|
|
35
|
+
"@types/express": "^5.0.4",
|
|
36
36
|
"express": "^5.1.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "912cb44292b64679630a799974d18c22b2e69738"
|
|
39
39
|
}
|