phecda-server 5.0.0-alpha.11 → 5.0.0-alpha.13

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 (37) hide show
  1. package/dist/{chunk-JJG37LHY.mjs → chunk-BADPI5WG.mjs} +25 -21
  2. package/dist/{chunk-KGMDCF26.mjs → chunk-DJO45NRZ.mjs} +6 -2
  3. package/dist/{chunk-C36XJ7D3.js → chunk-GWLM5DEJ.js} +7 -3
  4. package/dist/{chunk-MZBE4NIO.mjs → chunk-HQ5RLYMA.mjs} +1 -1
  5. package/dist/{chunk-ANH53I6B.js → chunk-INPMEA67.js} +33 -37
  6. package/dist/{chunk-P5LJBZPN.js → chunk-MFCPWVO5.js} +65 -61
  7. package/dist/{chunk-2AI7ID6X.js → chunk-SSZS3GSQ.js} +2 -2
  8. package/dist/{chunk-KKTRNKCF.mjs → chunk-Y7AOZMC2.mjs} +15 -19
  9. package/dist/{core-39d78b79.d.ts → core-11dd822c.d.ts} +8 -5
  10. package/dist/index.d.ts +26 -25
  11. package/dist/index.js +77 -62
  12. package/dist/index.mjs +32 -17
  13. package/dist/rpc/kafka/index.d.ts +1 -1
  14. package/dist/rpc/kafka/index.js +9 -9
  15. package/dist/rpc/kafka/index.mjs +3 -3
  16. package/dist/rpc/rabbitmq/index.d.ts +1 -1
  17. package/dist/rpc/rabbitmq/index.js +9 -9
  18. package/dist/rpc/rabbitmq/index.mjs +3 -3
  19. package/dist/rpc/redis/index.d.ts +1 -1
  20. package/dist/rpc/redis/index.js +9 -9
  21. package/dist/rpc/redis/index.mjs +3 -3
  22. package/dist/server/express/index.d.ts +1 -1
  23. package/dist/server/express/index.js +24 -24
  24. package/dist/server/express/index.mjs +4 -4
  25. package/dist/server/fastify/index.d.ts +1 -1
  26. package/dist/server/fastify/index.js +22 -22
  27. package/dist/server/fastify/index.mjs +4 -4
  28. package/dist/server/h3/index.d.ts +1 -1
  29. package/dist/server/h3/index.js +21 -21
  30. package/dist/server/h3/index.mjs +4 -4
  31. package/dist/server/koa/index.d.ts +1 -1
  32. package/dist/server/koa/index.js +24 -24
  33. package/dist/server/koa/index.mjs +4 -4
  34. package/dist/test.d.ts +5 -4
  35. package/dist/test.js +45 -43
  36. package/dist/test.mjs +42 -40
  37. package/package.json +2 -2
@@ -1,18 +1,18 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunk2AI7ID6Xjs = require('../../chunk-2AI7ID6X.js');
3
+ var _chunkSSZS3GSQjs = require('../../chunk-SSZS3GSQ.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunkP5LJBZPNjs = require('../../chunk-P5LJBZPN.js');
8
+ var _chunkMFCPWVO5js = require('../../chunk-MFCPWVO5.js');
9
9
 
10
10
 
11
11
 
12
12
 
13
13
 
14
14
 
15
- var _chunkC36XJ7D3js = require('../../chunk-C36XJ7D3.js');
15
+ var _chunkGWLM5DEJjs = require('../../chunk-GWLM5DEJ.js');
16
16
 
17
17
  // src/server/h3/bind.ts
18
18
  var _h3 = require('h3');
@@ -24,18 +24,18 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
24
24
  plugins: [],
25
25
  ...options
26
26
  };
27
- _chunkP5LJBZPNjs.isAopDepInject.call(void 0, meta, {
27
+ _chunkGWLM5DEJjs.IS_DEV && _chunkMFCPWVO5js.isAopDepInject.call(void 0, meta, {
28
28
  plugins,
29
29
  guards: globalGuards,
30
30
  interceptors: globalInterceptors
31
31
  });
32
- router[_chunkC36XJ7D3js.APP_SYMBOL] = {
32
+ router[_chunkGWLM5DEJjs.APP_SYMBOL] = {
33
33
  moduleMap,
34
34
  meta
35
35
  };
36
36
  const prePlugin = _h3.defineRequestMiddleware.call(void 0, (event) => {
37
- event[_chunkC36XJ7D3js.MODULE_SYMBOL] = moduleMap;
38
- event[_chunkC36XJ7D3js.META_SYMBOL] = meta;
37
+ event[_chunkGWLM5DEJjs.MODULE_SYMBOL] = moduleMap;
38
+ event[_chunkGWLM5DEJjs.META_SYMBOL] = meta;
39
39
  });
40
40
  const metaMap = /* @__PURE__ */ new Map();
41
41
  function handleMeta() {
@@ -48,32 +48,32 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
48
48
  metaMap.set(methodTag, item);
49
49
  }
50
50
  }
51
- _chunkC36XJ7D3js.__name.call(void 0, handleMeta, "handleMeta");
51
+ _chunkGWLM5DEJjs.__name.call(void 0, handleMeta, "handleMeta");
52
52
  async function createRoute() {
53
53
  router.post(route, _h3.eventHandler.call(void 0, {
54
54
  onRequest: [
55
55
  prePlugin,
56
- ..._chunkP5LJBZPNjs.Context.usePlugin(plugins).map((p) => _h3.defineRequestMiddleware.call(void 0, p))
56
+ ..._chunkMFCPWVO5js.Context.usePlugin(plugins).map((p) => _h3.defineRequestMiddleware.call(void 0, p))
57
57
  ],
58
58
  handler: async (event) => {
59
59
  const body = await _h3.readBody.call(void 0, event, {
60
60
  strict: true
61
61
  });
62
62
  async function errorHandler(e) {
63
- const error = await _chunkP5LJBZPNjs.Context.filterRecord.default(e);
63
+ const error = await _chunkMFCPWVO5js.Context.filterRecord.default(e);
64
64
  _h3.setResponseStatus.call(void 0, event, error.status);
65
65
  return error;
66
66
  }
67
- _chunkC36XJ7D3js.__name.call(void 0, errorHandler, "errorHandler");
67
+ _chunkGWLM5DEJjs.__name.call(void 0, errorHandler, "errorHandler");
68
68
  if (!Array.isArray(body))
69
- return errorHandler(new (0, _chunkP5LJBZPNjs.BadRequestException)("data format should be an array"));
69
+ return errorHandler(new (0, _chunkMFCPWVO5js.BadRequestException)("data format should be an array"));
70
70
  try {
71
71
  return Promise.all(body.map((item) => {
72
72
  return new Promise(async (resolve) => {
73
73
  const { tag } = item;
74
74
  const meta2 = metaMap.get(tag);
75
75
  if (!meta2)
76
- return resolve(await _chunkP5LJBZPNjs.Context.filterRecord.default(new (0, _chunkP5LJBZPNjs.BadRequestException)(`"${tag}" doesn't exist`)));
76
+ return resolve(await _chunkMFCPWVO5js.Context.filterRecord.default(new (0, _chunkMFCPWVO5js.BadRequestException)(`"${tag}" doesn't exist`)));
77
77
  const contextData = {
78
78
  type: "h3",
79
79
  event,
@@ -82,7 +82,7 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
82
82
  parallel: true,
83
83
  tag
84
84
  };
85
- const context = new (0, _chunkP5LJBZPNjs.Context)(contextData);
85
+ const context = new (0, _chunkMFCPWVO5js.Context)(contextData);
86
86
  const [name, method] = tag.split("-");
87
87
  const { paramsType, handlers, data: { params, guards, interceptors, filter } } = metaMap.get(tag);
88
88
  const instance = moduleMap.get(name);
@@ -131,7 +131,7 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
131
131
  router[http.type](http.route, _h3.eventHandler.call(void 0, {
132
132
  onRequest: [
133
133
  prePlugin,
134
- ..._chunkP5LJBZPNjs.Context.usePlugin(plugins2).map((p) => _h3.defineRequestMiddleware.call(void 0, p))
134
+ ..._chunkMFCPWVO5js.Context.usePlugin(plugins2).map((p) => _h3.defineRequestMiddleware.call(void 0, p))
135
135
  ],
136
136
  handler: async (event) => {
137
137
  const instance = moduleMap.get(tag);
@@ -143,7 +143,7 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
143
143
  parallel: false,
144
144
  tag: methodTag
145
145
  };
146
- const context = new (0, _chunkP5LJBZPNjs.Context)(contextData);
146
+ const context = new (0, _chunkMFCPWVO5js.Context)(contextData);
147
147
  try {
148
148
  _h3.setHeaders.call(void 0, event, header);
149
149
  await context.useGuard([
@@ -175,7 +175,7 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
175
175
  arg = body;
176
176
  }
177
177
  return {
178
- arg: _chunk2AI7ID6Xjs.resolveDep.call(void 0, arg, key),
178
+ arg: _chunkSSZS3GSQjs.resolveDep.call(void 0, arg, key),
179
179
  pipe,
180
180
  pipeOpts,
181
181
  key,
@@ -198,12 +198,12 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
198
198
  }));
199
199
  }
200
200
  }
201
- _chunkC36XJ7D3js.__name.call(void 0, createRoute, "createRoute");
201
+ _chunkGWLM5DEJjs.__name.call(void 0, createRoute, "createRoute");
202
202
  handleMeta();
203
203
  createRoute();
204
- if (_chunkC36XJ7D3js.IS_DEV) {
204
+ if (_chunkGWLM5DEJjs.IS_DEV) {
205
205
  _optionalChain([globalThis, 'access', _7 => _7.__PS_HMR__, 'optionalAccess', _8 => _8.push, 'call', _9 => _9(async () => {
206
- _chunkP5LJBZPNjs.isAopDepInject.call(void 0, meta, {
206
+ _chunkMFCPWVO5js.isAopDepInject.call(void 0, meta, {
207
207
  plugins,
208
208
  guards: globalGuards,
209
209
  interceptors: globalInterceptors
@@ -212,7 +212,7 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
212
212
  })]);
213
213
  }
214
214
  }
215
- _chunkC36XJ7D3js.__name.call(void 0, bindApp, "bindApp");
215
+ _chunkGWLM5DEJjs.__name.call(void 0, bindApp, "bindApp");
216
216
 
217
217
 
218
218
  exports.bindApp = bindApp;
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  resolveDep
3
- } from "../../chunk-MZBE4NIO.mjs";
3
+ } from "../../chunk-HQ5RLYMA.mjs";
4
4
  import {
5
5
  BadRequestException,
6
6
  Context,
7
7
  isAopDepInject
8
- } from "../../chunk-JJG37LHY.mjs";
8
+ } from "../../chunk-BADPI5WG.mjs";
9
9
  import {
10
10
  APP_SYMBOL,
11
11
  IS_DEV,
12
12
  META_SYMBOL,
13
13
  MODULE_SYMBOL,
14
14
  __name
15
- } from "../../chunk-KGMDCF26.mjs";
15
+ } from "../../chunk-DJO45NRZ.mjs";
16
16
 
17
17
  // src/server/h3/bind.ts
18
18
  import { defineRequestMiddleware, eventHandler, getQuery, getRequestHeaders, getRouterParams, readBody, setHeaders, setResponseStatus } from "h3";
@@ -24,7 +24,7 @@ function bindApp(router, { moduleMap, meta }, options = {}) {
24
24
  plugins: [],
25
25
  ...options
26
26
  };
27
- isAopDepInject(meta, {
27
+ IS_DEV && isAopDepInject(meta, {
28
28
  plugins,
29
29
  guards: globalGuards,
30
30
  interceptors: globalInterceptors
@@ -1,6 +1,6 @@
1
1
  import Router, { RouterParamContext } from '@koa/router';
2
2
  import { DefaultContext, DefaultState } from 'koa';
3
- import { P, F as Factory } from '../../core-39d78b79.js';
3
+ import { P, F as Factory } from '../../core-11dd822c.js';
4
4
  import 'phecda-core';
5
5
 
6
6
  interface KoaCtx extends P.BaseContext {
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunk2AI7ID6Xjs = require('../../chunk-2AI7ID6X.js');
3
+ var _chunkSSZS3GSQjs = require('../../chunk-SSZS3GSQ.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunkP5LJBZPNjs = require('../../chunk-P5LJBZPN.js');
8
+ var _chunkMFCPWVO5js = require('../../chunk-MFCPWVO5.js');
9
9
 
10
10
 
11
11
 
@@ -13,7 +13,7 @@ var _chunkP5LJBZPNjs = require('../../chunk-P5LJBZPN.js');
13
13
 
14
14
 
15
15
 
16
- var _chunkC36XJ7D3js = require('../../chunk-C36XJ7D3.js');
16
+ var _chunkGWLM5DEJjs = require('../../chunk-GWLM5DEJ.js');
17
17
 
18
18
  // src/server/koa/bind.ts
19
19
  function bindApp(app, { moduleMap, meta }, options = {}) {
@@ -24,12 +24,12 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
24
24
  plugins: [],
25
25
  ...options
26
26
  };
27
- _chunkP5LJBZPNjs.isAopDepInject.call(void 0, meta, {
27
+ _chunkGWLM5DEJjs.IS_DEV && _chunkMFCPWVO5js.isAopDepInject.call(void 0, meta, {
28
28
  plugins,
29
29
  guards: globalGuards,
30
30
  interceptors: globalInterceptors
31
31
  });
32
- app[_chunkC36XJ7D3js.APP_SYMBOL] = {
32
+ app[_chunkGWLM5DEJjs.APP_SYMBOL] = {
33
33
  moduleMap,
34
34
  meta
35
35
  };
@@ -44,30 +44,30 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
44
44
  metaMap.set(methodTag, item);
45
45
  }
46
46
  }
47
- _chunkC36XJ7D3js.__name.call(void 0, handleMeta, "handleMeta");
47
+ _chunkGWLM5DEJjs.__name.call(void 0, handleMeta, "handleMeta");
48
48
  async function createRoute() {
49
49
  app.post(route, async (ctx, next) => {
50
- ctx[_chunkC36XJ7D3js.MERGE_SYMBOL] = true;
51
- ctx[_chunkC36XJ7D3js.MODULE_SYMBOL] = moduleMap;
52
- ctx[_chunkC36XJ7D3js.META_SYMBOL] = meta;
50
+ ctx[_chunkGWLM5DEJjs.MERGE_SYMBOL] = true;
51
+ ctx[_chunkGWLM5DEJjs.MODULE_SYMBOL] = moduleMap;
52
+ ctx[_chunkGWLM5DEJjs.META_SYMBOL] = meta;
53
53
  await next();
54
- }, ..._chunkP5LJBZPNjs.Context.usePlugin(plugins), async (ctx) => {
54
+ }, ..._chunkMFCPWVO5js.Context.usePlugin(plugins), async (ctx) => {
55
55
  const { body } = ctx.request;
56
56
  async function errorHandler(e) {
57
- const error = await _chunkP5LJBZPNjs.Context.filterRecord.default(e);
57
+ const error = await _chunkMFCPWVO5js.Context.filterRecord.default(e);
58
58
  ctx.status = error.status;
59
59
  ctx.body = error;
60
60
  }
61
- _chunkC36XJ7D3js.__name.call(void 0, errorHandler, "errorHandler");
61
+ _chunkGWLM5DEJjs.__name.call(void 0, errorHandler, "errorHandler");
62
62
  if (!Array.isArray(body))
63
- return errorHandler(new (0, _chunkP5LJBZPNjs.BadRequestException)("data format should be an array"));
63
+ return errorHandler(new (0, _chunkMFCPWVO5js.BadRequestException)("data format should be an array"));
64
64
  try {
65
65
  return Promise.all(body.map((item) => {
66
66
  return new Promise(async (resolve) => {
67
67
  const { tag } = item;
68
68
  const meta2 = metaMap.get(tag);
69
69
  if (!meta2)
70
- return resolve(await _chunkP5LJBZPNjs.Context.filterRecord.default(new (0, _chunkP5LJBZPNjs.BadRequestException)(`"${tag}" doesn't exist`)));
70
+ return resolve(await _chunkMFCPWVO5js.Context.filterRecord.default(new (0, _chunkMFCPWVO5js.BadRequestException)(`"${tag}" doesn't exist`)));
71
71
  const contextData = {
72
72
  type: "koa",
73
73
  ctx,
@@ -76,7 +76,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
76
76
  parallel: true,
77
77
  tag
78
78
  };
79
- const context = new (0, _chunkP5LJBZPNjs.Context)(contextData);
79
+ const context = new (0, _chunkMFCPWVO5js.Context)(contextData);
80
80
  const [name, method] = tag.split("-");
81
81
  const { paramsType, handlers, data: { params, guards, interceptors, filter } } = meta2;
82
82
  const instance = moduleMap.get(name);
@@ -124,10 +124,10 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
124
124
  const methodTag = `${tag}-${method}`;
125
125
  const { paramsType, handlers, data: { interceptors, guards, params, plugins: plugins2, filter } } = metaMap.get(methodTag);
126
126
  app[http.type](http.route, async (ctx, next) => {
127
- ctx[_chunkC36XJ7D3js.MODULE_SYMBOL] = moduleMap;
128
- ctx[_chunkC36XJ7D3js.META_SYMBOL] = meta;
127
+ ctx[_chunkGWLM5DEJjs.MODULE_SYMBOL] = moduleMap;
128
+ ctx[_chunkGWLM5DEJjs.META_SYMBOL] = meta;
129
129
  await next();
130
- }, ..._chunkP5LJBZPNjs.Context.usePlugin(plugins2), async (ctx) => {
130
+ }, ..._chunkMFCPWVO5js.Context.usePlugin(plugins2), async (ctx) => {
131
131
  const instance = moduleMap.get(tag);
132
132
  const contextData = {
133
133
  type: "koa",
@@ -137,7 +137,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
137
137
  parallel: false,
138
138
  tag: methodTag
139
139
  };
140
- const context = new (0, _chunkP5LJBZPNjs.Context)(contextData);
140
+ const context = new (0, _chunkMFCPWVO5js.Context)(contextData);
141
141
  try {
142
142
  for (const name in header)
143
143
  ctx.set(name, header[name]);
@@ -155,7 +155,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
155
155
  }
156
156
  const args = await context.usePipe(params.map(({ type, key, pipeOpts, index, pipe }) => {
157
157
  return {
158
- arg: _chunk2AI7ID6Xjs.resolveDep.call(void 0, ctx.request[type], key),
158
+ arg: _chunkSSZS3GSQjs.resolveDep.call(void 0, ctx.request[type], key),
159
159
  pipeOpts,
160
160
  pipe,
161
161
  key,
@@ -181,12 +181,12 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
181
181
  });
182
182
  }
183
183
  }
184
- _chunkC36XJ7D3js.__name.call(void 0, createRoute, "createRoute");
184
+ _chunkGWLM5DEJjs.__name.call(void 0, createRoute, "createRoute");
185
185
  handleMeta();
186
186
  createRoute();
187
- if (_chunkC36XJ7D3js.IS_DEV) {
187
+ if (_chunkGWLM5DEJjs.IS_DEV) {
188
188
  _optionalChain([globalThis, 'access', _7 => _7.__PS_HMR__, 'optionalAccess', _8 => _8.push, 'call', _9 => _9(async () => {
189
- _chunkP5LJBZPNjs.isAopDepInject.call(void 0, meta, {
189
+ _chunkMFCPWVO5js.isAopDepInject.call(void 0, meta, {
190
190
  plugins,
191
191
  guards: globalGuards,
192
192
  interceptors: globalInterceptors
@@ -197,7 +197,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
197
197
  })]);
198
198
  }
199
199
  }
200
- _chunkC36XJ7D3js.__name.call(void 0, bindApp, "bindApp");
200
+ _chunkGWLM5DEJjs.__name.call(void 0, bindApp, "bindApp");
201
201
 
202
202
 
203
203
  exports.bindApp = bindApp;
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  resolveDep
3
- } from "../../chunk-MZBE4NIO.mjs";
3
+ } from "../../chunk-HQ5RLYMA.mjs";
4
4
  import {
5
5
  BadRequestException,
6
6
  Context,
7
7
  isAopDepInject
8
- } from "../../chunk-JJG37LHY.mjs";
8
+ } from "../../chunk-BADPI5WG.mjs";
9
9
  import {
10
10
  APP_SYMBOL,
11
11
  IS_DEV,
@@ -13,7 +13,7 @@ import {
13
13
  META_SYMBOL,
14
14
  MODULE_SYMBOL,
15
15
  __name
16
- } from "../../chunk-KGMDCF26.mjs";
16
+ } from "../../chunk-DJO45NRZ.mjs";
17
17
 
18
18
  // src/server/koa/bind.ts
19
19
  function bindApp(app, { moduleMap, meta }, options = {}) {
@@ -24,7 +24,7 @@ function bindApp(app, { moduleMap, meta }, options = {}) {
24
24
  plugins: [],
25
25
  ...options
26
26
  };
27
- isAopDepInject(meta, {
27
+ IS_DEV && isAopDepInject(meta, {
28
28
  plugins,
29
29
  guards: globalGuards,
30
30
  interceptors: globalInterceptors
package/dist/test.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { Server } from 'node:http';
1
+ import * as supertest from 'supertest';
2
2
  import { Test } from 'supertest';
3
+ import { Server } from 'node:http';
3
4
  import { Construct } from 'phecda-core';
4
- import { F as Factory, c as PickFunc } from './core-39d78b79.js';
5
+ import { F as Factory, c as PickFunc } from './core-11dd822c.js';
5
6
 
6
7
  declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
7
8
  get<C extends T[number]>(Module: C): InstanceType<C>;
@@ -9,8 +10,8 @@ declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
9
10
  type SuperTestRequest<T> = {
10
11
  [K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
11
12
  };
12
- declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>): Promise<{
13
- get<T extends Construct>(Module: T): SuperTestRequest<PickFunc<InstanceType<T>>>;
13
+ declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "key" | "query" | "use" | "on" | "set" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
14
+ module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
14
15
  }>;
15
16
 
16
17
  export { SuperTestRequest, TestFactory, TestHttp };
package/dist/test.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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 _chunkANH53I6Bjs = require('./chunk-ANH53I6B.js');
3
+ var _chunkINPMEA67js = require('./chunk-INPMEA67.js');
4
4
 
5
5
 
6
- var _chunkC36XJ7D3js = require('./chunk-C36XJ7D3.js');
6
+ var _chunkGWLM5DEJjs = require('./chunk-GWLM5DEJ.js');
7
7
 
8
8
  // src/test.ts
9
9
  async function TestFactory(...Modules) {
10
- const { moduleMap, constructorMap } = await _chunkANH53I6Bjs.Factory.call(void 0, Modules);
10
+ const { moduleMap, constructorMap } = await _chunkINPMEA67js.Factory.call(void 0, Modules);
11
11
  return {
12
12
  get(Module) {
13
13
  const tag = _optionalChain([Module, 'access', _ => _.prototype, 'optionalAccess', _2 => _2.__TAG__]) || Module.name;
@@ -20,48 +20,50 @@ async function TestFactory(...Modules) {
20
20
  }
21
21
  };
22
22
  }
23
- _chunkC36XJ7D3js.__name.call(void 0, TestFactory, "TestFactory");
24
- async function TestHttp(app, { moduleMap, meta }) {
25
- const { default: request } = await Promise.resolve().then(() => require("supertest"));
26
- return {
27
- get(Module) {
28
- const tag = _optionalChain([Module, 'access', _3 => _3.prototype, 'optionalAccess', _4 => _4.__TAG__]) || Module.name;
29
- const instance = moduleMap.get(tag);
30
- if (!instance)
31
- throw new Error(`module "${tag}" doesn't exist`);
32
- return new Proxy({}, {
33
- get(_target, p) {
34
- const { data } = meta.find(({ data: data2 }) => data2.name === Module.name && data2.method === p && data2.tag === tag);
35
- return (...args) => {
36
- const ret = {
37
- body: {},
38
- headers: {},
39
- query: {},
40
- method: data.http.type,
41
- url: data.http.route
42
- };
43
- data.params.forEach((item) => {
44
- if (item.type === "params") {
45
- ret.url = ret.url.replace(`:${item.key}`, args[item.index]);
46
- return;
47
- }
48
- if (item.type === "query") {
49
- ret.query[item.key] = args[item.index];
50
- return;
51
- }
52
- if (item.key)
53
- ret[item.type][item.key] = args[item.index];
54
- else
55
- ret[item.type] = args[item.index];
56
- });
57
- return request(app)[ret.method](ret.url).query(ret.query).set(ret.headers).send(ret.body);
23
+ _chunkGWLM5DEJjs.__name.call(void 0, TestFactory, "TestFactory");
24
+ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
25
+ const { default: request, agent } = await Promise.resolve().then(() => require("supertest"));
26
+ const Agent = agent(app);
27
+ function module(Module) {
28
+ const tag = _optionalChain([Module, 'access', _3 => _3.prototype, 'optionalAccess', _4 => _4.__TAG__]) || Module.name;
29
+ const instance = moduleMap.get(tag);
30
+ if (!instance)
31
+ throw new Error(`module "${tag}" doesn't exist`);
32
+ return new Proxy({}, {
33
+ get(_target, p) {
34
+ const { data } = meta.find(({ data: data2 }) => data2.name === Module.name && data2.method === p && data2.tag === tag);
35
+ return (...args) => {
36
+ const ret = {
37
+ body: {},
38
+ headers: {},
39
+ query: {},
40
+ method: data.http.type,
41
+ url: data.http.route
58
42
  };
59
- }
60
- });
61
- }
62
- };
43
+ data.params.forEach((item) => {
44
+ if (item.type === "params") {
45
+ ret.url = ret.url.replace(`:${item.key}`, args[item.index]);
46
+ return;
47
+ }
48
+ if (item.type === "query") {
49
+ ret.query[item.key] = args[item.index];
50
+ return;
51
+ }
52
+ if (item.key)
53
+ ret[item.type][item.key] = args[item.index];
54
+ else
55
+ ret[item.type] = args[item.index];
56
+ });
57
+ return (isAgent ? Agent : request(app))[ret.method](ret.url).query(ret.query).set(ret.headers).send(ret.body);
58
+ };
59
+ }
60
+ });
61
+ }
62
+ _chunkGWLM5DEJjs.__name.call(void 0, module, "module");
63
+ Agent.module = module;
64
+ return Agent;
63
65
  }
64
- _chunkC36XJ7D3js.__name.call(void 0, TestHttp, "TestHttp");
66
+ _chunkGWLM5DEJjs.__name.call(void 0, TestHttp, "TestHttp");
65
67
 
66
68
 
67
69
 
package/dist/test.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Factory
3
- } from "./chunk-KKTRNKCF.mjs";
3
+ } from "./chunk-Y7AOZMC2.mjs";
4
4
  import {
5
5
  __name
6
- } from "./chunk-KGMDCF26.mjs";
6
+ } from "./chunk-DJO45NRZ.mjs";
7
7
 
8
8
  // src/test.ts
9
9
  async function TestFactory(...Modules) {
@@ -21,45 +21,47 @@ async function TestFactory(...Modules) {
21
21
  };
22
22
  }
23
23
  __name(TestFactory, "TestFactory");
24
- async function TestHttp(app, { moduleMap, meta }) {
25
- const { default: request } = await import("supertest");
26
- return {
27
- get(Module) {
28
- const tag = Module.prototype?.__TAG__ || Module.name;
29
- const instance = moduleMap.get(tag);
30
- if (!instance)
31
- throw new Error(`module "${tag}" doesn't exist`);
32
- return new Proxy({}, {
33
- get(_target, p) {
34
- const { data } = meta.find(({ data: data2 }) => data2.name === Module.name && data2.method === p && data2.tag === tag);
35
- return (...args) => {
36
- const ret = {
37
- body: {},
38
- headers: {},
39
- query: {},
40
- method: data.http.type,
41
- url: data.http.route
42
- };
43
- data.params.forEach((item) => {
44
- if (item.type === "params") {
45
- ret.url = ret.url.replace(`:${item.key}`, args[item.index]);
46
- return;
47
- }
48
- if (item.type === "query") {
49
- ret.query[item.key] = args[item.index];
50
- return;
51
- }
52
- if (item.key)
53
- ret[item.type][item.key] = args[item.index];
54
- else
55
- ret[item.type] = args[item.index];
56
- });
57
- return request(app)[ret.method](ret.url).query(ret.query).set(ret.headers).send(ret.body);
24
+ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
25
+ const { default: request, agent } = await import("supertest");
26
+ const Agent = agent(app);
27
+ function module(Module) {
28
+ const tag = Module.prototype?.__TAG__ || Module.name;
29
+ const instance = moduleMap.get(tag);
30
+ if (!instance)
31
+ throw new Error(`module "${tag}" doesn't exist`);
32
+ return new Proxy({}, {
33
+ get(_target, p) {
34
+ const { data } = meta.find(({ data: data2 }) => data2.name === Module.name && data2.method === p && data2.tag === tag);
35
+ return (...args) => {
36
+ const ret = {
37
+ body: {},
38
+ headers: {},
39
+ query: {},
40
+ method: data.http.type,
41
+ url: data.http.route
58
42
  };
59
- }
60
- });
61
- }
62
- };
43
+ data.params.forEach((item) => {
44
+ if (item.type === "params") {
45
+ ret.url = ret.url.replace(`:${item.key}`, args[item.index]);
46
+ return;
47
+ }
48
+ if (item.type === "query") {
49
+ ret.query[item.key] = args[item.index];
50
+ return;
51
+ }
52
+ if (item.key)
53
+ ret[item.type][item.key] = args[item.index];
54
+ else
55
+ ret[item.type] = args[item.index];
56
+ });
57
+ return (isAgent ? Agent : request(app))[ret.method](ret.url).query(ret.query).set(ret.headers).send(ret.body);
58
+ };
59
+ }
60
+ });
61
+ }
62
+ __name(module, "module");
63
+ Agent.module = module;
64
+ return Agent;
63
65
  }
64
66
  __name(TestHttp, "TestHttp");
65
67
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "5.0.0-alpha.11",
3
+ "version": "5.0.0-alpha.13",
4
4
  "description": "provide express middlewares, `nestjs` format",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -121,7 +121,7 @@
121
121
  "debug": "^4.3.4",
122
122
  "picocolors": "^1.0.0",
123
123
  "reflect-metadata": "^0.1.13",
124
- "phecda-core": "3.0.0-alpha.5"
124
+ "phecda-core": "3.0.0-alpha.7"
125
125
  },
126
126
  "scripts": {
127
127
  "dev": "tsup --watch",