@domain.js/main 0.4.17 → 0.4.18

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.
@@ -10,6 +10,8 @@ export interface Cnf {
10
10
  [propName: string]: any;
11
11
  }
12
12
  export interface Profile {
13
+ /** 操作涉及到的资源名称 */
14
+ resource?: string;
13
15
  verb?: string;
14
16
  clientIp: string;
15
17
  remoteIp: string;
@@ -76,7 +76,7 @@ function Router(deps) {
76
76
  });
77
77
  }
78
78
  // eslint-disable-next-line max-params
79
- function register(verb, route, methodPath, code = 200, isList = false, handler, resHandler) {
79
+ function register(verb, route, methodPath, code = 200, isList = false, handler, resHandler, resource) {
80
80
  /**
81
81
  * 暂存起来,提供给apis接口来
82
82
  * apis接口用来返回当前 services 提供的可用的 api
@@ -92,6 +92,8 @@ function Router(deps) {
92
92
  }
93
93
  server[verb](route, async (req, res, next) => {
94
94
  const profile = makeProfile(req, methodPath, makeProfileHook);
95
+ if (resource)
96
+ profile.resource = resource;
95
97
  const params = makeParams(req);
96
98
  // 额外处理 params
97
99
  if (handler)
@@ -174,19 +176,19 @@ function Router(deps) {
174
176
  routePath = _routePath;
175
177
  }
176
178
  if (controller) {
177
- register("get", routePath, `${controller}.${name}s`, 200, true);
178
- register("post", routePath, `${controller}.add${ucwords(name)}`, 201);
179
+ register("get", routePath, `${controller}.${name}s`, 200, true, undefined, undefined, name);
180
+ register("post", routePath, `${controller}.add${ucwords(name)}`, 201, false, undefined, undefined, name);
179
181
  }
180
182
  else {
181
- register("get", routePath, `${name}.list`, 200, true);
182
- register("post", routePath, `${name}.add`, 201);
183
+ register("get", routePath, `${name}.list`, 200, true, undefined, undefined, name);
184
+ register("post", routePath, `${name}.add`, 201, false, undefined, undefined, name);
183
185
  }
184
186
  };
185
187
  const model = (res, routePath = `/${res}s/:id`) => {
186
- register("get", routePath, `${res}.detail`);
187
- register("put", routePath, `${res}.modify`);
188
- register("patch", routePath, `${res}.modify`);
189
- register("del", routePath, `${res}.remove`, 204);
188
+ register("get", routePath, `${res}.detail`, 200, false, undefined, undefined, res);
189
+ register("put", routePath, `${res}.modify`, 200, false, undefined, undefined, res);
190
+ register("patch", routePath, `${res}.modify`, 200, false, undefined, undefined, res);
191
+ register("del", routePath, `${res}.remove`, 204, false, undefined, undefined, res);
190
192
  };
191
193
  const resource = (res, routePath = `/${res}s`) => {
192
194
  collection(res, routePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.4.17",
3
+ "version": "0.4.18",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {