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
@@ -4,95 +4,95 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
8
7
 
8
+ var _chunkFSBD5R22js = require('../../chunk-FSBD5R22.js');
9
9
 
10
- var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
10
+
11
+ var _chunkZP7HNASUjs = require('../../chunk-ZP7HNASU.js');
11
12
 
12
13
  // src/server/koa/bind.ts
13
14
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
14
15
  var debug = _debug2.default.call(void 0, "phecda-server/koa");
15
- function bind(router, { moduleMap, meta }, opts = {}) {
16
- const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
17
- route: "/__PHECDA_SERVER__",
18
- plugins: [],
19
- ...opts
20
- };
16
+ function bind(router, data, opts = {}) {
17
+ const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
18
+ const { moduleMap, meta } = data;
21
19
  const originStack = router.stack.slice(0, router.stack.length);
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" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
28
- continue;
20
+ const metaMap = _chunkFSBD5R22js.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
+ const { controller, http, func, tag } = meta2.data;
22
+ if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
29
23
  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
- });
24
+ return true;
36
25
  }
37
- }
38
- _chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
39
- async function createRoute() {
40
- router.post(route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins), async (ctx, next) => {
41
- const { body } = ctx.request;
42
- async function errorHandler(e) {
43
- const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
44
- ctx.status = error.status;
45
- ctx.body = error;
46
- }
47
- _chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
48
- if (!Array.isArray(body))
49
- return errorHandler(new (0, _chunkYERBWZCSjs.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 _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
57
- const meta2 = metaMap.get(tag)[func];
58
- if (!meta2)
59
- return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
60
- const { data: { params } } = meta2;
61
- const contextData = {
62
- type: "koa",
63
- index: i,
64
- ctx,
65
- meta: meta2,
66
- moduleMap,
67
- parallel: true,
68
- next,
69
- app: router,
70
- ..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, ctx.headers),
71
- tag,
72
- func
73
- };
74
- const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
75
- context.run({
76
- globalGuards,
77
- globalInterceptors,
78
- globalFilter,
79
- globalPipe
80
- }, resolve, resolve);
26
+ });
27
+ _chunkFSBD5R22js.detectAopDep.call(void 0, meta, {
28
+ plugins: [
29
+ ...globalPlugins,
30
+ ...parallelPlugins
31
+ ],
32
+ guards: globalGuards,
33
+ interceptors: globalInterceptors
34
+ });
35
+ registerRoute();
36
+ async function registerRoute() {
37
+ _chunkFSBD5R22js.Context.usePlugin(globalPlugins, "koa").forEach((p) => router.use(p));
38
+ if (parallelRoute) {
39
+ router.post(parallelRoute, ..._chunkFSBD5R22js.Context.usePlugin(parallelPlugins, "koa"), async (ctx, next) => {
40
+ const { body } = ctx.request;
41
+ async function errorHandler(e) {
42
+ const error = await _chunkFSBD5R22js.Context.filterRecord.default(e);
43
+ ctx.status = error.status;
44
+ ctx.body = error;
45
+ }
46
+ _chunkZP7HNASUjs.__name.call(void 0, errorHandler, "errorHandler");
47
+ if (!Array.isArray(body))
48
+ return errorHandler(new (0, _chunkFSBD5R22js.BadRequestException)("data format should be an array"));
49
+ try {
50
+ return Promise.all(body.map((item, i) => {
51
+ return new Promise(async (resolve) => {
52
+ const { tag, func } = item;
53
+ debug(`(parallel)invoke method "${func}" in module "${tag}"`);
54
+ if (!metaMap.has(tag))
55
+ return resolve(await _chunkFSBD5R22js.Context.filterRecord.default(new (0, _chunkFSBD5R22js.BadRequestException)(`module "${tag}" doesn't exist`)));
56
+ const meta2 = metaMap.get(tag)[func];
57
+ if (!meta2)
58
+ return resolve(await _chunkFSBD5R22js.Context.filterRecord.default(new (0, _chunkFSBD5R22js.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
59
+ const { data: { params } } = meta2;
60
+ const contextData = {
61
+ type: "koa",
62
+ index: i,
63
+ ctx,
64
+ meta: meta2,
65
+ moduleMap,
66
+ parallel: true,
67
+ next,
68
+ app: router,
69
+ ..._chunkFSBD5R22js.argToReq.call(void 0, params, item.args, ctx.headers),
70
+ tag,
71
+ func
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
+ ctx.body = ret;
81
83
  });
82
- })).then((ret) => {
83
- ctx.body = ret;
84
- });
85
- } catch (e) {
86
- return errorHandler(e);
87
- }
88
- });
84
+ } catch (e) {
85
+ return errorHandler(e);
86
+ }
87
+ });
88
+ }
89
89
  for (const [tag, record] of metaMap) {
90
90
  for (const func in record) {
91
91
  const meta2 = metaMap.get(tag)[func];
92
- const { data: { plugins: plugins2, http } } = meta2;
92
+ const { data: { plugins, http } } = meta2;
93
93
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
94
94
  continue;
95
- router[http.type](http.prefix + http.route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins2), async (ctx, next) => {
95
+ router[http.type](http.prefix + http.route, ..._chunkFSBD5R22js.Context.usePlugin(plugins, "koa"), async (ctx, next) => {
96
96
  debug(`invoke method "${func}" in module "${tag}"`);
97
97
  const contextData = {
98
98
  type: "koa",
@@ -108,7 +108,7 @@ function bind(router, { moduleMap, meta }, opts = {}) {
108
108
  headers: ctx.headers,
109
109
  next
110
110
  };
111
- const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
111
+ const context = new (0, _chunkFSBD5R22js.Context)(contextData);
112
112
  if (http.headers) {
113
113
  for (const name in http.headers)
114
114
  ctx.set(name, http.headers[name]);
@@ -132,26 +132,13 @@ function bind(router, { moduleMap, meta }, opts = {}) {
132
132
  }
133
133
  }
134
134
  }
135
- _chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
136
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
137
- plugins,
138
- guards: globalGuards,
139
- interceptors: globalInterceptors
140
- });
141
- handleMeta();
142
- createRoute();
143
- _chunkYERBWZCSjs.HMR.call(void 0, async () => {
135
+ _chunkZP7HNASUjs.__name.call(void 0, registerRoute, "registerRoute");
136
+ _chunkFSBD5R22js.HMR.call(void 0, async () => {
144
137
  router.stack = originStack;
145
- _chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
146
- plugins,
147
- guards: globalGuards,
148
- interceptors: globalInterceptors
149
- });
150
- handleMeta();
151
- createRoute();
138
+ registerRoute();
152
139
  });
153
140
  }
154
- _chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
141
+ _chunkZP7HNASUjs.__name.call(void 0, bind, "bind");
155
142
 
156
143
 
157
144
  exports.bind = bind;
@@ -3,96 +3,96 @@ import {
3
3
  Context,
4
4
  HMR,
5
5
  argToReq,
6
+ createControllerMetaMap,
6
7
  detectAopDep
7
- } from "../../chunk-AB4OX3WV.mjs";
8
+ } from "../../chunk-665MB62T.mjs";
8
9
  import {
9
10
  __name
10
- } from "../../chunk-ITTD2GBR.mjs";
11
+ } from "../../chunk-VLV3AO3H.mjs";
11
12
 
12
13
  // src/server/koa/bind.ts
13
14
  import Debug from "debug";
14
15
  var debug = Debug("phecda-server/koa");
15
- function bind(router, { moduleMap, meta }, opts = {}) {
16
- const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
17
- route: "/__PHECDA_SERVER__",
18
- plugins: [],
19
- ...opts
20
- };
16
+ function bind(router, data, opts = {}) {
17
+ const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
18
+ const { moduleMap, meta } = data;
21
19
  const originStack = router.stack.slice(0, router.stack.length);
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;
20
+ const metaMap = createControllerMetaMap(meta, (meta2) => {
21
+ const { controller, http, func, tag } = meta2.data;
22
+ if (controller === "http" && http?.type) {
29
23
  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
- });
24
+ return true;
36
25
  }
37
- }
38
- __name(handleMeta, "handleMeta");
39
- async function createRoute() {
40
- router.post(route, ...Context.usePlugin(plugins), async (ctx, next) => {
41
- const { body } = ctx.request;
42
- async function errorHandler(e) {
43
- const error = await Context.filterRecord.default(e);
44
- ctx.status = error.status;
45
- ctx.body = 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: "koa",
63
- index: i,
64
- ctx,
65
- meta: meta2,
66
- moduleMap,
67
- parallel: true,
68
- next,
69
- app: router,
70
- ...argToReq(params, item.args, ctx.headers),
71
- tag,
72
- func
73
- };
74
- const context = new Context(contextData);
75
- context.run({
76
- globalGuards,
77
- globalInterceptors,
78
- globalFilter,
79
- globalPipe
80
- }, resolve, resolve);
26
+ });
27
+ detectAopDep(meta, {
28
+ plugins: [
29
+ ...globalPlugins,
30
+ ...parallelPlugins
31
+ ],
32
+ guards: globalGuards,
33
+ interceptors: globalInterceptors
34
+ });
35
+ registerRoute();
36
+ async function registerRoute() {
37
+ Context.usePlugin(globalPlugins, "koa").forEach((p) => router.use(p));
38
+ if (parallelRoute) {
39
+ router.post(parallelRoute, ...Context.usePlugin(parallelPlugins, "koa"), async (ctx, next) => {
40
+ const { body } = ctx.request;
41
+ async function errorHandler(e) {
42
+ const error = await Context.filterRecord.default(e);
43
+ ctx.status = error.status;
44
+ ctx.body = error;
45
+ }
46
+ __name(errorHandler, "errorHandler");
47
+ if (!Array.isArray(body))
48
+ return errorHandler(new BadRequestException("data format should be an array"));
49
+ try {
50
+ return Promise.all(body.map((item, i) => {
51
+ return new Promise(async (resolve) => {
52
+ const { tag, func } = item;
53
+ debug(`(parallel)invoke method "${func}" in module "${tag}"`);
54
+ if (!metaMap.has(tag))
55
+ return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
56
+ const meta2 = metaMap.get(tag)[func];
57
+ if (!meta2)
58
+ return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
59
+ const { data: { params } } = meta2;
60
+ const contextData = {
61
+ type: "koa",
62
+ index: i,
63
+ ctx,
64
+ meta: meta2,
65
+ moduleMap,
66
+ parallel: true,
67
+ next,
68
+ app: router,
69
+ ...argToReq(params, item.args, ctx.headers),
70
+ tag,
71
+ func
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
+ ctx.body = ret;
81
83
  });
82
- })).then((ret) => {
83
- ctx.body = ret;
84
- });
85
- } catch (e) {
86
- return errorHandler(e);
87
- }
88
- });
84
+ } catch (e) {
85
+ return errorHandler(e);
86
+ }
87
+ });
88
+ }
89
89
  for (const [tag, record] of metaMap) {
90
90
  for (const func in record) {
91
91
  const meta2 = metaMap.get(tag)[func];
92
- const { data: { plugins: plugins2, http } } = meta2;
92
+ const { data: { plugins, http } } = meta2;
93
93
  if (!http?.type)
94
94
  continue;
95
- router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins2), async (ctx, next) => {
95
+ router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins, "koa"), async (ctx, next) => {
96
96
  debug(`invoke method "${func}" in module "${tag}"`);
97
97
  const contextData = {
98
98
  type: "koa",
@@ -132,23 +132,10 @@ function bind(router, { moduleMap, meta }, opts = {}) {
132
132
  }
133
133
  }
134
134
  }
135
- __name(createRoute, "createRoute");
136
- detectAopDep(meta, {
137
- plugins,
138
- guards: globalGuards,
139
- interceptors: globalInterceptors
140
- });
141
- handleMeta();
142
- createRoute();
135
+ __name(registerRoute, "registerRoute");
143
136
  HMR(async () => {
144
137
  router.stack = originStack;
145
- detectAopDep(meta, {
146
- plugins,
147
- guards: globalGuards,
148
- interceptors: globalInterceptors
149
- });
150
- handleMeta();
151
- createRoute();
138
+ registerRoute();
152
139
  });
153
140
  }
154
141
  __name(bind, "bind");
package/dist/test.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as supertest from 'supertest';
2
2
  import { Test } from 'supertest';
3
3
  import { Server } from 'node:http';
4
4
  import { Construct } from 'phecda-core';
5
- import { F as Factory, P as PickFunc } from './core-fd134ffa.js';
5
+ import { F as Factory, P as PickFunc } from './core-39f27fe8.js';
6
6
 
7
7
  declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
8
8
  get<C extends T[number]>(Module: C): InstanceType<C>;
package/dist/test.js CHANGED
@@ -1,14 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkF5YWXY5Wjs = require('./chunk-F5YWXY5W.js');
3
+ var _chunkHMPTPTFLjs = require('./chunk-HMPTPTFL.js');
4
4
 
5
5
 
6
- var _chunkYR5Q5F2Kjs = require('./chunk-YR5Q5F2K.js');
6
+ var _chunkZP7HNASUjs = require('./chunk-ZP7HNASU.js');
7
7
 
8
8
  // src/test.ts
9
9
  var _phecdacore = require('phecda-core');
10
10
  async function TestFactory(...Modules) {
11
- const { moduleMap, constructorMap } = await _chunkF5YWXY5Wjs.Factory.call(void 0, Modules);
11
+ const { moduleMap, constructorMap } = await _chunkHMPTPTFLjs.Factory.call(void 0, Modules);
12
12
  return {
13
13
  get(Module) {
14
14
  const tag = _phecdacore.getTag.call(void 0, Module);
@@ -21,7 +21,7 @@ async function TestFactory(...Modules) {
21
21
  }
22
22
  };
23
23
  }
24
- _chunkYR5Q5F2Kjs.__name.call(void 0, TestFactory, "TestFactory");
24
+ _chunkZP7HNASUjs.__name.call(void 0, TestFactory, "TestFactory");
25
25
  async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
26
26
  const { default: request, agent } = await Promise.resolve().then(() => require("supertest"));
27
27
  const Agent = agent(app);
@@ -67,11 +67,11 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
67
67
  }
68
68
  });
69
69
  }
70
- _chunkYR5Q5F2Kjs.__name.call(void 0, module, "module");
70
+ _chunkZP7HNASUjs.__name.call(void 0, module, "module");
71
71
  Agent.module = module;
72
72
  return Agent;
73
73
  }
74
- _chunkYR5Q5F2Kjs.__name.call(void 0, TestHttp, "TestHttp");
74
+ _chunkZP7HNASUjs.__name.call(void 0, TestHttp, "TestHttp");
75
75
 
76
76
 
77
77
 
package/dist/test.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  Factory
3
- } from "./chunk-RCTOVYZY.mjs";
3
+ } from "./chunk-2HKQPZDT.mjs";
4
4
  import {
5
5
  __name
6
- } from "./chunk-ITTD2GBR.mjs";
6
+ } from "./chunk-VLV3AO3H.mjs";
7
7
 
8
8
  // src/test.ts
9
9
  import { getTag } from "phecda-core";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "5.0.2",
4
- "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor ",
3
+ "version": "5.1.1",
4
+ "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
@@ -117,11 +117,12 @@
117
117
  },
118
118
  "keywords": [
119
119
  "server",
120
- "express",
121
- "types-share",
122
- "fullstack"
120
+ "IOC",
121
+ "rpc",
122
+ "types-share"
123
123
  ],
124
- "author": "",
124
+ "author": "fgsreally",
125
+ "repository": "https://github.com/fgsreally/phecda/tree/main/packages/server",
125
126
  "files": [
126
127
  "dist",
127
128
  "register",
@@ -143,7 +144,7 @@
143
144
  "elysia": "^1.0.17",
144
145
  "express": "^4.18.2",
145
146
  "fastify": "^4.25.1",
146
- "h3": "^1.9.0",
147
+ "h3": "^1.11.1",
147
148
  "hono": "^4.3.4",
148
149
  "hyper-express": "^6.15.2",
149
150
  "ioredis": "^5.3.2",
@@ -155,7 +156,7 @@
155
156
  "nats": "^2.22.0",
156
157
  "supertest": "^6.3.3",
157
158
  "tsup": "^6.5.0",
158
- "typescript": "^5.2.2",
159
+ "typescript": "^5.4.5",
159
160
  "unimport": "^3.7.1"
160
161
  },
161
162
  "dependencies": {
@@ -67,9 +67,10 @@ export async function initialize(data) {
67
67
  if (!config.unimport)
68
68
  return
69
69
  unimportRet = await genUnImportRet(config.unimport)
70
- await unimportRet.init()
71
70
  if (unimportRet) {
72
71
  log('auto import...')
72
+ await unimportRet.init()
73
+
73
74
  writeFile(
74
75
  config.unimport.dtsPath || dtsPath,
75
76
  handleClassTypes(await unimportRet.generateTypeDeclarations()),
@@ -120,9 +121,9 @@ export const resolve = async (specifier, context, nextResolve) => {
120
121
  }
121
122
  }
122
123
  // url import
124
+ // it seems useless
123
125
  if (/^file:\/\/\//.test(specifier) && extname(specifier) === '.ts') {
124
126
  const url = addUrlToGraph(specifier, context.parentURL.split('?')[0])
125
-
126
127
  return {
127
128
  format: 'ts',
128
129
  url,
@@ -151,7 +152,8 @@ export const resolve = async (specifier, context, nextResolve) => {
151
152
  host,
152
153
  moduleResolutionCache,
153
154
  )
154
- // import from local project to local project TS file
155
+
156
+ // import between loacl projects
155
157
  if (
156
158
  resolvedModule
157
159
  && !resolvedModule.resolvedFileName.includes('/node_modules/')
@@ -184,7 +186,13 @@ export const resolve = async (specifier, context, nextResolve) => {
184
186
  }
185
187
  }
186
188
 
187
- return nextResolve(specifier)
189
+ const resolveRet = await nextResolve(specifier)
190
+
191
+ // ts resolve fail in some cases
192
+ if (isAbsolute(resolveRet.url))
193
+ resolveRet.url = pathToFileURL(resolveRet.url).href
194
+
195
+ return resolveRet
188
196
  }
189
197
  // @todo the first params may be url or path, need to distinguish
190
198
 
@@ -271,7 +279,13 @@ export const load = async (url, context, nextLoad) => {
271
279
  return {
272
280
  format: 'module',
273
281
  source: (
274
- await injectImports(compiled, (url.startsWith('file://') ? fileURLToPath(url) : url).replace(/\\/g, '/'))
282
+ await injectImports(
283
+ compiled,
284
+ (url.startsWith('file://') ? fileURLToPath(url) : url).replace(
285
+ /\\/g,
286
+ '/',
287
+ ),
288
+ )
275
289
  ).code,
276
290
  shortCircuit: true,
277
291
  }