phecda-server 6.0.2 → 6.1.0

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 (72) hide show
  1. package/dist/{chunk-WXFZZZRY.mjs → chunk-2CFYUXPM.mjs} +1 -1
  2. package/dist/{chunk-HDQAT2IM.mjs → chunk-3H3T54IC.mjs} +116 -87
  3. package/dist/{chunk-7SYPUIBY.js → chunk-DVTBLV6I.js} +60 -60
  4. package/dist/{chunk-UXD62LGG.mjs → chunk-G7TD2VB7.mjs} +10 -2
  5. package/dist/{chunk-F3W3NN7F.mjs → chunk-J7B24YSE.mjs} +1 -1
  6. package/dist/{chunk-XCND2QW3.js → chunk-JDV2XJYE.js} +25 -25
  7. package/dist/chunk-NL6QBQAR.js +266 -0
  8. package/dist/{chunk-GHFSIZUO.js → chunk-TVT62GIX.js} +11 -3
  9. package/dist/core-BlN0Spy9.d.ts +47 -0
  10. package/dist/core-P1CsH6jz.d.mts +47 -0
  11. package/dist/helper.js +3 -3
  12. package/dist/helper.mjs +2 -2
  13. package/dist/index.d.mts +6 -5
  14. package/dist/index.d.ts +6 -5
  15. package/dist/index.js +49 -43
  16. package/dist/index.mjs +15 -9
  17. package/dist/rpc/bullmq/index.d.mts +1 -1
  18. package/dist/rpc/bullmq/index.d.ts +1 -1
  19. package/dist/rpc/bullmq/index.js +12 -12
  20. package/dist/rpc/bullmq/index.mjs +2 -2
  21. package/dist/rpc/kafka/index.d.mts +1 -1
  22. package/dist/rpc/kafka/index.d.ts +1 -1
  23. package/dist/rpc/kafka/index.js +12 -12
  24. package/dist/rpc/kafka/index.mjs +2 -2
  25. package/dist/rpc/nats/index.d.mts +1 -1
  26. package/dist/rpc/nats/index.d.ts +1 -1
  27. package/dist/rpc/nats/index.js +11 -11
  28. package/dist/rpc/nats/index.mjs +2 -2
  29. package/dist/rpc/rabbitmq/index.d.mts +1 -1
  30. package/dist/rpc/rabbitmq/index.d.ts +1 -1
  31. package/dist/rpc/rabbitmq/index.js +13 -13
  32. package/dist/rpc/rabbitmq/index.mjs +2 -2
  33. package/dist/rpc/redis/index.d.mts +1 -1
  34. package/dist/rpc/redis/index.d.ts +1 -1
  35. package/dist/rpc/redis/index.js +11 -11
  36. package/dist/rpc/redis/index.mjs +2 -2
  37. package/dist/server/elysia/index.d.mts +1 -1
  38. package/dist/server/elysia/index.d.ts +1 -1
  39. package/dist/server/elysia/index.js +36 -36
  40. package/dist/server/elysia/index.mjs +3 -3
  41. package/dist/server/express/index.d.mts +1 -1
  42. package/dist/server/express/index.d.ts +1 -1
  43. package/dist/server/express/index.js +34 -34
  44. package/dist/server/express/index.mjs +2 -2
  45. package/dist/server/fastify/index.d.mts +1 -1
  46. package/dist/server/fastify/index.d.ts +1 -1
  47. package/dist/server/fastify/index.js +35 -35
  48. package/dist/server/fastify/index.mjs +3 -3
  49. package/dist/server/h3/index.d.mts +1 -1
  50. package/dist/server/h3/index.d.ts +1 -1
  51. package/dist/server/h3/index.js +34 -34
  52. package/dist/server/h3/index.mjs +2 -2
  53. package/dist/server/hono/index.d.mts +1 -1
  54. package/dist/server/hono/index.d.ts +1 -1
  55. package/dist/server/hono/index.js +33 -33
  56. package/dist/server/hono/index.mjs +2 -2
  57. package/dist/server/hyper-express/index.d.mts +1 -1
  58. package/dist/server/hyper-express/index.d.ts +1 -1
  59. package/dist/server/hyper-express/index.js +33 -33
  60. package/dist/server/hyper-express/index.mjs +2 -2
  61. package/dist/server/koa/index.d.mts +1 -1
  62. package/dist/server/koa/index.d.ts +1 -1
  63. package/dist/server/koa/index.js +34 -34
  64. package/dist/server/koa/index.mjs +2 -2
  65. package/dist/test.d.mts +1 -1
  66. package/dist/test.d.ts +1 -1
  67. package/dist/test.js +6 -6
  68. package/dist/test.mjs +2 -2
  69. package/package.json +2 -2
  70. package/dist/chunk-LYEZ6RGX.js +0 -237
  71. package/dist/core-2SNw8m2B.d.mts +0 -30
  72. package/dist/core-BmJJLUqj.d.ts +0 -30
@@ -0,0 +1,266 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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; } var _class;
2
+
3
+
4
+
5
+
6
+ var _chunkTVT62GIXjs = require('./chunk-TVT62GIX.js');
7
+
8
+ // src/meta.ts
9
+ var Meta = class {
10
+ static {
11
+ _chunkTVT62GIXjs.__name.call(void 0, this, "Meta");
12
+ }
13
+
14
+
15
+ constructor(data, paramsType) {
16
+ this.data = data;
17
+ this.paramsType = paramsType;
18
+ }
19
+ };
20
+
21
+ // src/core.ts
22
+ require('reflect-metadata');
23
+ var _events = require('events'); var _events2 = _interopRequireDefault(_events);
24
+ var _phecdacore = require('phecda-core');
25
+ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
26
+ var debug = _debug2.default.call(void 0, "phecda-server(createPhecda)");
27
+ var emitter = new (0, _events2.default)();
28
+ function defaultServerInject() {
29
+ if (!_phecdacore.getInject.call(void 0, "watcher")) {
30
+ _phecdacore.setInject.call(void 0, "watcher", ({ eventName, instance, property, options }) => {
31
+ const fn = typeof instance[property] === "function" ? instance[property].bind(instance) : (v) => instance[property] = v;
32
+ if (_optionalChain([options, 'optionalAccess', _ => _.once])) emitter.once(eventName, fn);
33
+ else emitter.on(eventName, fn);
34
+ return () => {
35
+ emitter.off(eventName, fn);
36
+ };
37
+ });
38
+ }
39
+ }
40
+ _chunkTVT62GIXjs.__name.call(void 0, defaultServerInject, "defaultServerInject");
41
+ var phecdaNamespace = /* @__PURE__ */ new Map();
42
+ var ServerPhecda = (_class = class {
43
+ static {
44
+ _chunkTVT62GIXjs.__name.call(void 0, this, "ServerPhecda");
45
+ }
46
+ __init() {this.moduleMap = /* @__PURE__ */ new Map()}
47
+ __init2() {this.meta = []}
48
+ __init3() {this.modelMap = /* @__PURE__ */ new WeakMap()}
49
+ __init4() {this.modelSet = /* @__PURE__ */ new WeakSet()}
50
+ __init5() {this.dependenceGraph = /* @__PURE__ */ new Map()}
51
+
52
+
53
+
54
+ constructor(options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);
55
+ defaultServerInject();
56
+ const { namespace = "default", parseModule = /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (module) => module, "parseModule"), parseMeta = /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (meta) => meta, "parseMeta"), generators = [] } = options;
57
+ phecdaNamespace.set(namespace, this);
58
+ this.parseMeta = parseMeta;
59
+ this.parseModule = parseModule;
60
+ this.generators = generators;
61
+ }
62
+ async start(models) {
63
+ for (const model of models) await this.buildDepModule(model);
64
+ const generateCode = /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, async () => {
65
+ if (_chunkTVT62GIXjs.IS_HMR) {
66
+ return Promise.all(this.generators.map((generator) => {
67
+ debug(`generate "${generator.name}" code to ${generator.path}`);
68
+ return generator.output(this.meta);
69
+ }));
70
+ }
71
+ }, "generateCode");
72
+ generateCode().then(() => {
73
+ if (_chunkTVT62GIXjs.IS_ONLY_GENERATE) process.exit(4);
74
+ });
75
+ if (_chunkTVT62GIXjs.IS_HMR) {
76
+ if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
77
+ _optionalChain([globalThis, 'access', _2 => _2.__PS_HMR__, 'optionalAccess', _3 => _3.push, 'call', _4 => _4(async (files) => {
78
+ debug("reload files ");
79
+ for (const file of files) {
80
+ const models2 = await Promise.resolve().then(() => _interopRequireWildcard(require(file)));
81
+ for (const i in models2) {
82
+ if (_phecdacore.isPhecda.call(void 0, models2[i])) await this.add(models2[i]);
83
+ }
84
+ }
85
+ generateCode();
86
+ })]);
87
+ }
88
+ }
89
+ async add(Model) {
90
+ const tag = _phecdacore.getTag.call(void 0, Model);
91
+ const oldInstance = await this.del(tag);
92
+ const { module: newModule } = await this.buildDepModule(Model);
93
+ if (oldInstance && this.dependenceGraph.has(tag)) {
94
+ debug(`replace module "${String(tag)}"`);
95
+ [
96
+ ...this.dependenceGraph.get(tag)
97
+ ].forEach((tag2) => {
98
+ const module = this.moduleMap.get(tag2);
99
+ for (const key in module) {
100
+ if (module[key] === oldInstance) module[key] = newModule;
101
+ }
102
+ });
103
+ }
104
+ }
105
+ async del(tag) {
106
+ if (!this.moduleMap.has(tag)) return;
107
+ const module = this.moduleMap.get(tag);
108
+ debug(`unmount module "${String(tag)}"`);
109
+ await _phecdacore.invokeUnmount.call(void 0, module);
110
+ debug(`del module "${String(tag)}"`);
111
+ this.moduleMap.delete(tag);
112
+ this.modelMap.delete(module);
113
+ for (let i = this.meta.length - 1; i >= 0; i--) {
114
+ if (this.meta[i].data.tag === tag) this.meta.splice(i, 1);
115
+ }
116
+ return module;
117
+ }
118
+ async destroy() {
119
+ debug("destroy all");
120
+ for (const [tag] of this.moduleMap) await this.del(tag);
121
+ }
122
+ async buildDepModule(Model) {
123
+ const paramtypes = getParamTypes(Model);
124
+ let module;
125
+ const tag = _phecdacore.getTag.call(void 0, Model);
126
+ if (this.moduleMap.has(tag)) {
127
+ module = this.moduleMap.get(tag);
128
+ if (!module) throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Model}`);
129
+ if (this.modelMap.get(module) !== Model && !this.modelSet.has(Model)) {
130
+ this.modelSet.add(Model);
131
+ if (module instanceof Model) _chunkTVT62GIXjs.log.call(void 0, `Module taged ${String(tag)} has been overridden`);
132
+ else _chunkTVT62GIXjs.log.call(void 0, `Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Model.name}"`, "warn");
133
+ }
134
+ return {
135
+ module,
136
+ tag
137
+ };
138
+ }
139
+ this.moduleMap.set(tag, void 0);
140
+ debug(`instantiate module "${String(tag)}"`);
141
+ if (paramtypes) {
142
+ const paramtypesInstances = [];
143
+ for (const i in paramtypes) {
144
+ const { module: sub, tag: subTag } = await this.buildDepModule(paramtypes[i]);
145
+ paramtypesInstances[i] = sub;
146
+ if (!this.dependenceGraph.has(subTag)) this.dependenceGraph.set(subTag, /* @__PURE__ */ new Set());
147
+ this.dependenceGraph.get(subTag).add(tag);
148
+ }
149
+ module = this.parseModule(new Model(...paramtypesInstances));
150
+ } else {
151
+ module = this.parseModule(new Model());
152
+ }
153
+ this.meta.push(...getMetaFromInstance(module, tag, Model.name).map(this.parseMeta).filter((item) => !!item));
154
+ debug(`init module "${String(tag)}"`);
155
+ if (!_chunkTVT62GIXjs.IS_ONLY_GENERATE) await _phecdacore.invokeInit.call(void 0, module);
156
+ debug(`add module "${String(tag)}"`);
157
+ this.moduleMap.set(tag, module);
158
+ this.modelMap.set(module, Model);
159
+ return {
160
+ module,
161
+ tag
162
+ };
163
+ }
164
+ has(modelOrTag) {
165
+ return this.moduleMap.has(typeof modelOrTag === "function" ? _phecdacore.getTag.call(void 0, modelOrTag) : modelOrTag);
166
+ }
167
+ get(modelOrTag) {
168
+ const tag = typeof modelOrTag === "function" ? _phecdacore.getTag.call(void 0, modelOrTag) : modelOrTag;
169
+ if (!this.has(tag)) throw new Error(`module "${tag.toString()}" doesn't exist`);
170
+ return this.moduleMap.get(tag);
171
+ }
172
+ }, _class);
173
+ async function Factory(models, opts = {}) {
174
+ const phecda = new ServerPhecda(opts);
175
+ await phecda.start(models);
176
+ return phecda;
177
+ }
178
+ _chunkTVT62GIXjs.__name.call(void 0, Factory, "Factory");
179
+ function useS(nsOrModel, namespace) {
180
+ if (!nsOrModel) {
181
+ namespace = "default";
182
+ } else {
183
+ if (typeof nsOrModel === "string") namespace = nsOrModel;
184
+ else if (!namespace) namespace = "default";
185
+ }
186
+ if (!phecdaNamespace.has(namespace)) throw new Error(`namespace "${namespace}" doesn't exist`);
187
+ const serverPhecda = phecdaNamespace.get(namespace);
188
+ if (nsOrModel && typeof nsOrModel !== "string") return serverPhecda.get(nsOrModel);
189
+ else return serverPhecda;
190
+ }
191
+ _chunkTVT62GIXjs.__name.call(void 0, useS, "useS");
192
+ function getMetaFromInstance(instance, tag, name) {
193
+ const propertyKeys = _phecdacore.getMetaKey.call(void 0, instance).filter((item) => typeof item === "string");
194
+ const baseMeta = _phecdacore.getMergedMeta.call(void 0, instance, void 0);
195
+ const ctxs = baseMeta.ctxs;
196
+ return propertyKeys.filter((i) => typeof instance[i] === "function").map((i) => {
197
+ const meta = _phecdacore.getMergedMeta.call(void 0, instance, i);
198
+ const metaData = {
199
+ ...meta,
200
+ name,
201
+ tag,
202
+ func: i
203
+ };
204
+ if (baseMeta.controller) {
205
+ if (typeof tag !== "string") _chunkTVT62GIXjs.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
206
+ metaData.controller = baseMeta.controller;
207
+ metaData[baseMeta.controller] = {
208
+ ...baseMeta[baseMeta.controller],
209
+ ...meta[baseMeta.controller]
210
+ };
211
+ const params = _phecdacore.getMetaParams.call(void 0, instance, i).map((item) => _phecdacore.getMergedMeta.call(void 0, instance, i, item));
212
+ params.forEach((item, index) => {
213
+ if (!item.pipe) item.pipe = meta.pipe || baseMeta.pipe;
214
+ if (!item.define) item.define = {};
215
+ item.index = index;
216
+ });
217
+ metaData.ctxs = ctxs;
218
+ metaData.params = params;
219
+ metaData.filter = meta.filter || baseMeta.filter;
220
+ metaData.define = {
221
+ ...baseMeta.define,
222
+ ...meta.define
223
+ };
224
+ for (const item of [
225
+ "plugins",
226
+ "guards",
227
+ "interceptors"
228
+ ]) {
229
+ const set = new Set(baseMeta[item]);
230
+ if (meta[item]) {
231
+ meta[item].forEach((part) => {
232
+ set.delete(part);
233
+ set.add(part);
234
+ });
235
+ }
236
+ metaData[item] = [
237
+ ...set
238
+ ];
239
+ }
240
+ }
241
+ return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || []);
242
+ });
243
+ }
244
+ _chunkTVT62GIXjs.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
245
+ function deepFreeze(object) {
246
+ Object.freeze(object);
247
+ Object.getOwnPropertyNames(object).forEach((prop) => {
248
+ if (object[prop] !== null && (typeof object[prop] === "object" || typeof object[prop] === "function") && !Object.isFrozen(object[prop])) deepFreeze(object[prop]);
249
+ });
250
+ return object;
251
+ }
252
+ _chunkTVT62GIXjs.__name.call(void 0, deepFreeze, "deepFreeze");
253
+ function getParamTypes(Model, key) {
254
+ return Reflect.getMetadata("design:paramtypes", Model, key);
255
+ }
256
+ _chunkTVT62GIXjs.__name.call(void 0, getParamTypes, "getParamTypes");
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+ exports.Meta = Meta; exports.emitter = emitter; exports.defaultServerInject = defaultServerInject; exports.phecdaNamespace = phecdaNamespace; exports.ServerPhecda = ServerPhecda; exports.Factory = Factory; exports.useS = useS;
@@ -17,13 +17,19 @@ var PS_EXIT_CODE;
17
17
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
18
18
  var _tsmixer = require('ts-mixer');
19
19
  var time;
20
- var internalLogger = console;
20
+ var internalLogger;
21
21
  function setLogger(logger) {
22
22
  internalLogger = logger;
23
23
  }
24
24
  __name(setLogger, "setLogger");
25
+ function getLogger() {
26
+ return internalLogger;
27
+ }
28
+ __name(getLogger, "getLogger");
25
29
  function log(msg, level = "log") {
30
+ if (internalLogger) internalLogger[level](msg);
26
31
  const logLevel = {
32
+ debug: -1,
27
33
  info: 0,
28
34
  log: 1,
29
35
  warn: 2,
@@ -31,6 +37,7 @@ function log(msg, level = "log") {
31
37
  }[level];
32
38
  if (logLevel < LOG_LEVEL) return;
33
39
  const color = {
40
+ debug: "bgMagenta",
34
41
  error: "red",
35
42
  info: "gray",
36
43
  warn: "yellow",
@@ -40,7 +47,7 @@ function log(msg, level = "log") {
40
47
  const current = Date.now();
41
48
  const interval = time && current - time ? `+${current - time}` : "";
42
49
  time = current;
43
- internalLogger[level](`${_picocolors2.default.magenta("[phecda-server]")} ${_picocolors2.default.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${_picocolors2.default[color](msg)} ${_picocolors2.default.gray(interval)}`);
50
+ console[level](`${_picocolors2.default.magenta("[phecda-server]")} ${_picocolors2.default.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${_picocolors2.default[color](msg)} ${_picocolors2.default.gray(interval)}`);
44
51
  }
45
52
  __name(log, "log");
46
53
 
@@ -55,4 +62,5 @@ __name(log, "log");
55
62
 
56
63
 
57
64
 
58
- exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_HMR = IS_HMR; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.LOG_LEVEL = LOG_LEVEL; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.log = log; exports.Mixin = _tsmixer.Mixin;
65
+
66
+ exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_HMR = IS_HMR; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.LOG_LEVEL = LOG_LEVEL; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.getLogger = getLogger; exports.log = log; exports.Mixin = _tsmixer.Mixin;
@@ -0,0 +1,47 @@
1
+ import { Construct } from 'phecda-core';
2
+ import { b as MetaData, M as Meta, E as Emitter } from './meta-KtfiBIde.js';
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
+ interface Options {
15
+ parseModule?: (module: any) => any;
16
+ parseMeta?: (meta: Meta) => Meta | null | undefined;
17
+ generators?: Generator[];
18
+ namespace?: string;
19
+ }
20
+ declare function defaultServerInject(): void;
21
+ declare const phecdaNamespace: Map<string, ServerPhecda>;
22
+ declare class ServerPhecda {
23
+ moduleMap: Map<PropertyKey, any>;
24
+ meta: Meta[];
25
+ modelMap: WeakMap<any, Construct>;
26
+ modelSet: WeakSet<Construct>;
27
+ dependenceGraph: Map<PropertyKey, Set<PropertyKey>>;
28
+ parseModule: (module: any) => any;
29
+ parseMeta: (meta: Meta) => Meta | null | undefined;
30
+ generators: Generator[];
31
+ constructor(options: Options);
32
+ start(models: Construct[]): Promise<void>;
33
+ add(Model: Construct): Promise<void>;
34
+ del(tag: PropertyKey): Promise<any>;
35
+ destroy(): Promise<void>;
36
+ protected buildDepModule(Model: Construct): Promise<{
37
+ module: any;
38
+ tag: PropertyKey;
39
+ }>;
40
+ has(modelOrTag: Construct | PropertyKey): boolean;
41
+ get<Model extends Construct>(modelOrTag: Model | PropertyKey): InstanceType<Model>;
42
+ }
43
+ declare function Factory(models: Construct[], opts?: Options): Promise<ServerPhecda>;
44
+ declare function useS<Model extends Construct>(model: Model, namespace?: string): InstanceType<Model>;
45
+ declare function useS(namespace?: string): ServerPhecda;
46
+
47
+ export { Factory as F, Generator as G, type Options as O, ServerPhecda as S, defaultServerInject as d, emitter as e, phecdaNamespace as p, useS as u };
@@ -0,0 +1,47 @@
1
+ import { Construct } from 'phecda-core';
2
+ import { b as MetaData, M as Meta, E as Emitter } from './meta-KtfiBIde.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
+ interface Options {
15
+ parseModule?: (module: any) => any;
16
+ parseMeta?: (meta: Meta) => Meta | null | undefined;
17
+ generators?: Generator[];
18
+ namespace?: string;
19
+ }
20
+ declare function defaultServerInject(): void;
21
+ declare const phecdaNamespace: Map<string, ServerPhecda>;
22
+ declare class ServerPhecda {
23
+ moduleMap: Map<PropertyKey, any>;
24
+ meta: Meta[];
25
+ modelMap: WeakMap<any, Construct>;
26
+ modelSet: WeakSet<Construct>;
27
+ dependenceGraph: Map<PropertyKey, Set<PropertyKey>>;
28
+ parseModule: (module: any) => any;
29
+ parseMeta: (meta: Meta) => Meta | null | undefined;
30
+ generators: Generator[];
31
+ constructor(options: Options);
32
+ start(models: Construct[]): Promise<void>;
33
+ add(Model: Construct): Promise<void>;
34
+ del(tag: PropertyKey): Promise<any>;
35
+ destroy(): Promise<void>;
36
+ protected buildDepModule(Model: Construct): Promise<{
37
+ module: any;
38
+ tag: PropertyKey;
39
+ }>;
40
+ has(modelOrTag: Construct | PropertyKey): boolean;
41
+ get<Model extends Construct>(modelOrTag: Model | PropertyKey): InstanceType<Model>;
42
+ }
43
+ declare function Factory(models: Construct[], opts?: Options): Promise<ServerPhecda>;
44
+ declare function useS<Model extends Construct>(model: Model, namespace?: string): InstanceType<Model>;
45
+ declare function useS(namespace?: string): ServerPhecda;
46
+
47
+ export { Factory as F, Generator as G, type Options as O, ServerPhecda as S, defaultServerInject as d, emitter as e, phecdaNamespace as p, useS as u };
package/dist/helper.js CHANGED
@@ -7,8 +7,8 @@
7
7
 
8
8
 
9
9
 
10
- var _chunk7SYPUIBYjs = require('./chunk-7SYPUIBY.js');
11
- require('./chunk-GHFSIZUO.js');
10
+ var _chunkDVTBLV6Ijs = require('./chunk-DVTBLV6I.js');
11
+ require('./chunk-TVT62GIX.js');
12
12
 
13
13
 
14
14
 
@@ -18,4 +18,4 @@ require('./chunk-GHFSIZUO.js');
18
18
 
19
19
 
20
20
 
21
- exports.HMR = _chunk7SYPUIBYjs.HMR; exports.argToReq = _chunk7SYPUIBYjs.argToReq; exports.createControllerMetaMap = _chunk7SYPUIBYjs.createControllerMetaMap; exports.detectAopDep = _chunk7SYPUIBYjs.detectAopDep; exports.genClientQueue = _chunk7SYPUIBYjs.genClientQueue; exports.mergeObject = _chunk7SYPUIBYjs.mergeObject; exports.resolveDep = _chunk7SYPUIBYjs.resolveDep; exports.shallowClone = _chunk7SYPUIBYjs.shallowClone;
21
+ exports.HMR = _chunkDVTBLV6Ijs.HMR; exports.argToReq = _chunkDVTBLV6Ijs.argToReq; exports.createControllerMetaMap = _chunkDVTBLV6Ijs.createControllerMetaMap; exports.detectAopDep = _chunkDVTBLV6Ijs.detectAopDep; exports.genClientQueue = _chunkDVTBLV6Ijs.genClientQueue; exports.mergeObject = _chunkDVTBLV6Ijs.mergeObject; exports.resolveDep = _chunkDVTBLV6Ijs.resolveDep; exports.shallowClone = _chunkDVTBLV6Ijs.shallowClone;
package/dist/helper.mjs CHANGED
@@ -7,8 +7,8 @@ import {
7
7
  mergeObject,
8
8
  resolveDep,
9
9
  shallowClone
10
- } from "./chunk-WXFZZZRY.mjs";
11
- import "./chunk-UXD62LGG.mjs";
10
+ } from "./chunk-2CFYUXPM.mjs";
11
+ import "./chunk-G7TD2VB7.mjs";
12
12
  export {
13
13
  HMR,
14
14
  argToReq,
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { B as BaseContext, D as DefaultOptions, C as ControllerMetaData, b as MetaData, E as Emitter, c as BaseError } from './meta-KtfiBIde.mjs';
2
2
  export { g as BaseRequestType, f as BaseReturn, a as ControllerMeta, h as CustomResponse, j as ERROR_SYMBOL, i as ExtractResponse, I as IS_HMR, k as IS_ONLY_GENERATE, l as IS_STRICT, L as LOG_LEVEL, M as Meta, O as OmitFunction, m as PS_EXIT_CODE, P as PickFunc, S as ServiceMetaData, e as ToClientFn, d as ToClientInstance, T as ToClientMap } from './meta-KtfiBIde.mjs';
3
- import { G as Generator } from './core-2SNw8m2B.mjs';
4
- export { F as Factory, O as Options, c as createPhecda, e as emitter, i as isObject } from './core-2SNw8m2B.mjs';
3
+ import { G as Generator } from './core-P1CsH6jz.mjs';
4
+ export { F as Factory, O as Options, S as ServerPhecda, d as defaultServerInject, e as emitter, p as phecdaNamespace, u as useS } from './core-P1CsH6jz.mjs';
5
5
  import { Base } from 'phecda-core';
6
6
  export * from 'phecda-core';
7
7
  import { H as HttpContext } from './types-BvD3B5Ny.mjs';
@@ -221,7 +221,7 @@ declare abstract class PPipe<C extends BaseContext = any> extends ServerBase {
221
221
  declare abstract class PPlugin extends ServerBase {
222
222
  readonly key: PropertyKey;
223
223
  constructor(tag?: string);
224
- abstract use<Plugin = any>(framework: string): Plugin;
224
+ abstract use<Plugin = any>(framework: string): Plugin | undefined;
225
225
  }
226
226
 
227
227
  interface PExtension<C extends BaseContext = any, E extends Exception = Exception> {
@@ -243,8 +243,9 @@ declare class PExtension extends ServerBase {
243
243
  constructor(tag?: string);
244
244
  }
245
245
 
246
- type LogLevel = 'error' | 'info' | 'warn' | 'log';
246
+ type LogLevel = 'error' | 'info' | 'warn' | 'log' | 'debug';
247
247
  declare function setLogger(logger: Record<LogLevel, (msg: string) => void>): void;
248
+ declare function getLogger(): Record<LogLevel, (msg: string) => void>;
248
249
  declare function log(msg: string, level?: LogLevel): void;
249
250
 
250
- export { Arg, BadGatewayException, BadRequestException, BaseContext, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMetaData, Ctx, DefaultOptions, Define, Delete, Emitter, Exception, Filter, type FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, type GuardType, HTTPGenerator, Head, Header, HttpBase, HttpContext, Interceptor, type InterceptorType, InvalidInputException, MetaData, NotFoundException, PExtension, PFilter, PGuard, PInterceptor, PPipe, PPlugin, Param, Patch, PayloadLargeException, Pipe, type PipeArg, type PipeType, Plugin, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, RpcBase, RpcContext, Search, ServerBase, ServiceUnavailableException, TimeoutException, TimerException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addFilter, addGuard, addInterceptor, addPipe, addPlugin, defaultPipe, log, setLogger };
251
+ export { Arg, BadGatewayException, BadRequestException, BaseContext, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMetaData, Ctx, DefaultOptions, Define, Delete, Emitter, Exception, Filter, type FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, type GuardType, HTTPGenerator, Head, Header, HttpBase, HttpContext, Interceptor, type InterceptorType, InvalidInputException, MetaData, NotFoundException, PExtension, PFilter, PGuard, PInterceptor, PPipe, PPlugin, Param, Patch, PayloadLargeException, Pipe, type PipeArg, type PipeType, Plugin, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, RpcBase, RpcContext, Search, ServerBase, ServiceUnavailableException, TimeoutException, TimerException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addFilter, addGuard, addInterceptor, addPipe, addPlugin, defaultPipe, getLogger, log, setLogger };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { B as BaseContext, D as DefaultOptions, C as ControllerMetaData, b as MetaData, E as Emitter, c as BaseError } from './meta-KtfiBIde.js';
2
2
  export { g as BaseRequestType, f as BaseReturn, a as ControllerMeta, h as CustomResponse, j as ERROR_SYMBOL, i as ExtractResponse, I as IS_HMR, k as IS_ONLY_GENERATE, l as IS_STRICT, L as LOG_LEVEL, M as Meta, O as OmitFunction, m as PS_EXIT_CODE, P as PickFunc, S as ServiceMetaData, e as ToClientFn, d as ToClientInstance, T as ToClientMap } from './meta-KtfiBIde.js';
3
- import { G as Generator } from './core-BmJJLUqj.js';
4
- export { F as Factory, O as Options, c as createPhecda, e as emitter, i as isObject } from './core-BmJJLUqj.js';
3
+ import { G as Generator } from './core-BlN0Spy9.js';
4
+ export { F as Factory, O as Options, S as ServerPhecda, d as defaultServerInject, e as emitter, p as phecdaNamespace, u as useS } from './core-BlN0Spy9.js';
5
5
  import { Base } from 'phecda-core';
6
6
  export * from 'phecda-core';
7
7
  import { H as HttpContext } from './types-DIw7B6Up.js';
@@ -221,7 +221,7 @@ declare abstract class PPipe<C extends BaseContext = any> extends ServerBase {
221
221
  declare abstract class PPlugin extends ServerBase {
222
222
  readonly key: PropertyKey;
223
223
  constructor(tag?: string);
224
- abstract use<Plugin = any>(framework: string): Plugin;
224
+ abstract use<Plugin = any>(framework: string): Plugin | undefined;
225
225
  }
226
226
 
227
227
  interface PExtension<C extends BaseContext = any, E extends Exception = Exception> {
@@ -243,8 +243,9 @@ declare class PExtension extends ServerBase {
243
243
  constructor(tag?: string);
244
244
  }
245
245
 
246
- type LogLevel = 'error' | 'info' | 'warn' | 'log';
246
+ type LogLevel = 'error' | 'info' | 'warn' | 'log' | 'debug';
247
247
  declare function setLogger(logger: Record<LogLevel, (msg: string) => void>): void;
248
+ declare function getLogger(): Record<LogLevel, (msg: string) => void>;
248
249
  declare function log(msg: string, level?: LogLevel): void;
249
250
 
250
- export { Arg, BadGatewayException, BadRequestException, BaseContext, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMetaData, Ctx, DefaultOptions, Define, Delete, Emitter, Exception, Filter, type FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, type GuardType, HTTPGenerator, Head, Header, HttpBase, HttpContext, Interceptor, type InterceptorType, InvalidInputException, MetaData, NotFoundException, PExtension, PFilter, PGuard, PInterceptor, PPipe, PPlugin, Param, Patch, PayloadLargeException, Pipe, type PipeArg, type PipeType, Plugin, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, RpcBase, RpcContext, Search, ServerBase, ServiceUnavailableException, TimeoutException, TimerException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addFilter, addGuard, addInterceptor, addPipe, addPlugin, defaultPipe, log, setLogger };
251
+ export { Arg, BadGatewayException, BadRequestException, BaseContext, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMetaData, Ctx, DefaultOptions, Define, Delete, Emitter, Exception, Filter, type FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, type GuardType, HTTPGenerator, Head, Header, HttpBase, HttpContext, Interceptor, type InterceptorType, InvalidInputException, MetaData, NotFoundException, PExtension, PFilter, PGuard, PInterceptor, PPipe, PPlugin, Param, Patch, PayloadLargeException, Pipe, type PipeArg, type PipeType, Plugin, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, RpcBase, RpcContext, Search, ServerBase, ServiceUnavailableException, TimeoutException, TimerException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addFilter, addGuard, addInterceptor, addPipe, addPlugin, defaultPipe, getLogger, log, setLogger };