phecda-server 5.2.4 → 5.2.5

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 (77) hide show
  1. package/dist/{chunk-VYDBNZJ2.mjs → chunk-2NTXVYQC.mjs} +1 -8
  2. package/dist/{chunk-Q4AGVGVA.mjs → chunk-2O6X54P5.mjs} +103 -105
  3. package/dist/{chunk-AWY6FTH4.js → chunk-6QLTBEXP.js} +70 -86
  4. package/dist/{chunk-H6NYBVBV.js → chunk-6T4UZ4LV.js} +130 -132
  5. package/dist/{chunk-FNJWO324.js → chunk-H2FWLKXN.js} +2 -9
  6. package/dist/{chunk-IJNA24EZ.mjs → chunk-JJJ7AUEF.mjs} +39 -55
  7. package/dist/{chunk-LGP5AT6W.mjs → chunk-MGADYFW4.mjs} +28 -49
  8. package/dist/{chunk-UJAI73O6.js → chunk-MKZOLLJS.js} +39 -60
  9. package/dist/core-BIm7dkko.d.mts +27 -0
  10. package/dist/{core-7f6d2be6.d.ts → core-C3cON4Um.d.ts} +1 -1
  11. package/dist/helper.d.mts +27 -0
  12. package/dist/helper.d.ts +1 -1
  13. package/dist/helper.js +3 -3
  14. package/dist/helper.mjs +2 -2
  15. package/dist/index.d.mts +246 -0
  16. package/dist/index.d.ts +7 -7
  17. package/dist/index.js +73 -64
  18. package/dist/index.mjs +48 -39
  19. package/dist/rpc/bullmq/index.d.mts +21 -0
  20. package/dist/rpc/bullmq/index.d.ts +4 -4
  21. package/dist/rpc/bullmq/index.js +30 -43
  22. package/dist/rpc/bullmq/index.mjs +20 -33
  23. package/dist/rpc/kafka/index.d.mts +24 -0
  24. package/dist/rpc/kafka/index.d.ts +4 -4
  25. package/dist/rpc/kafka/index.js +25 -34
  26. package/dist/rpc/kafka/index.mjs +17 -26
  27. package/dist/rpc/nats/index.d.mts +15 -0
  28. package/dist/rpc/nats/index.d.ts +4 -4
  29. package/dist/rpc/nats/index.js +33 -46
  30. package/dist/rpc/nats/index.mjs +24 -37
  31. package/dist/rpc/rabbitmq/index.d.mts +16 -0
  32. package/dist/rpc/rabbitmq/index.d.ts +4 -4
  33. package/dist/rpc/rabbitmq/index.js +34 -46
  34. package/dist/rpc/rabbitmq/index.mjs +23 -35
  35. package/dist/rpc/redis/index.d.mts +23 -0
  36. package/dist/rpc/redis/index.d.ts +4 -4
  37. package/dist/rpc/redis/index.js +27 -38
  38. package/dist/rpc/redis/index.mjs +18 -29
  39. package/dist/server/elysia/index.d.mts +18 -0
  40. package/dist/server/elysia/index.d.ts +4 -4
  41. package/dist/server/elysia/index.js +22 -27
  42. package/dist/server/elysia/index.mjs +8 -13
  43. package/dist/server/express/index.d.mts +18 -0
  44. package/dist/server/express/index.d.ts +4 -4
  45. package/dist/server/express/index.js +24 -33
  46. package/dist/server/express/index.mjs +11 -20
  47. package/dist/server/fastify/index.d.mts +20 -0
  48. package/dist/server/fastify/index.d.ts +4 -4
  49. package/dist/server/fastify/index.js +23 -30
  50. package/dist/server/fastify/index.mjs +10 -17
  51. package/dist/server/h3/index.d.mts +16 -0
  52. package/dist/server/h3/index.d.ts +4 -4
  53. package/dist/server/h3/index.js +21 -25
  54. package/dist/server/h3/index.mjs +10 -14
  55. package/dist/server/hono/index.d.mts +16 -0
  56. package/dist/server/hono/index.d.ts +4 -4
  57. package/dist/server/hono/index.js +22 -30
  58. package/dist/server/hono/index.mjs +10 -18
  59. package/dist/server/hyper-express/index.d.mts +18 -0
  60. package/dist/server/hyper-express/index.d.ts +4 -4
  61. package/dist/server/hyper-express/index.js +23 -32
  62. package/dist/server/hyper-express/index.mjs +11 -20
  63. package/dist/server/koa/index.d.mts +18 -0
  64. package/dist/server/koa/index.d.ts +4 -4
  65. package/dist/server/koa/index.js +22 -29
  66. package/dist/server/koa/index.mjs +9 -16
  67. package/dist/test.d.mts +18 -0
  68. package/dist/test.d.ts +3 -3
  69. package/dist/test.js +14 -22
  70. package/dist/test.mjs +10 -18
  71. package/dist/types-B-y2TwhC.d.mts +17 -0
  72. package/dist/types-ByP1fKMe.d.mts +27 -0
  73. package/dist/{types-0a76c4bc.d.ts → types-C5sdDiDQ.d.ts} +2 -2
  74. package/dist/{types-f3b79218.d.ts → types-CIZbw8S2.d.ts} +2 -2
  75. package/dist/{types-81be0ba3.d.ts → types-CdQey96H.d.mts} +1 -1
  76. package/dist/types-CdQey96H.d.ts +108 -0
  77. package/package.json +3 -3
@@ -1,30 +1,26 @@
1
1
  import {
2
2
  mergeObject,
3
3
  shallowClone
4
- } from "./chunk-Q4AGVGVA.mjs";
4
+ } from "./chunk-2O6X54P5.mjs";
5
5
  import {
6
6
  __name
7
- } from "./chunk-VYDBNZJ2.mjs";
7
+ } from "./chunk-2NTXVYQC.mjs";
8
8
 
9
9
  // src/decorators/param.ts
10
10
  import { getState, setPropertyState } from "phecda-core";
11
11
  function BaseParam(data) {
12
12
  return (target, k, index) => {
13
- if (!k)
14
- return;
13
+ if (!k) return;
15
14
  setPropertyState(target, k, (state) => {
16
- if (!state.params)
17
- state.params = [
18
- ...getState(target, k)?.params || []
19
- ].map(shallowClone);
15
+ if (!state.params) state.params = [
16
+ ...getState(target, k)?.params || []
17
+ ].map(shallowClone);
20
18
  const existItem = state.params.find((item) => item.index === index);
21
- if (existItem)
22
- Object.assign(existItem, data);
23
- else
24
- state.params.push({
25
- ...data,
26
- index
27
- });
19
+ if (existItem) Object.assign(existItem, data);
20
+ else state.params.push({
21
+ ...data,
22
+ index
23
+ });
28
24
  });
29
25
  };
30
26
  }
@@ -70,13 +66,11 @@ import { getState as getState2, setPropertyState as setPropertyState2 } from "ph
70
66
  function Guard(...guards) {
71
67
  return (target, k) => {
72
68
  setPropertyState2(target, k, (state) => {
73
- if (!state.guards)
74
- state.guards = /* @__PURE__ */ new Set([
75
- ...getState2(target, k)?.guards || []
76
- ]);
69
+ if (!state.guards) state.guards = /* @__PURE__ */ new Set([
70
+ ...getState2(target, k)?.guards || []
71
+ ]);
77
72
  guards.forEach((guard) => {
78
- if (state.guards.has(guard))
79
- state.guards.delete(guard);
73
+ if (state.guards.has(guard)) state.guards.delete(guard);
80
74
  state.guards.add(guard);
81
75
  });
82
76
  });
@@ -86,13 +80,11 @@ __name(Guard, "Guard");
86
80
  function Plugin(...plugins) {
87
81
  return (target, k) => {
88
82
  setPropertyState2(target, k, (state) => {
89
- if (!state.plugins)
90
- state.plugins = /* @__PURE__ */ new Set([
91
- ...getState2(target, k)?.plugins || []
92
- ]);
83
+ if (!state.plugins) state.plugins = /* @__PURE__ */ new Set([
84
+ ...getState2(target, k)?.plugins || []
85
+ ]);
93
86
  plugins.forEach((plugin) => {
94
- if (state.plugins.has(plugin))
95
- state.plugins.delete(plugin);
87
+ if (state.plugins.has(plugin)) state.plugins.delete(plugin);
96
88
  state.plugins.add(plugin);
97
89
  });
98
90
  });
@@ -102,13 +94,11 @@ __name(Plugin, "Plugin");
102
94
  function Interceptor(...interceptors) {
103
95
  return (target, k) => {
104
96
  setPropertyState2(target, k, (state) => {
105
- if (!state.interceptors)
106
- state.interceptors = /* @__PURE__ */ new Set([
107
- ...getState2(target, k)?.interceptors || []
108
- ]);
97
+ if (!state.interceptors) state.interceptors = /* @__PURE__ */ new Set([
98
+ ...getState2(target, k)?.interceptors || []
99
+ ]);
109
100
  interceptors.forEach((interceptor) => {
110
- if (state.interceptors.has(interceptor))
111
- state.interceptors.delete(interceptor);
101
+ if (state.interceptors.has(interceptor)) state.interceptors.delete(interceptor);
112
102
  state.interceptors.add(interceptor);
113
103
  });
114
104
  });
@@ -150,8 +140,7 @@ __name(Route, "Route");
150
140
  function Header(headers) {
151
141
  return (target, k) => {
152
142
  setPropertyState3(target, k, (state) => {
153
- if (!state.http)
154
- state.http = mergeObject(getState3(target, k)?.http);
143
+ if (!state.http) state.http = mergeObject(getState3(target, k)?.http);
155
144
  state.http = mergeObject(state.http, {
156
145
  headers: mergeObject(state.http?.headers, headers)
157
146
  });
@@ -230,10 +219,9 @@ function Injectable() {
230
219
  __name(Injectable, "Injectable");
231
220
  var Ctx = /* @__PURE__ */ __name((target, key) => {
232
221
  setPropertyState5(target, SHARE_KEY, (state) => {
233
- if (!state.ctxs)
234
- state.ctxs = /* @__PURE__ */ new Set([
235
- ...getState5(target)?.ctxs || []
236
- ]);
222
+ if (!state.ctxs) state.ctxs = /* @__PURE__ */ new Set([
223
+ ...getState5(target)?.ctxs || []
224
+ ]);
237
225
  state.ctxs.add(key);
238
226
  });
239
227
  }, "Ctx");
@@ -242,29 +230,25 @@ function Define(key, value) {
242
230
  if (typeof index === "number") {
243
231
  setPropertyState5(target, k, (state) => {
244
232
  const parentState = getState5(target, k)?.params || [];
245
- if (!state.params)
246
- state.params = [
247
- ...parentState
248
- ].map(shallowClone);
233
+ if (!state.params) state.params = [
234
+ ...parentState
235
+ ].map(shallowClone);
249
236
  const existItem = state.params.find((item) => item.index === index);
250
- if (existItem)
251
- existItem.define = mergeObject(existItem.define, {
237
+ if (existItem) existItem.define = mergeObject(existItem.define, {
238
+ [key]: value
239
+ });
240
+ else state.params.push({
241
+ define: {
252
242
  [key]: value
253
- });
254
- else
255
- state.params.push({
256
- define: {
257
- [key]: value
258
- },
259
- index
260
- });
243
+ },
244
+ index
245
+ });
261
246
  });
262
247
  return;
263
248
  }
264
249
  setPropertyState5(target, k, (state) => {
265
250
  const parentState = getState5(target, k)?.define;
266
- if (!state.define)
267
- state.define = mergeObject(parentState);
251
+ if (!state.define) state.define = mergeObject(parentState);
268
252
  state.define[key] = value;
269
253
  });
270
254
  };
@@ -3,10 +3,13 @@ import {
3
3
  IS_ONLY_GENERATE,
4
4
  __name,
5
5
  log
6
- } from "./chunk-VYDBNZJ2.mjs";
6
+ } from "./chunk-2NTXVYQC.mjs";
7
7
 
8
8
  // src/meta.ts
9
9
  var Meta = class {
10
+ static {
11
+ __name(this, "Meta");
12
+ }
10
13
  data;
11
14
  paramsType;
12
15
  constructor(data, paramsType) {
@@ -14,7 +17,6 @@ var Meta = class {
14
17
  this.paramsType = paramsType;
15
18
  }
16
19
  };
17
- __name(Meta, "Meta");
18
20
 
19
21
  // src/core.ts
20
22
  import "reflect-metadata";
@@ -33,18 +35,15 @@ async function Factory(models, opts = {}) {
33
35
  if (!getInject("watcher")) {
34
36
  setInject("watcher", ({ eventName, instance, key, options }) => {
35
37
  const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
36
- if (options?.once)
37
- emitter.once(eventName, fn);
38
- else
39
- emitter.on(eventName, fn);
38
+ if (options?.once) emitter.once(eventName, fn);
39
+ else emitter.on(eventName, fn);
40
40
  return () => {
41
41
  emitter.off(eventName, fn);
42
42
  };
43
43
  });
44
44
  }
45
45
  async function del(tag) {
46
- if (!moduleMap.has(tag))
47
- return;
46
+ if (!moduleMap.has(tag)) return;
48
47
  const instance = moduleMap.get(tag);
49
48
  debug(`unmount module "${String(tag)}"`);
50
49
  await invokeHandler("unmount", instance);
@@ -52,16 +51,14 @@ async function Factory(models, opts = {}) {
52
51
  moduleMap.delete(tag);
53
52
  constructorMap.delete(tag);
54
53
  for (let i = meta.length - 1; i >= 0; i--) {
55
- if (meta[i].data.tag === tag)
56
- meta.splice(i, 1);
54
+ if (meta[i].data.tag === tag) meta.splice(i, 1);
57
55
  }
58
56
  return instance;
59
57
  }
60
58
  __name(del, "del");
61
59
  async function destroy() {
62
60
  debug("destroy all");
63
- for (const [tag] of moduleMap)
64
- await del(tag);
61
+ for (const [tag] of moduleMap) await del(tag);
65
62
  }
66
63
  __name(destroy, "destroy");
67
64
  async function add(Model) {
@@ -75,8 +72,7 @@ async function Factory(models, opts = {}) {
75
72
  ].forEach((tag2) => {
76
73
  const module = moduleMap.get(tag2);
77
74
  for (const key in module) {
78
- if (module[key] === oldInstance)
79
- module[key] = newModule;
75
+ if (module[key] === oldInstance) module[key] = newModule;
80
76
  }
81
77
  });
82
78
  }
@@ -88,14 +84,11 @@ async function Factory(models, opts = {}) {
88
84
  const tag = getTag(Model);
89
85
  if (moduleMap.has(tag)) {
90
86
  instance = moduleMap.get(tag);
91
- if (!instance)
92
- throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Model}`);
87
+ if (!instance) throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Model}`);
93
88
  if (constructorMap.get(tag) !== Model && !constructorSet.has(Model)) {
94
89
  constructorSet.add(Model);
95
- if (instance instanceof Model)
96
- log(`Module taged ${String(tag)} has been overridden`);
97
- else
98
- log(`Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Model.name}"`, "warn");
90
+ if (instance instanceof Model) log(`Module taged ${String(tag)} has been overridden`);
91
+ else log(`Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Model.name}"`, "warn");
99
92
  }
100
93
  return {
101
94
  instance,
@@ -109,8 +102,7 @@ async function Factory(models, opts = {}) {
109
102
  for (const i in paramtypes) {
110
103
  const { instance: sub, tag: subTag } = await buildDepModule(paramtypes[i]);
111
104
  paramtypesInstances[i] = sub;
112
- if (!dependenceGraph.has(subTag))
113
- dependenceGraph.set(subTag, /* @__PURE__ */ new Set());
105
+ if (!dependenceGraph.has(subTag)) dependenceGraph.set(subTag, /* @__PURE__ */ new Set());
114
106
  dependenceGraph.get(subTag).add(tag);
115
107
  }
116
108
  instance = parseModule(new Model(...paramtypesInstances));
@@ -119,8 +111,7 @@ async function Factory(models, opts = {}) {
119
111
  }
120
112
  meta.push(...getMetaFromInstance(instance, tag, Model.name).map(parseMeta).filter((item) => !!item));
121
113
  debug(`init module "${String(tag)}"`);
122
- if (!IS_ONLY_GENERATE)
123
- await invokeHandler("init", instance);
114
+ if (!IS_ONLY_GENERATE) await invokeHandler("init", instance);
124
115
  debug(`add module "${String(tag)}"`);
125
116
  moduleMap.set(tag, instance);
126
117
  constructorMap.set(tag, Model);
@@ -130,10 +121,9 @@ async function Factory(models, opts = {}) {
130
121
  };
131
122
  }
132
123
  __name(buildDepModule, "buildDepModule");
133
- for (const model of models)
134
- await buildDepModule(model);
124
+ for (const model of models) await buildDepModule(model);
135
125
  async function generateCode() {
136
- if (generators) {
126
+ if (generators && IS_HMR) {
137
127
  return Promise.all(generators.map((generator) => {
138
128
  debug(`generate "${generator.name}" code to ${generator.path}`);
139
129
  return generator.output(meta);
@@ -142,19 +132,16 @@ async function Factory(models, opts = {}) {
142
132
  }
143
133
  __name(generateCode, "generateCode");
144
134
  generateCode().then(() => {
145
- if (IS_ONLY_GENERATE)
146
- process.exit(4);
135
+ if (IS_ONLY_GENERATE) process.exit(4);
147
136
  });
148
137
  if (IS_HMR) {
149
- if (!globalThis.__PS_HMR__)
150
- globalThis.__PS_HMR__ = [];
138
+ if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
151
139
  globalThis.__PS_HMR__?.push(async (files) => {
152
140
  debug("reload files ");
153
141
  for (const file of files) {
154
142
  const models2 = await import(file);
155
143
  for (const i in models2) {
156
- if (isPhecda(models2[i]))
157
- await add(models2[i]);
144
+ if (isPhecda(models2[i])) await add(models2[i]);
158
145
  }
159
146
  }
160
147
  generateCode();
@@ -184,8 +171,7 @@ function getMetaFromInstance(instance, tag, name) {
184
171
  func: i
185
172
  };
186
173
  if (baseState.controller) {
187
- if (typeof tag !== "string")
188
- log(`can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
174
+ if (typeof tag !== "string") log(`can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
189
175
  initState(state);
190
176
  meta.controller = baseState.controller;
191
177
  meta[baseState.controller] = {
@@ -194,13 +180,10 @@ function getMetaFromInstance(instance, tag, name) {
194
180
  };
195
181
  const params = [];
196
182
  for (const i2 of state.params || []) {
197
- if (!i2.pipe)
198
- i2.pipe = state.pipe || baseState.pipe;
199
- if (!i2.define)
200
- i2.define = {};
183
+ if (!i2.pipe) i2.pipe = state.pipe || baseState.pipe;
184
+ if (!i2.define) i2.define = {};
201
185
  params.unshift(i2);
202
- if (i2.index === 0)
203
- break;
186
+ if (i2.index === 0) break;
204
187
  }
205
188
  meta.ctxs = ctxs;
206
189
  meta.params = params;
@@ -237,14 +220,10 @@ function getParamTypes(Model, key) {
237
220
  }
238
221
  __name(getParamTypes, "getParamTypes");
239
222
  function initState(state) {
240
- if (!state.define)
241
- state.define = {};
242
- if (!state.plugins)
243
- state.plugins = /* @__PURE__ */ new Set();
244
- if (!state.guards)
245
- state.guards = /* @__PURE__ */ new Set();
246
- if (!state.interceptors)
247
- state.interceptors = /* @__PURE__ */ new Set();
223
+ if (!state.define) state.define = {};
224
+ if (!state.plugins) state.plugins = /* @__PURE__ */ new Set();
225
+ if (!state.guards) state.guards = /* @__PURE__ */ new Set();
226
+ if (!state.interceptors) state.interceptors = /* @__PURE__ */ new Set();
248
227
  }
249
228
  __name(initState, "initState");
250
229
 
@@ -3,10 +3,13 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkFNJWO324js = require('./chunk-FNJWO324.js');
6
+ var _chunkH2FWLKXNjs = require('./chunk-H2FWLKXN.js');
7
7
 
8
8
  // src/meta.ts
9
9
  var Meta = class {
10
+ static {
11
+ _chunkH2FWLKXNjs.__name.call(void 0, this, "Meta");
12
+ }
10
13
 
11
14
 
12
15
  constructor(data, paramsType) {
@@ -14,7 +17,6 @@ var Meta = class {
14
17
  this.paramsType = paramsType;
15
18
  }
16
19
  };
17
- _chunkFNJWO324js.__name.call(void 0, Meta, "Meta");
18
20
 
19
21
  // src/core.ts
20
22
  require('reflect-metadata');
@@ -29,22 +31,19 @@ async function Factory(models, opts = {}) {
29
31
  const constructorMap = /* @__PURE__ */ new Map();
30
32
  const constructorSet = /* @__PURE__ */ new WeakSet();
31
33
  const dependenceGraph = /* @__PURE__ */ new Map();
32
- const { parseModule = /* @__PURE__ */ _chunkFNJWO324js.__name.call(void 0, (module) => module, "parseModule"), parseMeta = /* @__PURE__ */ _chunkFNJWO324js.__name.call(void 0, (meta2) => meta2, "parseMeta"), generators } = opts;
34
+ const { parseModule = /* @__PURE__ */ _chunkH2FWLKXNjs.__name.call(void 0, (module) => module, "parseModule"), parseMeta = /* @__PURE__ */ _chunkH2FWLKXNjs.__name.call(void 0, (meta2) => meta2, "parseMeta"), generators } = opts;
33
35
  if (!_phecdacore.getInject.call(void 0, "watcher")) {
34
36
  _phecdacore.setInject.call(void 0, "watcher", ({ eventName, instance, key, options }) => {
35
37
  const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
36
- if (_optionalChain([options, 'optionalAccess', _ => _.once]))
37
- emitter.once(eventName, fn);
38
- else
39
- emitter.on(eventName, fn);
38
+ if (_optionalChain([options, 'optionalAccess', _ => _.once])) emitter.once(eventName, fn);
39
+ else emitter.on(eventName, fn);
40
40
  return () => {
41
41
  emitter.off(eventName, fn);
42
42
  };
43
43
  });
44
44
  }
45
45
  async function del(tag) {
46
- if (!moduleMap.has(tag))
47
- return;
46
+ if (!moduleMap.has(tag)) return;
48
47
  const instance = moduleMap.get(tag);
49
48
  debug(`unmount module "${String(tag)}"`);
50
49
  await _phecdacore.invokeHandler.call(void 0, "unmount", instance);
@@ -52,18 +51,16 @@ async function Factory(models, opts = {}) {
52
51
  moduleMap.delete(tag);
53
52
  constructorMap.delete(tag);
54
53
  for (let i = meta.length - 1; i >= 0; i--) {
55
- if (meta[i].data.tag === tag)
56
- meta.splice(i, 1);
54
+ if (meta[i].data.tag === tag) meta.splice(i, 1);
57
55
  }
58
56
  return instance;
59
57
  }
60
- _chunkFNJWO324js.__name.call(void 0, del, "del");
58
+ _chunkH2FWLKXNjs.__name.call(void 0, del, "del");
61
59
  async function destroy() {
62
60
  debug("destroy all");
63
- for (const [tag] of moduleMap)
64
- await del(tag);
61
+ for (const [tag] of moduleMap) await del(tag);
65
62
  }
66
- _chunkFNJWO324js.__name.call(void 0, destroy, "destroy");
63
+ _chunkH2FWLKXNjs.__name.call(void 0, destroy, "destroy");
67
64
  async function add(Model) {
68
65
  const tag = _phecdacore.getTag.call(void 0, Model);
69
66
  const oldInstance = await del(tag);
@@ -75,27 +72,23 @@ async function Factory(models, opts = {}) {
75
72
  ].forEach((tag2) => {
76
73
  const module = moduleMap.get(tag2);
77
74
  for (const key in module) {
78
- if (module[key] === oldInstance)
79
- module[key] = newModule;
75
+ if (module[key] === oldInstance) module[key] = newModule;
80
76
  }
81
77
  });
82
78
  }
83
79
  }
84
- _chunkFNJWO324js.__name.call(void 0, add, "add");
80
+ _chunkH2FWLKXNjs.__name.call(void 0, add, "add");
85
81
  async function buildDepModule(Model) {
86
82
  const paramtypes = getParamTypes(Model);
87
83
  let instance;
88
84
  const tag = _phecdacore.getTag.call(void 0, Model);
89
85
  if (moduleMap.has(tag)) {
90
86
  instance = moduleMap.get(tag);
91
- if (!instance)
92
- throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Model}`);
87
+ if (!instance) throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Model}`);
93
88
  if (constructorMap.get(tag) !== Model && !constructorSet.has(Model)) {
94
89
  constructorSet.add(Model);
95
- if (instance instanceof Model)
96
- _chunkFNJWO324js.log.call(void 0, `Module taged ${String(tag)} has been overridden`);
97
- else
98
- _chunkFNJWO324js.log.call(void 0, `Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Model.name}"`, "warn");
90
+ if (instance instanceof Model) _chunkH2FWLKXNjs.log.call(void 0, `Module taged ${String(tag)} has been overridden`);
91
+ else _chunkH2FWLKXNjs.log.call(void 0, `Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Model.name}"`, "warn");
99
92
  }
100
93
  return {
101
94
  instance,
@@ -109,8 +102,7 @@ async function Factory(models, opts = {}) {
109
102
  for (const i in paramtypes) {
110
103
  const { instance: sub, tag: subTag } = await buildDepModule(paramtypes[i]);
111
104
  paramtypesInstances[i] = sub;
112
- if (!dependenceGraph.has(subTag))
113
- dependenceGraph.set(subTag, /* @__PURE__ */ new Set());
105
+ if (!dependenceGraph.has(subTag)) dependenceGraph.set(subTag, /* @__PURE__ */ new Set());
114
106
  dependenceGraph.get(subTag).add(tag);
115
107
  }
116
108
  instance = parseModule(new Model(...paramtypesInstances));
@@ -119,8 +111,7 @@ async function Factory(models, opts = {}) {
119
111
  }
120
112
  meta.push(...getMetaFromInstance(instance, tag, Model.name).map(parseMeta).filter((item) => !!item));
121
113
  debug(`init module "${String(tag)}"`);
122
- if (!_chunkFNJWO324js.IS_ONLY_GENERATE)
123
- await _phecdacore.invokeHandler.call(void 0, "init", instance);
114
+ if (!_chunkH2FWLKXNjs.IS_ONLY_GENERATE) await _phecdacore.invokeHandler.call(void 0, "init", instance);
124
115
  debug(`add module "${String(tag)}"`);
125
116
  moduleMap.set(tag, instance);
126
117
  constructorMap.set(tag, Model);
@@ -129,32 +120,28 @@ async function Factory(models, opts = {}) {
129
120
  tag
130
121
  };
131
122
  }
132
- _chunkFNJWO324js.__name.call(void 0, buildDepModule, "buildDepModule");
133
- for (const model of models)
134
- await buildDepModule(model);
123
+ _chunkH2FWLKXNjs.__name.call(void 0, buildDepModule, "buildDepModule");
124
+ for (const model of models) await buildDepModule(model);
135
125
  async function generateCode() {
136
- if (generators) {
126
+ if (generators && _chunkH2FWLKXNjs.IS_HMR) {
137
127
  return Promise.all(generators.map((generator) => {
138
128
  debug(`generate "${generator.name}" code to ${generator.path}`);
139
129
  return generator.output(meta);
140
130
  }));
141
131
  }
142
132
  }
143
- _chunkFNJWO324js.__name.call(void 0, generateCode, "generateCode");
133
+ _chunkH2FWLKXNjs.__name.call(void 0, generateCode, "generateCode");
144
134
  generateCode().then(() => {
145
- if (_chunkFNJWO324js.IS_ONLY_GENERATE)
146
- process.exit(4);
135
+ if (_chunkH2FWLKXNjs.IS_ONLY_GENERATE) process.exit(4);
147
136
  });
148
- if (_chunkFNJWO324js.IS_HMR) {
149
- if (!globalThis.__PS_HMR__)
150
- globalThis.__PS_HMR__ = [];
137
+ if (_chunkH2FWLKXNjs.IS_HMR) {
138
+ if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
151
139
  _optionalChain([globalThis, 'access', _2 => _2.__PS_HMR__, 'optionalAccess', _3 => _3.push, 'call', _4 => _4(async (files) => {
152
140
  debug("reload files ");
153
141
  for (const file of files) {
154
142
  const models2 = await Promise.resolve().then(() => _interopRequireWildcard(require(file)));
155
143
  for (const i in models2) {
156
- if (_phecdacore.isPhecda.call(void 0, models2[i]))
157
- await add(models2[i]);
144
+ if (_phecdacore.isPhecda.call(void 0, models2[i])) await add(models2[i]);
158
145
  }
159
146
  }
160
147
  generateCode();
@@ -169,7 +156,7 @@ async function Factory(models, opts = {}) {
169
156
  destroy
170
157
  };
171
158
  }
172
- _chunkFNJWO324js.__name.call(void 0, Factory, "Factory");
159
+ _chunkH2FWLKXNjs.__name.call(void 0, Factory, "Factory");
173
160
  function getMetaFromInstance(instance, tag, name) {
174
161
  const vars = _phecdacore.getExposeKey.call(void 0, instance).filter((item) => typeof item === "string");
175
162
  const baseState = _phecdacore.getState.call(void 0, instance);
@@ -184,8 +171,7 @@ function getMetaFromInstance(instance, tag, name) {
184
171
  func: i
185
172
  };
186
173
  if (baseState.controller) {
187
- if (typeof tag !== "string")
188
- _chunkFNJWO324js.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
174
+ if (typeof tag !== "string") _chunkH2FWLKXNjs.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
189
175
  initState(state);
190
176
  meta.controller = baseState.controller;
191
177
  meta[baseState.controller] = {
@@ -194,13 +180,10 @@ function getMetaFromInstance(instance, tag, name) {
194
180
  };
195
181
  const params = [];
196
182
  for (const i2 of state.params || []) {
197
- if (!i2.pipe)
198
- i2.pipe = state.pipe || baseState.pipe;
199
- if (!i2.define)
200
- i2.define = {};
183
+ if (!i2.pipe) i2.pipe = state.pipe || baseState.pipe;
184
+ if (!i2.define) i2.define = {};
201
185
  params.unshift(i2);
202
- if (i2.index === 0)
203
- break;
186
+ if (i2.index === 0) break;
204
187
  }
205
188
  meta.ctxs = ctxs;
206
189
  meta.params = params;
@@ -231,22 +214,18 @@ function getMetaFromInstance(instance, tag, name) {
231
214
  return new Meta(meta, getParamTypes(instance, i) || []);
232
215
  });
233
216
  }
234
- _chunkFNJWO324js.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
217
+ _chunkH2FWLKXNjs.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
235
218
  function getParamTypes(Model, key) {
236
219
  return Reflect.getMetadata("design:paramtypes", Model, key);
237
220
  }
238
- _chunkFNJWO324js.__name.call(void 0, getParamTypes, "getParamTypes");
221
+ _chunkH2FWLKXNjs.__name.call(void 0, getParamTypes, "getParamTypes");
239
222
  function initState(state) {
240
- if (!state.define)
241
- state.define = {};
242
- if (!state.plugins)
243
- state.plugins = /* @__PURE__ */ new Set();
244
- if (!state.guards)
245
- state.guards = /* @__PURE__ */ new Set();
246
- if (!state.interceptors)
247
- state.interceptors = /* @__PURE__ */ new Set();
223
+ if (!state.define) state.define = {};
224
+ if (!state.plugins) state.plugins = /* @__PURE__ */ new Set();
225
+ if (!state.guards) state.guards = /* @__PURE__ */ new Set();
226
+ if (!state.interceptors) state.interceptors = /* @__PURE__ */ new Set();
248
227
  }
249
- _chunkFNJWO324js.__name.call(void 0, initState, "initState");
228
+ _chunkH2FWLKXNjs.__name.call(void 0, initState, "initState");
250
229
 
251
230
 
252
231
 
@@ -0,0 +1,27 @@
1
+ import { Construct } from 'phecda-core';
2
+ import { M as MetaData, h as Meta, E as Emitter } from './types-CdQey96H.mjs';
3
+
4
+ declare abstract class Generator {
5
+ private _path;
6
+ constructor(path?: string);
7
+ abstract name: string;
8
+ get path(): string;
9
+ abstract generateCode(meta: MetaData[]): string;
10
+ output(meta: Meta[]): Promise<void>;
11
+ }
12
+
13
+ declare const emitter: Emitter;
14
+ declare function Factory(models: (new (...args: any) => any)[], opts?: {
15
+ parseModule?: (module: any) => any;
16
+ parseMeta?: (meta: Meta) => Meta | null | undefined;
17
+ generators?: Generator[];
18
+ }): Promise<{
19
+ moduleMap: Map<PropertyKey, any>;
20
+ constructorMap: Map<any, any>;
21
+ meta: Meta[];
22
+ add: (Model: Construct) => Promise<void>;
23
+ del: (tag: PropertyKey) => Promise<any>;
24
+ destroy: () => Promise<void>;
25
+ }>;
26
+
27
+ export { Factory as F, Generator as G, emitter as e };
@@ -1,5 +1,5 @@
1
1
  import { Construct } from 'phecda-core';
2
- import { M as MetaData, h as Meta, E as Emitter } from './types-81be0ba3.js';
2
+ import { M as MetaData, h as Meta, E as Emitter } from './types-CdQey96H.js';
3
3
 
4
4
  declare abstract class Generator {
5
5
  private _path;
@@ -0,0 +1,27 @@
1
+ import { C as ControllerMetaData, h as Meta, i as ControllerMeta } from './types-CdQey96H.mjs';
2
+ import 'phecda-core';
3
+
4
+ declare function HMR(cb: (...args: any) => any): void;
5
+
6
+ declare function resolveDep(ret: any, key: string): any;
7
+ declare function argToReq(params: ControllerMetaData['params'], args: any[], headers: Record<string, any>): any;
8
+
9
+ declare function genClientQueue(key?: string): string;
10
+
11
+ declare function shallowClone(obj: any): any;
12
+ declare function mergeObject(...args: any[]): any;
13
+
14
+ declare function createControllerMetaMap(meta: Meta[], filter: (meta: Meta) => boolean | void): Map<string, Record<string, ControllerMeta>>;
15
+ declare function detectAopDep(meta: Meta[], { guards, interceptors, plugins }?: {
16
+ guards?: string[];
17
+ interceptors?: string[];
18
+ plugins?: string[];
19
+ }, controller?: string): {
20
+ pluginSet: Set<string>;
21
+ guardSet: Set<string>;
22
+ interceptorSet: Set<string>;
23
+ pipeSet: Set<string>;
24
+ filterSet: Set<string>;
25
+ };
26
+
27
+ export { HMR, argToReq, createControllerMetaMap, detectAopDep, genClientQueue, mergeObject, resolveDep, shallowClone };
package/dist/helper.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ControllerMetaData, h as Meta, i as ControllerMeta } from './types-81be0ba3.js';
1
+ import { C as ControllerMetaData, h as Meta, i as ControllerMeta } from './types-CdQey96H.js';
2
2
  import 'phecda-core';
3
3
 
4
4
  declare function HMR(cb: (...args: any) => any): void;
package/dist/helper.js CHANGED
@@ -7,8 +7,8 @@
7
7
 
8
8
 
9
9
 
10
- var _chunkH6NYBVBVjs = require('./chunk-H6NYBVBV.js');
11
- require('./chunk-FNJWO324.js');
10
+ var _chunk6T4UZ4LVjs = require('./chunk-6T4UZ4LV.js');
11
+ require('./chunk-H2FWLKXN.js');
12
12
 
13
13
 
14
14
 
@@ -18,4 +18,4 @@ require('./chunk-FNJWO324.js');
18
18
 
19
19
 
20
20
 
21
- exports.HMR = _chunkH6NYBVBVjs.HMR; exports.argToReq = _chunkH6NYBVBVjs.argToReq; exports.createControllerMetaMap = _chunkH6NYBVBVjs.createControllerMetaMap; exports.detectAopDep = _chunkH6NYBVBVjs.detectAopDep; exports.genClientQueue = _chunkH6NYBVBVjs.genClientQueue; exports.mergeObject = _chunkH6NYBVBVjs.mergeObject; exports.resolveDep = _chunkH6NYBVBVjs.resolveDep; exports.shallowClone = _chunkH6NYBVBVjs.shallowClone;
21
+ exports.HMR = _chunk6T4UZ4LVjs.HMR; exports.argToReq = _chunk6T4UZ4LVjs.argToReq; exports.createControllerMetaMap = _chunk6T4UZ4LVjs.createControllerMetaMap; exports.detectAopDep = _chunk6T4UZ4LVjs.detectAopDep; exports.genClientQueue = _chunk6T4UZ4LVjs.genClientQueue; exports.mergeObject = _chunk6T4UZ4LVjs.mergeObject; exports.resolveDep = _chunk6T4UZ4LVjs.resolveDep; exports.shallowClone = _chunk6T4UZ4LVjs.shallowClone;