phecda-server 5.0.0 → 5.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.
Files changed (54) hide show
  1. package/bin/schema.json +7 -0
  2. package/dist/{chunk-5VMFQOJ7.mjs → chunk-AB4OX3WV.mjs} +13 -5
  3. package/dist/{chunk-VMXI3KFJ.js → chunk-BXLBWRHS.js} +12 -12
  4. package/dist/{chunk-C7MN5B36.mjs → chunk-W5EOVGQD.mjs} +1 -1
  5. package/dist/{chunk-5YYZLGGN.js → chunk-YERBWZCS.js} +13 -5
  6. package/dist/{core-eb646fe5.d.ts → core-fd134ffa.d.ts} +6 -15
  7. package/dist/helper-73e8d2f0.d.ts +18 -0
  8. package/dist/helper-f29f082f.d.ts +19 -0
  9. package/dist/index.d.ts +7 -7
  10. package/dist/index.js +23 -23
  11. package/dist/index.mjs +2 -2
  12. package/dist/rpc/bullmq/index.d.ts +2 -3
  13. package/dist/rpc/bullmq/index.js +14 -17
  14. package/dist/rpc/bullmq/index.mjs +9 -12
  15. package/dist/rpc/kafka/index.d.ts +2 -3
  16. package/dist/rpc/kafka/index.js +14 -17
  17. package/dist/rpc/kafka/index.mjs +9 -12
  18. package/dist/rpc/nats/index.d.ts +2 -3
  19. package/dist/rpc/nats/index.js +13 -16
  20. package/dist/rpc/nats/index.mjs +9 -12
  21. package/dist/rpc/rabbitmq/index.d.ts +2 -3
  22. package/dist/rpc/rabbitmq/index.js +14 -17
  23. package/dist/rpc/rabbitmq/index.mjs +9 -12
  24. package/dist/rpc/redis/index.d.ts +2 -3
  25. package/dist/rpc/redis/index.js +14 -17
  26. package/dist/rpc/redis/index.mjs +9 -12
  27. package/dist/server/elysia/index.d.ts +4 -4
  28. package/dist/server/elysia/index.js +30 -30
  29. package/dist/server/elysia/index.mjs +17 -17
  30. package/dist/server/express/index.d.ts +4 -4
  31. package/dist/server/express/index.js +28 -28
  32. package/dist/server/express/index.mjs +16 -16
  33. package/dist/server/fastify/index.d.ts +4 -4
  34. package/dist/server/fastify/index.js +30 -30
  35. package/dist/server/fastify/index.mjs +17 -17
  36. package/dist/server/h3/index.d.ts +5 -10
  37. package/dist/server/h3/index.js +28 -28
  38. package/dist/server/h3/index.mjs +16 -16
  39. package/dist/server/hono/index.d.ts +4 -4
  40. package/dist/server/hono/index.js +28 -28
  41. package/dist/server/hono/index.mjs +16 -16
  42. package/dist/server/hyper-express/index.d.ts +4 -4
  43. package/dist/server/hyper-express/index.js +28 -28
  44. package/dist/server/hyper-express/index.mjs +16 -16
  45. package/dist/server/koa/index.d.ts +4 -4
  46. package/dist/server/koa/index.js +28 -28
  47. package/dist/server/koa/index.mjs +16 -16
  48. package/dist/test.d.ts +1 -2
  49. package/dist/test.js +8 -1
  50. package/dist/test.mjs +8 -1
  51. package/package.json +2 -2
  52. package/register/loader.mjs +36 -8
  53. package/dist/helper-88b19c66.d.ts +0 -12
  54. package/dist/helper-9e206c66.d.ts +0 -12
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkVMXI3KFJjs = require('../../chunk-VMXI3KFJ.js');
3
+ var _chunkBXLBWRHSjs = require('../../chunk-BXLBWRHS.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
- var _chunk5YYZLGGNjs = require('../../chunk-5YYZLGGN.js');
10
+ var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
11
11
 
12
12
 
13
13
  var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
@@ -16,13 +16,11 @@ var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
16
16
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
17
17
  var _elysia = require('elysia');
18
18
  var debug = _debug2.default.call(void 0, "phecda-server/elysia");
19
- function bind(app, data, ServerOptions = {}) {
20
- const { globalGuards, globalInterceptors, route, plugins } = {
19
+ function bind(app, data, opts = {}) {
20
+ const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
21
21
  route: "/__PHECDA_SERVER__",
22
- globalGuards: [],
23
- globalInterceptors: [],
24
22
  plugins: [],
25
- ...ServerOptions
23
+ ...opts
26
24
  };
27
25
  const { moduleMap, meta } = data;
28
26
  const metaMap = /* @__PURE__ */ new Map();
@@ -33,14 +31,6 @@ function bind(app, data, ServerOptions = {}) {
33
31
  if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
34
32
  continue;
35
33
  debug(`register method "${func}" in module "${tag}"`);
36
- item.data.guards = [
37
- ...globalGuards,
38
- ...item.data.guards
39
- ];
40
- item.data.interceptors = [
41
- ...globalInterceptors,
42
- ...item.data.interceptors
43
- ];
44
34
  if (metaMap.has(tag))
45
35
  metaMap.get(tag)[func] = item;
46
36
  else
@@ -52,27 +42,27 @@ function bind(app, data, ServerOptions = {}) {
52
42
  _chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
53
43
  async function createRoute() {
54
44
  const parallelRouter = new (0, _elysia.Elysia)();
55
- _chunk5YYZLGGNjs.Context.usePlugin(plugins).forEach((p) => p(parallelRouter));
45
+ _chunkYERBWZCSjs.Context.usePlugin(plugins).forEach((p) => p(parallelRouter));
56
46
  parallelRouter.post(route, async (c) => {
57
47
  const { body } = c;
58
48
  async function errorHandler(e) {
59
- const error = await _chunk5YYZLGGNjs.Context.filterRecord.default(e);
49
+ const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
60
50
  c.set.status = error.status;
61
51
  return error;
62
52
  }
63
53
  _chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
64
54
  if (!Array.isArray(body))
65
- return errorHandler(new (0, _chunk5YYZLGGNjs.BadRequestException)("data format should be an array"));
55
+ return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
66
56
  try {
67
57
  return Promise.all(body.map((item, i) => {
68
58
  return new Promise(async (resolve) => {
69
59
  const { tag, func } = item;
70
60
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
71
61
  if (!metaMap.has(tag))
72
- return resolve(await _chunk5YYZLGGNjs.Context.filterRecord.default(new (0, _chunk5YYZLGGNjs.BadRequestException)(`module "${tag}" doesn't exist`)));
62
+ return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
73
63
  const meta2 = metaMap.get(tag)[func];
74
64
  if (!meta2)
75
- return resolve(await _chunk5YYZLGGNjs.Context.filterRecord.default(new (0, _chunk5YYZLGGNjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
65
+ return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
76
66
  const { data: { params } } = meta2;
77
67
  const contextData = {
78
68
  type: "elysia",
@@ -84,10 +74,15 @@ function bind(app, data, ServerOptions = {}) {
84
74
  tag,
85
75
  func,
86
76
  app,
87
- ..._chunk5YYZLGGNjs.argToReq.call(void 0, params, item.args, c.headers)
77
+ ..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, c.headers)
88
78
  };
89
- const context = new (0, _chunk5YYZLGGNjs.Context)(contextData);
90
- context.run(resolve, resolve);
79
+ const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
80
+ context.run({
81
+ globalGuards,
82
+ globalInterceptors,
83
+ globalFilter,
84
+ globalPipe
85
+ }, resolve, resolve);
91
86
  });
92
87
  })).then((ret) => {
93
88
  return ret;
@@ -104,7 +99,7 @@ function bind(app, data, ServerOptions = {}) {
104
99
  const funcRouter = new (0, _elysia.Elysia)();
105
100
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
106
101
  continue;
107
- _chunk5YYZLGGNjs.Context.usePlugin(plugins2).forEach((p) => p(funcRouter));
102
+ _chunkYERBWZCSjs.Context.usePlugin(plugins2).forEach((p) => p(funcRouter));
108
103
  funcRouter[http.type](http.prefix + http.route, async (c) => {
109
104
  debug(`invoke method "${func}" in module "${tag}"`);
110
105
  const contextData = {
@@ -120,10 +115,15 @@ function bind(app, data, ServerOptions = {}) {
120
115
  headers: c.headers,
121
116
  app
122
117
  };
123
- const context = new (0, _chunk5YYZLGGNjs.Context)(contextData);
118
+ const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
124
119
  if (http.headers)
125
120
  c.set.headers = http.headers;
126
- return context.run((returnData) => returnData, (err) => {
121
+ return context.run({
122
+ globalGuards,
123
+ globalInterceptors,
124
+ globalFilter,
125
+ globalPipe
126
+ }, (returnData) => returnData, (err) => {
127
127
  c.set.status = err.status;
128
128
  return err;
129
129
  });
@@ -133,15 +133,15 @@ function bind(app, data, ServerOptions = {}) {
133
133
  }
134
134
  }
135
135
  _chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
136
- _chunk5YYZLGGNjs.detectAopDep.call(void 0, meta, {
136
+ _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
137
137
  plugins,
138
138
  guards: globalGuards,
139
139
  interceptors: globalInterceptors
140
140
  });
141
141
  handleMeta();
142
142
  createRoute();
143
- _chunk5YYZLGGNjs.HMR.call(void 0, async () => {
144
- _chunk5YYZLGGNjs.detectAopDep.call(void 0, meta, {
143
+ _chunkYERBWZCSjs.HMR.call(void 0, async () => {
144
+ _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
145
145
  plugins,
146
146
  guards: globalGuards,
147
147
  interceptors: globalInterceptors
@@ -151,7 +151,7 @@ function bind(app, data, ServerOptions = {}) {
151
151
  }
152
152
  _chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
153
153
  function Elysia(opts) {
154
- return _chunkVMXI3KFJjs.Define.call(void 0, "elysia", opts);
154
+ return _chunkBXLBWRHSjs.Define.call(void 0, "elysia", opts);
155
155
  }
156
156
  _chunkYR5Q5F2Kjs.__name.call(void 0, Elysia, "Elysia");
157
157
 
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  Define
3
- } from "../../chunk-C7MN5B36.mjs";
3
+ } from "../../chunk-W5EOVGQD.mjs";
4
4
  import {
5
5
  BadRequestException,
6
6
  Context,
7
7
  HMR,
8
8
  argToReq,
9
9
  detectAopDep
10
- } from "../../chunk-5VMFQOJ7.mjs";
10
+ } from "../../chunk-AB4OX3WV.mjs";
11
11
  import {
12
12
  __name
13
13
  } from "../../chunk-ITTD2GBR.mjs";
@@ -16,13 +16,11 @@ import {
16
16
  import Debug from "debug";
17
17
  import { Elysia as App } from "elysia";
18
18
  var debug = Debug("phecda-server/elysia");
19
- function bind(app, data, ServerOptions = {}) {
20
- const { globalGuards, globalInterceptors, route, plugins } = {
19
+ function bind(app, data, opts = {}) {
20
+ const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
21
21
  route: "/__PHECDA_SERVER__",
22
- globalGuards: [],
23
- globalInterceptors: [],
24
22
  plugins: [],
25
- ...ServerOptions
23
+ ...opts
26
24
  };
27
25
  const { moduleMap, meta } = data;
28
26
  const metaMap = /* @__PURE__ */ new Map();
@@ -33,14 +31,6 @@ function bind(app, data, ServerOptions = {}) {
33
31
  if (controller !== "http" || !http?.type)
34
32
  continue;
35
33
  debug(`register method "${func}" in module "${tag}"`);
36
- item.data.guards = [
37
- ...globalGuards,
38
- ...item.data.guards
39
- ];
40
- item.data.interceptors = [
41
- ...globalInterceptors,
42
- ...item.data.interceptors
43
- ];
44
34
  if (metaMap.has(tag))
45
35
  metaMap.get(tag)[func] = item;
46
36
  else
@@ -87,7 +77,12 @@ function bind(app, data, ServerOptions = {}) {
87
77
  ...argToReq(params, item.args, c.headers)
88
78
  };
89
79
  const context = new Context(contextData);
90
- context.run(resolve, resolve);
80
+ context.run({
81
+ globalGuards,
82
+ globalInterceptors,
83
+ globalFilter,
84
+ globalPipe
85
+ }, resolve, resolve);
91
86
  });
92
87
  })).then((ret) => {
93
88
  return ret;
@@ -123,7 +118,12 @@ function bind(app, data, ServerOptions = {}) {
123
118
  const context = new Context(contextData);
124
119
  if (http.headers)
125
120
  c.set.headers = http.headers;
126
- return context.run((returnData) => returnData, (err) => {
121
+ return context.run({
122
+ globalGuards,
123
+ globalInterceptors,
124
+ globalFilter,
125
+ globalPipe
126
+ }, (returnData) => returnData, (err) => {
127
127
  c.set.status = err.status;
128
128
  return err;
129
129
  });
@@ -1,8 +1,8 @@
1
1
  import { Request, Response, Router } from 'express';
2
- import { S as ServerOptions } from '../../helper-88b19c66.js';
3
- import { H as HttpContext, F as Factory } from '../../core-eb646fe5.js';
2
+ import { a as HttpContext, H as HttpOptions } from '../../helper-f29f082f.js';
3
+ import { F as Factory } from '../../core-fd134ffa.js';
4
+ import 'node:http';
4
5
  import 'phecda-core';
5
- import 'http';
6
6
 
7
7
  interface ExpressCtx extends HttpContext {
8
8
  type: 'express';
@@ -11,6 +11,6 @@ interface ExpressCtx extends HttpContext {
11
11
  next: Function;
12
12
  app: Router;
13
13
  }
14
- declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, ServerOptions?: ServerOptions): void;
14
+ declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
15
15
 
16
16
  export { ExpressCtx, bind };
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunk5YYZLGGNjs = require('../../chunk-5YYZLGGN.js');
7
+ var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
8
8
 
9
9
 
10
10
  var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
@@ -12,13 +12,11 @@ var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
12
12
  // src/server/express/bind.ts
13
13
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
14
14
  var debug = _debug2.default.call(void 0, "phecda-server/express");
15
- function bind(router, data, ServerOptions = {}) {
16
- const { globalGuards, globalInterceptors, route, plugins } = {
15
+ function bind(router, data, opts = {}) {
16
+ const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
17
17
  route: "/__PHECDA_SERVER__",
18
- globalGuards: [],
19
- globalInterceptors: [],
20
18
  plugins: [],
21
- ...ServerOptions
19
+ ...opts
22
20
  };
23
21
  const { moduleMap, meta } = data;
24
22
  const originStack = router.stack.slice(0, router.stack.length);
@@ -30,14 +28,6 @@ function bind(router, data, ServerOptions = {}) {
30
28
  if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
31
29
  continue;
32
30
  debug(`register method "${func}" in module "${tag}"`);
33
- item.data.guards = [
34
- ...globalGuards,
35
- ...item.data.guards
36
- ];
37
- item.data.interceptors = [
38
- ...globalInterceptors,
39
- ...item.data.interceptors
40
- ];
41
31
  if (metaMap.has(tag))
42
32
  metaMap.get(tag)[func] = item;
43
33
  else
@@ -48,25 +38,25 @@ function bind(router, data, ServerOptions = {}) {
48
38
  }
49
39
  _chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
50
40
  async function createRoute() {
51
- router.post(route, ..._chunk5YYZLGGNjs.Context.usePlugin(plugins), async (req, res, next) => {
41
+ router.post(route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins), async (req, res, next) => {
52
42
  const { body } = req;
53
43
  async function errorHandler(e) {
54
- const error = await _chunk5YYZLGGNjs.Context.filterRecord.default(e);
44
+ const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
55
45
  return res.status(error.status).json(error);
56
46
  }
57
47
  _chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
58
48
  if (!Array.isArray(body))
59
- return errorHandler(new (0, _chunk5YYZLGGNjs.BadRequestException)("data format should be an array"));
49
+ return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
60
50
  try {
61
51
  return Promise.all(body.map((item, i) => {
62
52
  return new Promise(async (resolve) => {
63
53
  const { tag, func } = item;
64
54
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
65
55
  if (!metaMap.has(tag))
66
- return resolve(await _chunk5YYZLGGNjs.Context.filterRecord.default(new (0, _chunk5YYZLGGNjs.BadRequestException)(`module "${tag}" doesn't exist`)));
56
+ return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
67
57
  const meta2 = metaMap.get(tag)[func];
68
58
  if (!meta2)
69
- return resolve(await _chunk5YYZLGGNjs.Context.filterRecord.default(new (0, _chunk5YYZLGGNjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
59
+ return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
70
60
  const { data: { params } } = meta2;
71
61
  const contextData = {
72
62
  type: "express",
@@ -80,10 +70,15 @@ function bind(router, data, ServerOptions = {}) {
80
70
  func,
81
71
  next,
82
72
  app: router,
83
- ..._chunk5YYZLGGNjs.argToReq.call(void 0, params, item.args, req.headers)
73
+ ..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, req.headers)
84
74
  };
85
- const context = new (0, _chunk5YYZLGGNjs.Context)(contextData);
86
- context.run(resolve, resolve);
75
+ const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
76
+ context.run({
77
+ globalGuards,
78
+ globalInterceptors,
79
+ globalFilter,
80
+ globalPipe
81
+ }, resolve, resolve);
87
82
  });
88
83
  })).then((ret) => {
89
84
  res.json(ret);
@@ -98,7 +93,7 @@ function bind(router, data, ServerOptions = {}) {
98
93
  const { data: { plugins: plugins2, http } } = meta2;
99
94
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
100
95
  continue;
101
- router[http.type](http.prefix + http.route, ..._chunk5YYZLGGNjs.Context.usePlugin(plugins2), async (req, res, next) => {
96
+ router[http.type](http.prefix + http.route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins2), async (req, res, next) => {
102
97
  debug(`invoke method "${func}" in module "${tag}"`);
103
98
  const contextData = {
104
99
  type: "express",
@@ -115,12 +110,17 @@ function bind(router, data, ServerOptions = {}) {
115
110
  app: router,
116
111
  next
117
112
  };
118
- const context = new (0, _chunk5YYZLGGNjs.Context)(contextData);
113
+ const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
119
114
  if (http.headers) {
120
115
  for (const name in http.headers)
121
116
  res.set(name, http.headers[name]);
122
117
  }
123
- await context.run((returnData) => {
118
+ await context.run({
119
+ globalGuards,
120
+ globalInterceptors,
121
+ globalFilter,
122
+ globalPipe
123
+ }, (returnData) => {
124
124
  if (res.writableEnded)
125
125
  return;
126
126
  if (typeof returnData === "string")
@@ -137,16 +137,16 @@ function bind(router, data, ServerOptions = {}) {
137
137
  }
138
138
  }
139
139
  _chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
140
- _chunk5YYZLGGNjs.detectAopDep.call(void 0, meta, {
140
+ _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
141
141
  plugins,
142
142
  guards: globalGuards,
143
143
  interceptors: globalInterceptors
144
144
  });
145
145
  handleMeta();
146
146
  createRoute();
147
- _chunk5YYZLGGNjs.HMR.call(void 0, async () => {
147
+ _chunkYERBWZCSjs.HMR.call(void 0, async () => {
148
148
  router.stack = originStack;
149
- _chunk5YYZLGGNjs.detectAopDep.call(void 0, meta, {
149
+ _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
150
150
  plugins,
151
151
  guards: globalGuards,
152
152
  interceptors: globalInterceptors
@@ -4,7 +4,7 @@ import {
4
4
  HMR,
5
5
  argToReq,
6
6
  detectAopDep
7
- } from "../../chunk-5VMFQOJ7.mjs";
7
+ } from "../../chunk-AB4OX3WV.mjs";
8
8
  import {
9
9
  __name
10
10
  } from "../../chunk-ITTD2GBR.mjs";
@@ -12,13 +12,11 @@ import {
12
12
  // src/server/express/bind.ts
13
13
  import Debug from "debug";
14
14
  var debug = Debug("phecda-server/express");
15
- function bind(router, data, ServerOptions = {}) {
16
- const { globalGuards, globalInterceptors, route, plugins } = {
15
+ function bind(router, data, opts = {}) {
16
+ const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
17
17
  route: "/__PHECDA_SERVER__",
18
- globalGuards: [],
19
- globalInterceptors: [],
20
18
  plugins: [],
21
- ...ServerOptions
19
+ ...opts
22
20
  };
23
21
  const { moduleMap, meta } = data;
24
22
  const originStack = router.stack.slice(0, router.stack.length);
@@ -30,14 +28,6 @@ function bind(router, data, ServerOptions = {}) {
30
28
  if (controller !== "http" || !http?.type)
31
29
  continue;
32
30
  debug(`register method "${func}" in module "${tag}"`);
33
- item.data.guards = [
34
- ...globalGuards,
35
- ...item.data.guards
36
- ];
37
- item.data.interceptors = [
38
- ...globalInterceptors,
39
- ...item.data.interceptors
40
- ];
41
31
  if (metaMap.has(tag))
42
32
  metaMap.get(tag)[func] = item;
43
33
  else
@@ -83,7 +73,12 @@ function bind(router, data, ServerOptions = {}) {
83
73
  ...argToReq(params, item.args, req.headers)
84
74
  };
85
75
  const context = new Context(contextData);
86
- context.run(resolve, resolve);
76
+ context.run({
77
+ globalGuards,
78
+ globalInterceptors,
79
+ globalFilter,
80
+ globalPipe
81
+ }, resolve, resolve);
87
82
  });
88
83
  })).then((ret) => {
89
84
  res.json(ret);
@@ -120,7 +115,12 @@ function bind(router, data, ServerOptions = {}) {
120
115
  for (const name in http.headers)
121
116
  res.set(name, http.headers[name]);
122
117
  }
123
- await context.run((returnData) => {
118
+ await context.run({
119
+ globalGuards,
120
+ globalInterceptors,
121
+ globalFilter,
122
+ globalPipe
123
+ }, (returnData) => {
124
124
  if (res.writableEnded)
125
125
  return;
126
126
  if (typeof returnData === "string")
@@ -1,8 +1,8 @@
1
1
  import { FastifyRequest, FastifyReply, FastifyInstance, FastifyPluginCallback, RouteShorthandOptions } from 'fastify';
2
- import { S as ServerOptions } from '../../helper-88b19c66.js';
3
- import { H as HttpContext, F as Factory } from '../../core-eb646fe5.js';
2
+ import { a as HttpContext, H as HttpOptions } from '../../helper-f29f082f.js';
3
+ import { F as Factory } from '../../core-fd134ffa.js';
4
+ import 'node:http';
4
5
  import 'phecda-core';
5
- import 'http';
6
6
 
7
7
  interface FastifyCtx extends HttpContext {
8
8
  type: 'fastify';
@@ -10,7 +10,7 @@ interface FastifyCtx extends HttpContext {
10
10
  response: FastifyReply;
11
11
  app: FastifyInstance;
12
12
  }
13
- declare function bind(data: Awaited<ReturnType<typeof Factory>>, ServerOptions?: ServerOptions): FastifyPluginCallback;
13
+ declare function bind(data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): FastifyPluginCallback;
14
14
  declare function Fastify(opts: RouteShorthandOptions): any;
15
15
 
16
16
  export { Fastify, FastifyCtx, bind };
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkVMXI3KFJjs = require('../../chunk-VMXI3KFJ.js');
3
+ var _chunkBXLBWRHSjs = require('../../chunk-BXLBWRHS.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
- var _chunk5YYZLGGNjs = require('../../chunk-5YYZLGGN.js');
10
+ var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
11
11
 
12
12
 
13
13
  var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
@@ -15,13 +15,11 @@ var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
15
15
  // src/server/fastify/bind.ts
16
16
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
17
17
  var debug = _debug2.default.call(void 0, "phecda-server/fastify");
18
- function bind(data, ServerOptions = {}) {
19
- const { globalGuards, globalInterceptors, route, plugins } = {
18
+ function bind(data, opts = {}) {
19
+ const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
20
20
  route: "/__PHECDA_SERVER__",
21
- globalGuards: [],
22
- globalInterceptors: [],
23
21
  plugins: [],
24
- ...ServerOptions
22
+ ...opts
25
23
  };
26
24
  const { moduleMap, meta } = data;
27
25
  const metaMap = /* @__PURE__ */ new Map();
@@ -32,14 +30,6 @@ function bind(data, ServerOptions = {}) {
32
30
  if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _2 => _2.type]))
33
31
  continue;
34
32
  debug(`register method "${func}" in module "${tag}"`);
35
- item.data.guards = [
36
- ...globalGuards,
37
- ...item.data.guards
38
- ];
39
- item.data.interceptors = [
40
- ...globalInterceptors,
41
- ...item.data.interceptors
42
- ];
43
33
  if (metaMap.has(tag))
44
34
  metaMap.get(tag)[func] = item;
45
35
  else
@@ -49,14 +39,14 @@ function bind(data, ServerOptions = {}) {
49
39
  }
50
40
  }
51
41
  _chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
52
- _chunk5YYZLGGNjs.detectAopDep.call(void 0, meta, {
42
+ _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
53
43
  plugins,
54
44
  guards: globalGuards,
55
45
  interceptors: globalInterceptors
56
46
  });
57
47
  handleMeta();
58
- _chunk5YYZLGGNjs.HMR.call(void 0, async () => {
59
- _chunk5YYZLGGNjs.detectAopDep.call(void 0, meta, {
48
+ _chunkYERBWZCSjs.HMR.call(void 0, async () => {
49
+ _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
60
50
  plugins,
61
51
  guards: globalGuards,
62
52
  interceptors: globalInterceptors
@@ -66,7 +56,7 @@ function bind(data, ServerOptions = {}) {
66
56
  return (fastify, _, done) => {
67
57
  fastify.register((fastify2, _opts, done2) => {
68
58
  plugins.forEach((p) => {
69
- const plugin = _chunk5YYZLGGNjs.Context.usePlugin([
59
+ const plugin = _chunkYERBWZCSjs.Context.usePlugin([
70
60
  p
71
61
  ])[0];
72
62
  if (plugin) {
@@ -77,22 +67,22 @@ function bind(data, ServerOptions = {}) {
77
67
  fastify2.post(route, async (req, res) => {
78
68
  const { body } = req;
79
69
  async function errorHandler(e) {
80
- const error = await _chunk5YYZLGGNjs.Context.filterRecord.default(e);
70
+ const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
81
71
  return res.status(error.status).send(error);
82
72
  }
83
73
  _chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
84
74
  if (!Array.isArray(body))
85
- return errorHandler(new (0, _chunk5YYZLGGNjs.BadRequestException)("data format should be an array"));
75
+ return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
86
76
  try {
87
77
  return Promise.all(body.map((item, i) => {
88
78
  return new Promise(async (resolve) => {
89
79
  const { tag, func } = item;
90
80
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
91
81
  if (!metaMap.has(tag))
92
- return resolve(await _chunk5YYZLGGNjs.Context.filterRecord.default(new (0, _chunk5YYZLGGNjs.BadRequestException)(`module "${tag}" doesn't exist`)));
82
+ return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
93
83
  const meta2 = metaMap.get(tag)[func];
94
84
  if (!meta2)
95
- return resolve(await _chunk5YYZLGGNjs.Context.filterRecord.default(new (0, _chunk5YYZLGGNjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
85
+ return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
96
86
  const { data: { params } } = meta2;
97
87
  const contextData = {
98
88
  type: "fastify",
@@ -105,10 +95,15 @@ function bind(data, ServerOptions = {}) {
105
95
  tag,
106
96
  func,
107
97
  app: fastify2,
108
- ..._chunk5YYZLGGNjs.argToReq.call(void 0, params, item.args, req.headers)
98
+ ..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, req.headers)
109
99
  };
110
- const context = new (0, _chunk5YYZLGGNjs.Context)(contextData);
111
- context.run(resolve, resolve);
100
+ const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
101
+ context.run({
102
+ globalGuards,
103
+ globalInterceptors,
104
+ globalFilter,
105
+ globalPipe
106
+ }, resolve, resolve);
112
107
  });
113
108
  })).then((ret) => {
114
109
  res.send(ret);
@@ -126,7 +121,7 @@ function bind(data, ServerOptions = {}) {
126
121
  if (!_optionalChain([http, 'optionalAccess', _3 => _3.type]))
127
122
  continue;
128
123
  fastify.register((fastify2, _opts, done2) => {
129
- _chunk5YYZLGGNjs.Context.usePlugin(plugins2).forEach((p) => {
124
+ _chunkYERBWZCSjs.Context.usePlugin(plugins2).forEach((p) => {
130
125
  p[Symbol.for("skip-override")] = true;
131
126
  fastify2.register(p);
132
127
  });
@@ -146,12 +141,17 @@ function bind(data, ServerOptions = {}) {
146
141
  headers: req.headers,
147
142
  app: fastify2
148
143
  };
149
- const context = new (0, _chunk5YYZLGGNjs.Context)(contextData);
144
+ const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
150
145
  if (http.headers) {
151
146
  for (const name in http.headers)
152
147
  res.header(name, http.headers[name]);
153
148
  }
154
- return context.run((returnData) => {
149
+ return context.run({
150
+ globalGuards,
151
+ globalInterceptors,
152
+ globalFilter,
153
+ globalPipe
154
+ }, (returnData) => {
155
155
  if (res.sent)
156
156
  return;
157
157
  return returnData;
@@ -170,7 +170,7 @@ function bind(data, ServerOptions = {}) {
170
170
  }
171
171
  _chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
172
172
  function Fastify(opts) {
173
- return _chunkVMXI3KFJjs.Define.call(void 0, "fastify", opts);
173
+ return _chunkBXLBWRHSjs.Define.call(void 0, "fastify", opts);
174
174
  }
175
175
  _chunkYR5Q5F2Kjs.__name.call(void 0, Fastify, "Fastify");
176
176