@eggjs/tegg-controller-plugin 4.0.0-beta.6 → 4.0.0-beta.8

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.
Files changed (48) hide show
  1. package/dist/Acl-BF8dxD8f.js +29 -0
  2. package/dist/AppLoadUnitControllerHook-C3F2NtiE.js +27 -0
  3. package/dist/ControllerLoadUnit-DWgcQuC0.js +63 -0
  4. package/dist/ControllerLoadUnitHandler-BiPlOVSN.js +29 -0
  5. package/dist/ControllerMetadataManager-CC5nmTlv.js +23 -0
  6. package/dist/ControllerRegister-DDwsWz5F.d.ts +9 -0
  7. package/dist/ControllerRegister-DPqM08MF.js +3 -0
  8. package/dist/ControllerRegisterFactory-Bz7bulBg.js +23 -0
  9. package/dist/ControllerRegisterFactory-DCPVkM4E.d.ts +16 -0
  10. package/dist/EggControllerLoader-iohfFKpj.js +29 -0
  11. package/dist/EggControllerPrototypeHook-Djf4Mwvw.js +13 -0
  12. package/dist/HTTPControllerRegister-CZQJslUT.js +58 -0
  13. package/dist/HTTPMethodRegister-CHHFV-eT.js +138 -0
  14. package/dist/Req-D3i-7606.js +16 -0
  15. package/dist/RootProtoManager-CbLm-PD1.js +28 -0
  16. package/dist/RootProtoManager-DkqD47oc.d.ts +12 -0
  17. package/dist/app-CZQLJgoQ.d.ts +27 -0
  18. package/dist/app-Dq89t2rF.js +67 -0
  19. package/dist/app.d.ts +4 -26
  20. package/dist/app.js +15 -65
  21. package/dist/errors-CnXI09lf.js +16 -0
  22. package/dist/index.d.ts +5 -1
  23. package/dist/index.js +16 -1
  24. package/dist/lib/AppLoadUnitControllerHook.d.ts +3 -2
  25. package/dist/lib/AppLoadUnitControllerHook.js +5 -27
  26. package/dist/lib/ControllerLoadUnit.js +1 -61
  27. package/dist/lib/ControllerLoadUnitHandler.js +2 -27
  28. package/dist/lib/ControllerMetadataManager.js +1 -21
  29. package/dist/lib/ControllerRegister.d.ts +2 -8
  30. package/dist/lib/ControllerRegister.js +2 -2
  31. package/dist/lib/ControllerRegisterFactory.d.ts +3 -15
  32. package/dist/lib/ControllerRegisterFactory.js +3 -22
  33. package/dist/lib/EggControllerLoader.js +1 -27
  34. package/dist/lib/EggControllerPrototypeHook.js +1 -11
  35. package/dist/lib/RootProtoManager.d.ts +1 -11
  36. package/dist/lib/RootProtoManager.js +1 -26
  37. package/dist/lib/errors.js +1 -14
  38. package/dist/lib/impl/http/Acl.js +1 -27
  39. package/dist/lib/impl/http/HTTPControllerRegister.d.ts +2 -2
  40. package/dist/lib/impl/http/HTTPControllerRegister.js +7 -58
  41. package/dist/lib/impl/http/HTTPMethodRegister.d.ts +1 -1
  42. package/dist/lib/impl/http/HTTPMethodRegister.js +5 -137
  43. package/dist/lib/impl/http/Req.js +1 -14
  44. package/dist/types-D9vieyYE.d.ts +1 -0
  45. package/dist/types-DkvgFpN4.js +3 -0
  46. package/dist/types.d.ts +5 -1
  47. package/dist/types.js +16 -2
  48. package/package.json +11 -11
@@ -1,139 +1,7 @@
1
- import "../../RootProtoManager.js";
2
- import { aclMiddlewareFactory } from "./Acl.js";
3
- import { HTTPRequest as HTTPRequest$1 } from "./Req.js";
4
- import { RouterConflictError } from "../../errors.js";
5
- import "@eggjs/tegg-metadata";
6
- import { HTTPControllerMeta, HTTPCookies, HTTPMethodMeta, HTTPParamType } from "@eggjs/tegg";
7
- import { EggContainerFactory } from "@eggjs/tegg-runtime";
8
- import { Context, Router } from "egg";
9
- import assert from "node:assert";
10
- import pathToRegexp from "path-to-regexp";
11
- import { EggRouter } from "@eggjs/router";
12
- import { FrameworkErrorFormater } from "egg-errors";
1
+ import "../../../RootProtoManager-CbLm-PD1.js";
2
+ import "../../../Acl-BF8dxD8f.js";
3
+ import "../../../Req-D3i-7606.js";
4
+ import "../../../errors-CnXI09lf.js";
5
+ import { HTTPMethodRegister } from "../../../HTTPMethodRegister-CHHFV-eT.js";
13
6
 
14
- //#region src/lib/impl/http/HTTPMethodRegister.ts
15
- const noop = () => {};
16
- var HTTPMethodRegister = class {
17
- router;
18
- checkRouters;
19
- controllerMeta;
20
- methodMeta;
21
- proto;
22
- eggContainerFactory;
23
- constructor(proto, controllerMeta, methodMeta, router, checkRouters, eggContainerFactory) {
24
- this.proto = proto;
25
- this.controllerMeta = controllerMeta;
26
- this.router = router;
27
- this.methodMeta = methodMeta;
28
- this.checkRouters = checkRouters;
29
- this.eggContainerFactory = eggContainerFactory;
30
- }
31
- createHandler(methodMeta, host) {
32
- const argsLength = methodMeta.paramMap.size;
33
- const hasContext = methodMeta.contextParamIndex !== void 0;
34
- const contextIndex = methodMeta.contextParamIndex;
35
- const methodArgsLength = argsLength + (hasContext ? 1 : 0);
36
- const self = this;
37
- return async function(ctx, next) {
38
- if (host && host !== ctx.host) return await next();
39
- const realObj = (await self.eggContainerFactory.getOrCreateEggObject(self.proto, self.proto.name)).obj;
40
- const realMethod = realObj[methodMeta.name];
41
- const args = Array.from({ length: methodArgsLength });
42
- if (hasContext) args[contextIndex] = ctx;
43
- for (const [index, param] of methodMeta.paramMap) switch (param.type) {
44
- case HTTPParamType.BODY:
45
- args[index] = ctx.request.body;
46
- break;
47
- case HTTPParamType.PARAM: {
48
- const pathParam = param;
49
- args[index] = ctx.params[pathParam.name];
50
- break;
51
- }
52
- case HTTPParamType.QUERY: {
53
- const queryParam = param;
54
- args[index] = ctx.query[queryParam.name];
55
- break;
56
- }
57
- case HTTPParamType.QUERIES: {
58
- const queryParam = param;
59
- args[index] = ctx.queries[queryParam.name];
60
- break;
61
- }
62
- case HTTPParamType.HEADERS:
63
- args[index] = ctx.request.headers;
64
- break;
65
- case HTTPParamType.REQUEST:
66
- args[index] = new HTTPRequest$1(ctx);
67
- break;
68
- case HTTPParamType.COOKIES:
69
- args[index] = new HTTPCookies(ctx, []);
70
- break;
71
- default: assert.fail("never arrive");
72
- }
73
- const body = await Reflect.apply(realMethod, realObj, args);
74
- const explicitStatus = ctx.response._explicitStatus;
75
- if (body !== null && body !== void 0 || !explicitStatus) ctx.body = body;
76
- };
77
- }
78
- checkDuplicate() {
79
- this.checkDuplicateInRouter(this.router);
80
- let hostRouter;
81
- (this.controllerMeta.getMethodHosts(this.methodMeta) || []).forEach((h) => {
82
- if (h) {
83
- hostRouter = this.checkRouters.get(h);
84
- if (!hostRouter) {
85
- hostRouter = new EggRouter({ sensitive: true }, this.router.app);
86
- this.checkRouters.set(h, hostRouter);
87
- }
88
- }
89
- if (hostRouter) {
90
- this.checkDuplicateInRouter(hostRouter);
91
- this.registerToRouter(hostRouter);
92
- }
93
- });
94
- }
95
- registerToRouter(router) {
96
- const routerFunc = router[this.methodMeta.method.toLowerCase()];
97
- const methodRealPath = this.controllerMeta.getMethodRealPath(this.methodMeta);
98
- const methodName = this.controllerMeta.getMethodName(this.methodMeta);
99
- Reflect.apply(routerFunc, router, [
100
- methodName,
101
- methodRealPath,
102
- noop
103
- ]);
104
- }
105
- checkDuplicateInRouter(router) {
106
- const methodRealPath = this.controllerMeta.getMethodRealPath(this.methodMeta);
107
- const matched = router.match(methodRealPath, this.methodMeta.method);
108
- const methodName = this.controllerMeta.getMethodName(this.methodMeta);
109
- if (matched.route) {
110
- const [layer] = matched.path;
111
- const err = new RouterConflictError(`register http controller ${methodName} failed, ${this.methodMeta.method} ${methodRealPath} is conflict with exists rule ${layer.path}`);
112
- throw FrameworkErrorFormater.format(err);
113
- }
114
- }
115
- register(rootProtoManager) {
116
- const methodRealPath = this.controllerMeta.getMethodRealPath(this.methodMeta);
117
- const methodName = this.controllerMeta.getMethodName(this.methodMeta);
118
- const routerFunc = this.router[this.methodMeta.method.toLowerCase()];
119
- const methodMiddlewares = this.controllerMeta.getMethodMiddlewares(this.methodMeta);
120
- const aclMiddleware = aclMiddlewareFactory(this.controllerMeta, this.methodMeta);
121
- if (aclMiddleware) methodMiddlewares.push(aclMiddleware);
122
- (this.controllerMeta.getMethodHosts(this.methodMeta) || [void 0]).forEach((h) => {
123
- const handler = this.createHandler(this.methodMeta, h);
124
- Reflect.apply(routerFunc, this.router, [
125
- methodName,
126
- methodRealPath,
127
- ...methodMiddlewares,
128
- handler
129
- ]);
130
- const regExp = pathToRegexp(methodRealPath, { sensitive: true });
131
- rootProtoManager.registerRootProto(this.methodMeta.method, (ctx) => {
132
- if (regExp.test(ctx.path)) return this.proto;
133
- }, h || "");
134
- });
135
- }
136
- };
137
-
138
- //#endregion
139
7
  export { HTTPMethodRegister };
@@ -1,16 +1,3 @@
1
- import { HTTPRequest as HTTPRequest$1 } from "@eggjs/tegg";
1
+ import { HTTPRequest } from "../../../Req-D3i-7606.js";
2
2
 
3
- //#region src/lib/impl/http/Req.ts
4
- var HTTPRequest = class extends HTTPRequest$1 {
5
- constructor(ctx) {
6
- const request = ctx.request;
7
- super(request.href, {
8
- method: request.method,
9
- headers: request.headers,
10
- body: ctx.request.rawBody
11
- });
12
- }
13
- };
14
-
15
- //#endregion
16
3
  export { HTTPRequest };
@@ -0,0 +1 @@
1
+ import "@eggjs/tegg-plugin/types";
@@ -0,0 +1,3 @@
1
+ import "@eggjs/tegg-plugin/types";
2
+
3
+ export { };
package/dist/types.d.ts CHANGED
@@ -1 +1,5 @@
1
- import "@eggjs/tegg-plugin/types";
1
+ import "./RootProtoManager-DkqD47oc.js";
2
+ import "./ControllerRegister-DDwsWz5F.js";
3
+ import "./ControllerRegisterFactory-DCPVkM4E.js";
4
+ import "./app-CZQLJgoQ.js";
5
+ import "./types-D9vieyYE.js";
package/dist/types.js CHANGED
@@ -1,4 +1,18 @@
1
- import "./app.js";
2
- import "@eggjs/tegg-plugin/types";
1
+ import "./ControllerLoadUnit-DWgcQuC0.js";
2
+ import "./RootProtoManager-CbLm-PD1.js";
3
+ import "./ControllerRegister-DPqM08MF.js";
4
+ import "./ControllerRegisterFactory-Bz7bulBg.js";
5
+ import "./ControllerMetadataManager-CC5nmTlv.js";
6
+ import "./AppLoadUnitControllerHook-C3F2NtiE.js";
7
+ import "./Acl-BF8dxD8f.js";
8
+ import "./Req-D3i-7606.js";
9
+ import "./errors-CnXI09lf.js";
10
+ import "./HTTPMethodRegister-CHHFV-eT.js";
11
+ import "./HTTPControllerRegister-CZQJslUT.js";
12
+ import "./ControllerLoadUnitHandler-BiPlOVSN.js";
13
+ import "./EggControllerPrototypeHook-Djf4Mwvw.js";
14
+ import "./EggControllerLoader-iohfFKpj.js";
15
+ import "./app-Dq89t2rF.js";
16
+ import "./types-DkvgFpN4.js";
3
17
 
4
18
  export { };
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "tegg"
8
8
  ]
9
9
  },
10
- "version": "4.0.0-beta.6",
10
+ "version": "4.0.0-beta.8",
11
11
  "description": "controller decorator for egg",
12
12
  "keywords": [
13
13
  "egg",
@@ -60,17 +60,17 @@
60
60
  "globby": "^14.1.0",
61
61
  "path-to-regexp": "^1.9.0",
62
62
  "sdk-base": "^5.0.1",
63
- "@eggjs/egg-module-common": "4.0.0-beta.6",
64
- "@eggjs/tegg": "4.0.0-beta.6",
65
- "@eggjs/tegg-common-util": "4.0.0-beta.6",
66
- "@eggjs/tegg-loader": "4.0.0-beta.6",
67
- "@eggjs/tegg-runtime": "4.0.0-beta.6",
68
- "@eggjs/tegg-metadata": "4.0.0-beta.6",
69
- "@eggjs/tegg-types": "4.0.0-beta.6"
63
+ "@eggjs/egg-module-common": "4.0.0-beta.8",
64
+ "@eggjs/tegg-common-util": "4.0.0-beta.8",
65
+ "@eggjs/tegg": "4.0.0-beta.8",
66
+ "@eggjs/tegg-metadata": "4.0.0-beta.8",
67
+ "@eggjs/tegg-loader": "4.0.0-beta.8",
68
+ "@eggjs/tegg-runtime": "4.0.0-beta.8",
69
+ "@eggjs/tegg-types": "4.0.0-beta.8"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "egg": "beta",
73
- "@eggjs/tegg-plugin": "4.0.0-beta.6"
73
+ "@eggjs/tegg-plugin": "4.0.0-beta.8"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@eggjs/mock": "beta",
@@ -81,8 +81,8 @@
81
81
  "tsdown": "^0.15.6",
82
82
  "unplugin-unused": "^0.5.3",
83
83
  "@eggjs/module-test-util": "4.0.0-beta.4",
84
- "@eggjs/tegg-config": "4.0.0-beta.6",
85
- "@eggjs/tegg-plugin": "4.0.0-beta.6"
84
+ "@eggjs/tegg-config": "4.0.0-beta.8",
85
+ "@eggjs/tegg-plugin": "4.0.0-beta.8"
86
86
  },
87
87
  "publishConfig": {
88
88
  "access": "public"