phecda-server 5.0.2 → 5.1.1

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 (57) hide show
  1. package/README.md +4 -102
  2. package/bin/cli.mjs +17 -14
  3. package/dist/{chunk-RCTOVYZY.mjs → chunk-2HKQPZDT.mjs} +1 -1
  4. package/dist/{chunk-BXLBWRHS.js → chunk-3BV2GRS7.js} +38 -38
  5. package/dist/{chunk-AB4OX3WV.mjs → chunk-665MB62T.mjs} +127 -99
  6. package/dist/{chunk-YERBWZCS.js → chunk-FSBD5R22.js} +180 -152
  7. package/dist/{chunk-F5YWXY5W.js → chunk-HMPTPTFL.js} +17 -17
  8. package/dist/{chunk-W5EOVGQD.mjs → chunk-UU6RHGRF.mjs} +2 -2
  9. package/dist/{chunk-ITTD2GBR.mjs → chunk-VLV3AO3H.mjs} +7 -19
  10. package/dist/{chunk-YR5Q5F2K.js → chunk-ZP7HNASU.js} +7 -19
  11. package/dist/{core-fd134ffa.d.ts → core-39f27fe8.d.ts} +4 -3
  12. package/dist/{helper-73e8d2f0.d.ts → helper-6133f78f.d.ts} +1 -1
  13. package/dist/{helper-f29f082f.d.ts → helper-fcbf6aa8.d.ts} +4 -3
  14. package/dist/index.d.ts +27 -32
  15. package/dist/index.js +44 -40
  16. package/dist/index.mjs +14 -10
  17. package/dist/rpc/bullmq/index.d.ts +10 -6
  18. package/dist/rpc/bullmq/index.js +32 -53
  19. package/dist/rpc/bullmq/index.mjs +26 -47
  20. package/dist/rpc/kafka/index.d.ts +10 -4
  21. package/dist/rpc/kafka/index.js +20 -37
  22. package/dist/rpc/kafka/index.mjs +15 -32
  23. package/dist/rpc/nats/index.d.ts +2 -2
  24. package/dist/rpc/nats/index.js +20 -34
  25. package/dist/rpc/nats/index.mjs +13 -27
  26. package/dist/rpc/rabbitmq/index.d.ts +2 -2
  27. package/dist/rpc/rabbitmq/index.js +23 -37
  28. package/dist/rpc/rabbitmq/index.mjs +14 -28
  29. package/dist/rpc/redis/index.d.ts +10 -4
  30. package/dist/rpc/redis/index.js +23 -37
  31. package/dist/rpc/redis/index.mjs +16 -30
  32. package/dist/server/elysia/index.d.ts +4 -3
  33. package/dist/server/elysia/index.js +77 -94
  34. package/dist/server/elysia/index.mjs +74 -91
  35. package/dist/server/express/index.d.ts +5 -4
  36. package/dist/server/express/index.js +79 -93
  37. package/dist/server/express/index.mjs +77 -91
  38. package/dist/server/fastify/index.d.ts +8 -5
  39. package/dist/server/fastify/index.js +83 -102
  40. package/dist/server/fastify/index.mjs +79 -98
  41. package/dist/server/h3/index.d.ts +5 -4
  42. package/dist/server/h3/index.js +81 -97
  43. package/dist/server/h3/index.mjs +80 -96
  44. package/dist/server/hono/index.d.ts +5 -4
  45. package/dist/server/hono/index.js +73 -90
  46. package/dist/server/hono/index.mjs +72 -89
  47. package/dist/server/hyper-express/index.d.ts +6 -5
  48. package/dist/server/hyper-express/index.js +78 -96
  49. package/dist/server/hyper-express/index.mjs +77 -95
  50. package/dist/server/koa/index.d.ts +5 -4
  51. package/dist/server/koa/index.js +79 -92
  52. package/dist/server/koa/index.mjs +76 -89
  53. package/dist/test.d.ts +1 -1
  54. package/dist/test.js +6 -6
  55. package/dist/test.mjs +2 -2
  56. package/package.json +9 -8
  57. package/register/loader.mjs +19 -5
@@ -1,98 +1,96 @@
1
1
  import {
2
2
  BadRequestException,
3
3
  Context,
4
- HMR,
5
4
  argToReq,
5
+ createControllerMetaMap,
6
6
  detectAopDep
7
- } from "../../chunk-AB4OX3WV.mjs";
7
+ } from "../../chunk-665MB62T.mjs";
8
8
  import {
9
9
  __name
10
- } from "../../chunk-ITTD2GBR.mjs";
10
+ } from "../../chunk-VLV3AO3H.mjs";
11
11
 
12
12
  // src/server/hono/bind.ts
13
13
  import Debug from "debug";
14
14
  var debug = Debug("phecda-server/hono");
15
15
  function bind(router, data, opts = {}) {
16
- const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
17
- route: "/__PHECDA_SERVER__",
18
- plugins: [],
19
- ...opts
20
- };
16
+ const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
21
17
  const { moduleMap, meta } = data;
22
- const metaMap = /* @__PURE__ */ new Map();
23
- function handleMeta() {
24
- metaMap.clear();
25
- for (const item of meta) {
26
- const { tag, func, controller, http } = item.data;
27
- if (controller !== "http" || !http?.type)
28
- continue;
18
+ const metaMap = createControllerMetaMap(meta, (meta2) => {
19
+ const { controller, http, func, tag } = meta2.data;
20
+ if (controller === "http" && http?.type) {
29
21
  debug(`register method "${func}" in module "${tag}"`);
30
- if (metaMap.has(tag))
31
- metaMap.get(tag)[func] = item;
32
- else
33
- metaMap.set(tag, {
34
- [func]: item
35
- });
22
+ return true;
36
23
  }
37
- }
38
- __name(handleMeta, "handleMeta");
39
- async function createRoute() {
40
- router.post(route, ...Context.usePlugin(plugins), async (c) => {
41
- const body = await c.req.json();
42
- async function errorHandler(e) {
43
- const error = await Context.filterRecord.default(e);
44
- c.status(error.status);
45
- return c.json(error);
46
- }
47
- __name(errorHandler, "errorHandler");
48
- if (!Array.isArray(body))
49
- return errorHandler(new BadRequestException("data format should be an array"));
50
- try {
51
- return Promise.all(body.map((item, i) => {
52
- return new Promise(async (resolve) => {
53
- const { tag, func } = item;
54
- debug(`(parallel)invoke method "${func}" in module "${tag}"`);
55
- if (!metaMap.has(tag))
56
- return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
57
- const meta2 = metaMap.get(tag)[func];
58
- if (!meta2)
59
- return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
60
- const { data: { params } } = meta2;
61
- const contextData = {
62
- type: "hono",
63
- parallel: true,
64
- context: c,
65
- index: i,
66
- meta: meta2,
67
- moduleMap,
68
- tag,
69
- func,
70
- app: router,
71
- ...argToReq(params, item.args, c.req.header())
72
- };
73
- const context = new Context(contextData);
74
- context.run({
75
- globalGuards,
76
- globalInterceptors,
77
- globalFilter,
78
- globalPipe
79
- }, resolve, resolve);
24
+ });
25
+ detectAopDep(meta, {
26
+ plugins: [
27
+ ...globalPlugins,
28
+ ...parallelPlugins
29
+ ],
30
+ guards: globalGuards,
31
+ interceptors: globalInterceptors
32
+ });
33
+ registerRoute();
34
+ async function registerRoute() {
35
+ Context.usePlugin(globalPlugins, "hono").forEach((p) => router.use(p));
36
+ if (parallelRoute) {
37
+ router.post(parallelRoute, ...Context.usePlugin(parallelPlugins, "hono"), async (c) => {
38
+ const body = await c.req.json();
39
+ async function errorHandler(e) {
40
+ const error = await Context.filterRecord.default(e);
41
+ c.status(error.status);
42
+ return c.json(error);
43
+ }
44
+ __name(errorHandler, "errorHandler");
45
+ if (!Array.isArray(body))
46
+ return errorHandler(new BadRequestException("data format should be an array"));
47
+ try {
48
+ return Promise.all(body.map((item, i) => {
49
+ return new Promise(async (resolve) => {
50
+ const { tag, func } = item;
51
+ debug(`(parallel)invoke method "${func}" in module "${tag}"`);
52
+ if (!metaMap.has(tag))
53
+ return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
54
+ const meta2 = metaMap.get(tag)[func];
55
+ if (!meta2)
56
+ return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
57
+ const { data: { params } } = meta2;
58
+ const contextData = {
59
+ type: "hono",
60
+ parallel: true,
61
+ context: c,
62
+ index: i,
63
+ meta: meta2,
64
+ moduleMap,
65
+ tag,
66
+ func,
67
+ app: router,
68
+ ...argToReq(params, item.args, c.req.header())
69
+ };
70
+ const context = new Context(contextData);
71
+ context.run({
72
+ globalGuards,
73
+ globalInterceptors,
74
+ globalFilter,
75
+ globalPipe
76
+ }, resolve, resolve);
77
+ });
78
+ })).then((ret) => {
79
+ return c.json(ret);
80
80
  });
81
- })).then((ret) => {
82
- return c.json(ret);
83
- });
84
- } catch (e) {
85
- return errorHandler(e);
86
- }
87
- });
81
+ } catch (e) {
82
+ return errorHandler(e);
83
+ }
84
+ });
85
+ }
88
86
  for (const [tag, record] of metaMap) {
89
87
  for (const func in record) {
90
88
  const meta2 = metaMap.get(tag)[func];
91
- const { data: { params, plugins: plugins2, http } } = meta2;
89
+ const { data: { params, plugins, http } } = meta2;
92
90
  if (!http?.type)
93
91
  continue;
94
92
  const needBody = params.some((item) => item.type === "body");
95
- router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins2), async (c) => {
93
+ router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins, "hono"), async (c) => {
96
94
  debug(`invoke method "${func}" in module "${tag}"`);
97
95
  const contextData = {
98
96
  type: "hono",
@@ -132,22 +130,7 @@ function bind(router, data, opts = {}) {
132
130
  }
133
131
  }
134
132
  }
135
- __name(createRoute, "createRoute");
136
- detectAopDep(meta, {
137
- plugins,
138
- guards: globalGuards,
139
- interceptors: globalInterceptors
140
- });
141
- handleMeta();
142
- createRoute();
143
- HMR(async () => {
144
- detectAopDep(meta, {
145
- plugins,
146
- guards: globalGuards,
147
- interceptors: globalInterceptors
148
- });
149
- handleMeta();
150
- });
133
+ __name(registerRoute, "registerRoute");
151
134
  }
152
135
  __name(bind, "bind");
153
136
  export {
@@ -1,6 +1,6 @@
1
- import { Request, Response, Router } from 'hyper-express';
2
- import { a as HttpContext, H as HttpOptions } from '../../helper-f29f082f.js';
3
- import { F as Factory } from '../../core-fd134ffa.js';
1
+ import { Request, Response, Router, MiddlewareHandler } from 'hyper-express';
2
+ import { a as HttpContext, H as HttpOptions } from '../../helper-fcbf6aa8.js';
3
+ import { F as Factory } from '../../core-39f27fe8.js';
4
4
  import 'node:http';
5
5
  import 'phecda-core';
6
6
 
@@ -11,6 +11,7 @@ interface HyperExpressCtx extends HttpContext {
11
11
  next: Function;
12
12
  app: Router;
13
13
  }
14
- declare function bind(router: Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
14
+ type Plugin = MiddlewareHandler;
15
+ declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
15
16
 
16
- export { HyperExpressCtx, bind };
17
+ export { HyperExpressCtx, Plugin, bind };
@@ -4,99 +4,96 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
7
+ var _chunkFSBD5R22js = require('../../chunk-FSBD5R22.js');
8
8
 
9
9
 
10
- var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
10
+ var _chunkZP7HNASUjs = require('../../chunk-ZP7HNASU.js');
11
11
 
12
12
  // src/server/hyper-express/bind.ts
13
13
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
14
14
  var debug = _debug2.default.call(void 0, "phecda-server/hyper-express");
15
- function bind(router, { moduleMap, meta }, opts = {}) {
16
- const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
17
- route: "/__PHECDA_SERVER__",
18
- plugins: [],
19
- ...opts
20
- };
21
- const metaMap = /* @__PURE__ */ new Map();
22
- function handleMeta() {
23
- metaMap.clear();
24
- for (const item of meta) {
25
- const { tag, func, controller, http } = item.data;
26
- if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
27
- continue;
15
+ function bind(router, data, opts = {}) {
16
+ const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
17
+ const { moduleMap, meta } = data;
18
+ const metaMap = _chunkFSBD5R22js.createControllerMetaMap.call(void 0, meta, (meta2) => {
19
+ const { controller, http, func, tag } = meta2.data;
20
+ if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
28
21
  debug(`register method "${func}" in module "${tag}"`);
29
- if (metaMap.has(tag))
30
- metaMap.get(tag)[func] = item;
31
- else
32
- metaMap.set(tag, {
33
- [func]: item
34
- });
22
+ return true;
35
23
  }
36
- }
37
- _chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
38
- async function createRoute() {
39
- router.post(route, {
40
- middlewares: [
41
- ..._chunkYERBWZCSjs.Context.usePlugin(plugins)
42
- ]
43
- }, async (req, res, next) => {
44
- const body = await req.json();
45
- async function errorHandler(e) {
46
- const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
47
- return res.status(error.status).json(error);
48
- }
49
- _chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
50
- if (!Array.isArray(body))
51
- return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
52
- try {
53
- return Promise.all(body.map((item, i) => {
54
- return new Promise(async (resolve) => {
55
- const { tag, func } = item;
56
- debug(`(parallel)invoke method "${func}" in module "${tag}"`);
57
- if (!metaMap.has(tag))
58
- return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
59
- const meta2 = metaMap.get(tag)[func];
60
- if (!meta2)
61
- return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
62
- const { data: { params } } = meta2;
63
- const contextData = {
64
- type: "hyper-express",
65
- parallel: true,
66
- request: req,
67
- index: i,
68
- meta: meta2,
69
- response: res,
70
- moduleMap,
71
- tag,
72
- func,
73
- next,
74
- app: router,
75
- ..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, req.headers)
76
- };
77
- const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
78
- context.run({
79
- globalGuards,
80
- globalInterceptors,
81
- globalFilter,
82
- globalPipe
83
- }, resolve, resolve);
24
+ });
25
+ _chunkFSBD5R22js.detectAopDep.call(void 0, meta, {
26
+ plugins: [
27
+ ...globalPlugins,
28
+ ...parallelPlugins
29
+ ],
30
+ guards: globalGuards,
31
+ interceptors: globalInterceptors
32
+ });
33
+ registerRoute();
34
+ async function registerRoute() {
35
+ _chunkFSBD5R22js.Context.usePlugin(globalPlugins, "hyper-express").forEach((p) => router.use(p));
36
+ if (parallelRoute) {
37
+ router.post(parallelRoute, {
38
+ middlewares: _chunkFSBD5R22js.Context.usePlugin(parallelPlugins, "hyper-express")
39
+ }, async (req, res, next) => {
40
+ const body = await req.json();
41
+ async function errorHandler(e) {
42
+ const error = await _chunkFSBD5R22js.Context.filterRecord.default(e);
43
+ return res.status(error.status).json(error);
44
+ }
45
+ _chunkZP7HNASUjs.__name.call(void 0, errorHandler, "errorHandler");
46
+ if (!Array.isArray(body))
47
+ return errorHandler(new (0, _chunkFSBD5R22js.BadRequestException)("data format should be an array"));
48
+ try {
49
+ return Promise.all(body.map((item, i) => {
50
+ return new Promise(async (resolve) => {
51
+ const { tag, func } = item;
52
+ debug(`(parallel)invoke method "${func}" in module "${tag}"`);
53
+ if (!metaMap.has(tag))
54
+ return resolve(await _chunkFSBD5R22js.Context.filterRecord.default(new (0, _chunkFSBD5R22js.BadRequestException)(`module "${tag}" doesn't exist`)));
55
+ const meta2 = metaMap.get(tag)[func];
56
+ if (!meta2)
57
+ return resolve(await _chunkFSBD5R22js.Context.filterRecord.default(new (0, _chunkFSBD5R22js.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
58
+ const { data: { params } } = meta2;
59
+ const contextData = {
60
+ type: "hyper-express",
61
+ parallel: true,
62
+ request: req,
63
+ index: i,
64
+ meta: meta2,
65
+ response: res,
66
+ moduleMap,
67
+ tag,
68
+ func,
69
+ next,
70
+ app: router,
71
+ ..._chunkFSBD5R22js.argToReq.call(void 0, params, item.args, req.headers)
72
+ };
73
+ const context = new (0, _chunkFSBD5R22js.Context)(contextData);
74
+ context.run({
75
+ globalGuards,
76
+ globalInterceptors,
77
+ globalFilter,
78
+ globalPipe
79
+ }, resolve, resolve);
80
+ });
81
+ })).then((ret) => {
82
+ res.json(ret);
84
83
  });
85
- })).then((ret) => {
86
- res.json(ret);
87
- });
88
- } catch (e) {
89
- return errorHandler(e);
90
- }
91
- });
84
+ } catch (e) {
85
+ return errorHandler(e);
86
+ }
87
+ });
88
+ }
92
89
  for (const [tag, record] of metaMap) {
93
90
  for (const func in record) {
94
91
  const meta2 = metaMap.get(tag)[func];
95
- const { data: { params, plugins: plugins2, http } } = meta2;
92
+ const { data: { params, plugins, http } } = meta2;
96
93
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
97
94
  continue;
98
95
  const needBody = params.some((item) => item.type === "body");
99
- router[http.type](http.prefix + http.route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins2), async (req, res, next) => {
96
+ router[http.type](http.prefix + http.route, ..._chunkFSBD5R22js.Context.usePlugin(plugins, "hyper-express"), async (req, res, next) => {
100
97
  debug(`invoke method "${func}" in module "${tag}"`);
101
98
  const contextData = {
102
99
  type: "hyper-express",
@@ -113,7 +110,7 @@ function bind(router, { moduleMap, meta }, opts = {}) {
113
110
  headers: req.headers,
114
111
  next
115
112
  };
116
- const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
113
+ const context = new (0, _chunkFSBD5R22js.Context)(contextData);
117
114
  if (http.headers) {
118
115
  for (const name in http.headers)
119
116
  res.set(name, http.headers[name]);
@@ -139,24 +136,9 @@ function bind(router, { moduleMap, meta }, opts = {}) {
139
136
  }
140
137
  }
141
138
  }
142
- _chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
143
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
144
- plugins,
145
- guards: globalGuards,
146
- interceptors: globalInterceptors
147
- });
148
- handleMeta();
149
- createRoute();
150
- _chunkYERBWZCSjs.HMR.call(void 0, () => {
151
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
152
- plugins,
153
- guards: globalGuards,
154
- interceptors: globalInterceptors
155
- });
156
- handleMeta();
157
- });
139
+ _chunkZP7HNASUjs.__name.call(void 0, registerRoute, "registerRoute");
158
140
  }
159
- _chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
141
+ _chunkZP7HNASUjs.__name.call(void 0, bind, "bind");
160
142
 
161
143
 
162
144
  exports.bind = bind;
@@ -1,102 +1,99 @@
1
1
  import {
2
2
  BadRequestException,
3
3
  Context,
4
- HMR,
5
4
  argToReq,
5
+ createControllerMetaMap,
6
6
  detectAopDep
7
- } from "../../chunk-AB4OX3WV.mjs";
7
+ } from "../../chunk-665MB62T.mjs";
8
8
  import {
9
9
  __name
10
- } from "../../chunk-ITTD2GBR.mjs";
10
+ } from "../../chunk-VLV3AO3H.mjs";
11
11
 
12
12
  // src/server/hyper-express/bind.ts
13
13
  import Debug from "debug";
14
14
  var debug = Debug("phecda-server/hyper-express");
15
- function bind(router, { moduleMap, meta }, opts = {}) {
16
- const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
17
- route: "/__PHECDA_SERVER__",
18
- plugins: [],
19
- ...opts
20
- };
21
- const metaMap = /* @__PURE__ */ new Map();
22
- function handleMeta() {
23
- metaMap.clear();
24
- for (const item of meta) {
25
- const { tag, func, controller, http } = item.data;
26
- if (controller !== "http" || !http?.type)
27
- continue;
15
+ function bind(router, data, opts = {}) {
16
+ const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
17
+ const { moduleMap, meta } = data;
18
+ const metaMap = createControllerMetaMap(meta, (meta2) => {
19
+ const { controller, http, func, tag } = meta2.data;
20
+ if (controller === "http" && http?.type) {
28
21
  debug(`register method "${func}" in module "${tag}"`);
29
- if (metaMap.has(tag))
30
- metaMap.get(tag)[func] = item;
31
- else
32
- metaMap.set(tag, {
33
- [func]: item
34
- });
22
+ return true;
35
23
  }
36
- }
37
- __name(handleMeta, "handleMeta");
38
- async function createRoute() {
39
- router.post(route, {
40
- middlewares: [
41
- ...Context.usePlugin(plugins)
42
- ]
43
- }, async (req, res, next) => {
44
- const body = await req.json();
45
- async function errorHandler(e) {
46
- const error = await Context.filterRecord.default(e);
47
- return res.status(error.status).json(error);
48
- }
49
- __name(errorHandler, "errorHandler");
50
- if (!Array.isArray(body))
51
- return errorHandler(new BadRequestException("data format should be an array"));
52
- try {
53
- return Promise.all(body.map((item, i) => {
54
- return new Promise(async (resolve) => {
55
- const { tag, func } = item;
56
- debug(`(parallel)invoke method "${func}" in module "${tag}"`);
57
- if (!metaMap.has(tag))
58
- return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
59
- const meta2 = metaMap.get(tag)[func];
60
- if (!meta2)
61
- return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
62
- const { data: { params } } = meta2;
63
- const contextData = {
64
- type: "hyper-express",
65
- parallel: true,
66
- request: req,
67
- index: i,
68
- meta: meta2,
69
- response: res,
70
- moduleMap,
71
- tag,
72
- func,
73
- next,
74
- app: router,
75
- ...argToReq(params, item.args, req.headers)
76
- };
77
- const context = new Context(contextData);
78
- context.run({
79
- globalGuards,
80
- globalInterceptors,
81
- globalFilter,
82
- globalPipe
83
- }, resolve, resolve);
24
+ });
25
+ detectAopDep(meta, {
26
+ plugins: [
27
+ ...globalPlugins,
28
+ ...parallelPlugins
29
+ ],
30
+ guards: globalGuards,
31
+ interceptors: globalInterceptors
32
+ });
33
+ registerRoute();
34
+ async function registerRoute() {
35
+ Context.usePlugin(globalPlugins, "hyper-express").forEach((p) => router.use(p));
36
+ if (parallelRoute) {
37
+ router.post(parallelRoute, {
38
+ middlewares: Context.usePlugin(parallelPlugins, "hyper-express")
39
+ }, async (req, res, next) => {
40
+ const body = await req.json();
41
+ async function errorHandler(e) {
42
+ const error = await Context.filterRecord.default(e);
43
+ return res.status(error.status).json(error);
44
+ }
45
+ __name(errorHandler, "errorHandler");
46
+ if (!Array.isArray(body))
47
+ return errorHandler(new BadRequestException("data format should be an array"));
48
+ try {
49
+ return Promise.all(body.map((item, i) => {
50
+ return new Promise(async (resolve) => {
51
+ const { tag, func } = item;
52
+ debug(`(parallel)invoke method "${func}" in module "${tag}"`);
53
+ if (!metaMap.has(tag))
54
+ return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
55
+ const meta2 = metaMap.get(tag)[func];
56
+ if (!meta2)
57
+ return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
58
+ const { data: { params } } = meta2;
59
+ const contextData = {
60
+ type: "hyper-express",
61
+ parallel: true,
62
+ request: req,
63
+ index: i,
64
+ meta: meta2,
65
+ response: res,
66
+ moduleMap,
67
+ tag,
68
+ func,
69
+ next,
70
+ app: router,
71
+ ...argToReq(params, item.args, req.headers)
72
+ };
73
+ const context = new Context(contextData);
74
+ context.run({
75
+ globalGuards,
76
+ globalInterceptors,
77
+ globalFilter,
78
+ globalPipe
79
+ }, resolve, resolve);
80
+ });
81
+ })).then((ret) => {
82
+ res.json(ret);
84
83
  });
85
- })).then((ret) => {
86
- res.json(ret);
87
- });
88
- } catch (e) {
89
- return errorHandler(e);
90
- }
91
- });
84
+ } catch (e) {
85
+ return errorHandler(e);
86
+ }
87
+ });
88
+ }
92
89
  for (const [tag, record] of metaMap) {
93
90
  for (const func in record) {
94
91
  const meta2 = metaMap.get(tag)[func];
95
- const { data: { params, plugins: plugins2, http } } = meta2;
92
+ const { data: { params, plugins, http } } = meta2;
96
93
  if (!http?.type)
97
94
  continue;
98
95
  const needBody = params.some((item) => item.type === "body");
99
- router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins2), async (req, res, next) => {
96
+ router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins, "hyper-express"), async (req, res, next) => {
100
97
  debug(`invoke method "${func}" in module "${tag}"`);
101
98
  const contextData = {
102
99
  type: "hyper-express",
@@ -139,22 +136,7 @@ function bind(router, { moduleMap, meta }, opts = {}) {
139
136
  }
140
137
  }
141
138
  }
142
- __name(createRoute, "createRoute");
143
- detectAopDep(meta, {
144
- plugins,
145
- guards: globalGuards,
146
- interceptors: globalInterceptors
147
- });
148
- handleMeta();
149
- createRoute();
150
- HMR(() => {
151
- detectAopDep(meta, {
152
- plugins,
153
- guards: globalGuards,
154
- interceptors: globalInterceptors
155
- });
156
- handleMeta();
157
- });
139
+ __name(registerRoute, "registerRoute");
158
140
  }
159
141
  __name(bind, "bind");
160
142
  export {
@@ -1,7 +1,7 @@
1
1
  import Router, { RouterParamContext } from '@koa/router';
2
2
  import { DefaultContext, DefaultState } from 'koa';
3
- import { a as HttpContext, H as HttpOptions } from '../../helper-f29f082f.js';
4
- import { F as Factory } from '../../core-fd134ffa.js';
3
+ import { a as HttpContext, H as HttpOptions } from '../../helper-fcbf6aa8.js';
4
+ import { F as Factory } from '../../core-39f27fe8.js';
5
5
  import 'node:http';
6
6
  import 'phecda-core';
7
7
 
@@ -11,6 +11,7 @@ interface KoaCtx extends HttpContext {
11
11
  next: Function;
12
12
  app: Router;
13
13
  }
14
- declare function bind(router: Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
14
+ type Plugin = Router.Middleware;
15
+ declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
15
16
 
16
- export { KoaCtx, bind };
17
+ export { KoaCtx, Plugin, bind };