phecda-server 5.3.2 → 6.0.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.
- package/dist/chunk-2UTKBEZE.mjs +233 -0
- package/dist/{chunk-NT6HEBC6.mjs → chunk-HDQAT2IM.mjs} +63 -62
- package/dist/{chunk-UIKQNJN3.js → chunk-LYEZ6RGX.js} +62 -61
- package/dist/chunk-PALEEADE.js +233 -0
- package/dist/{chunk-RZ7IXJYQ.js → chunk-TZYATAJX.js} +12 -30
- package/dist/{chunk-3IPYLGY2.mjs → chunk-YUXERDQ6.mjs} +13 -31
- package/dist/{core-dx9E5x2N.d.ts → core-Blq8frmr.d.ts} +4 -3
- package/dist/{core-Bc2ENEHX.d.mts → core-D2oL8Ge0.d.mts} +4 -3
- package/dist/helper.js +2 -2
- package/dist/helper.mjs +1 -1
- package/dist/index.d.mts +9 -10
- package/dist/index.d.ts +9 -10
- package/dist/index.js +27 -27
- package/dist/index.mjs +6 -6
- package/dist/rpc/bullmq/index.d.mts +1 -1
- package/dist/rpc/bullmq/index.d.ts +1 -1
- package/dist/rpc/bullmq/index.js +6 -6
- package/dist/rpc/bullmq/index.mjs +1 -1
- package/dist/rpc/kafka/index.d.mts +1 -1
- package/dist/rpc/kafka/index.d.ts +1 -1
- package/dist/rpc/kafka/index.js +5 -5
- package/dist/rpc/kafka/index.mjs +1 -1
- package/dist/rpc/nats/index.d.mts +1 -1
- package/dist/rpc/nats/index.d.ts +1 -1
- package/dist/rpc/nats/index.js +5 -5
- package/dist/rpc/nats/index.mjs +1 -1
- package/dist/rpc/rabbitmq/index.d.mts +1 -1
- package/dist/rpc/rabbitmq/index.d.ts +1 -1
- package/dist/rpc/rabbitmq/index.js +6 -6
- package/dist/rpc/rabbitmq/index.mjs +1 -1
- package/dist/rpc/redis/index.d.mts +1 -1
- package/dist/rpc/redis/index.d.ts +1 -1
- package/dist/rpc/redis/index.js +6 -6
- package/dist/rpc/redis/index.mjs +1 -1
- package/dist/server/elysia/index.d.mts +1 -1
- package/dist/server/elysia/index.d.ts +1 -1
- package/dist/server/elysia/index.js +15 -15
- package/dist/server/elysia/index.mjs +2 -2
- package/dist/server/express/index.d.mts +1 -1
- package/dist/server/express/index.d.ts +1 -1
- package/dist/server/express/index.js +14 -14
- package/dist/server/express/index.mjs +1 -1
- package/dist/server/fastify/index.d.mts +1 -1
- package/dist/server/fastify/index.d.ts +1 -1
- package/dist/server/fastify/index.js +15 -15
- package/dist/server/fastify/index.mjs +2 -2
- package/dist/server/h3/index.d.mts +1 -1
- package/dist/server/h3/index.d.ts +1 -1
- package/dist/server/h3/index.js +12 -12
- package/dist/server/h3/index.mjs +1 -1
- package/dist/server/hono/index.d.mts +1 -1
- package/dist/server/hono/index.d.ts +1 -1
- package/dist/server/hono/index.js +13 -13
- package/dist/server/hono/index.mjs +1 -1
- package/dist/server/hyper-express/index.d.mts +1 -1
- package/dist/server/hyper-express/index.d.ts +1 -1
- package/dist/server/hyper-express/index.js +13 -13
- package/dist/server/hyper-express/index.mjs +1 -1
- package/dist/server/koa/index.d.mts +1 -1
- package/dist/server/koa/index.d.ts +1 -1
- package/dist/server/koa/index.js +14 -14
- package/dist/server/koa/index.mjs +1 -1
- package/dist/test.d.mts +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-2HVTWYS2.js +0 -279
- package/dist/chunk-SXOZVIKW.mjs +0 -279
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-UXD62LGG.mjs";
|
|
4
|
+
|
|
5
|
+
// src/decorators/param.ts
|
|
6
|
+
import { setMeta } from "phecda-core";
|
|
7
|
+
function BaseParam(data) {
|
|
8
|
+
return (target, property, index) => {
|
|
9
|
+
if (!property) return;
|
|
10
|
+
setMeta(target, property, index, data);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
__name(BaseParam, "BaseParam");
|
|
14
|
+
function Body(key = "") {
|
|
15
|
+
return BaseParam({
|
|
16
|
+
type: "body",
|
|
17
|
+
key
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
__name(Body, "Body");
|
|
21
|
+
function Head(key) {
|
|
22
|
+
return BaseParam({
|
|
23
|
+
type: "headers",
|
|
24
|
+
key: key.toLowerCase()
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
__name(Head, "Head");
|
|
28
|
+
function Query(key = "") {
|
|
29
|
+
return BaseParam({
|
|
30
|
+
type: "query",
|
|
31
|
+
key
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
__name(Query, "Query");
|
|
35
|
+
function Param(key) {
|
|
36
|
+
return BaseParam({
|
|
37
|
+
type: "params",
|
|
38
|
+
key
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
__name(Param, "Param");
|
|
42
|
+
function Arg(target, k, index) {
|
|
43
|
+
BaseParam({
|
|
44
|
+
type: "args",
|
|
45
|
+
key: `${index}`
|
|
46
|
+
})(target, k, index);
|
|
47
|
+
}
|
|
48
|
+
__name(Arg, "Arg");
|
|
49
|
+
|
|
50
|
+
// src/decorators/aop.ts
|
|
51
|
+
import { setMeta as setMeta2 } from "phecda-core";
|
|
52
|
+
function Guard(...guards) {
|
|
53
|
+
return (target, property) => {
|
|
54
|
+
setMeta2(target, property, void 0, {
|
|
55
|
+
guards
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
__name(Guard, "Guard");
|
|
60
|
+
function Plugin(...plugins) {
|
|
61
|
+
return (target, property) => {
|
|
62
|
+
setMeta2(target, property, void 0, {
|
|
63
|
+
plugins
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
__name(Plugin, "Plugin");
|
|
68
|
+
function Interceptor(...interceptors) {
|
|
69
|
+
return (target, property) => {
|
|
70
|
+
setMeta2(target, property, void 0, {
|
|
71
|
+
interceptors
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
__name(Interceptor, "Interceptor");
|
|
76
|
+
function Filter(filter) {
|
|
77
|
+
return (target, property) => {
|
|
78
|
+
setMeta2(target, property, void 0, {
|
|
79
|
+
filter
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
__name(Filter, "Filter");
|
|
84
|
+
function Pipe(pipe) {
|
|
85
|
+
return (target, property, index) => {
|
|
86
|
+
if (typeof index === "number") {
|
|
87
|
+
BaseParam({
|
|
88
|
+
pipe
|
|
89
|
+
})(target, property, index);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
setMeta2(target, property, void 0, {
|
|
93
|
+
pipe
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
__name(Pipe, "Pipe");
|
|
98
|
+
|
|
99
|
+
// src/decorators/http.ts
|
|
100
|
+
import { setMeta as setMeta3 } from "phecda-core";
|
|
101
|
+
function Route(route, type) {
|
|
102
|
+
return (target, property) => {
|
|
103
|
+
setMeta3(target, property, void 0, {
|
|
104
|
+
http: {
|
|
105
|
+
route,
|
|
106
|
+
type
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
__name(Route, "Route");
|
|
112
|
+
function Header(headers) {
|
|
113
|
+
return (target, property) => {
|
|
114
|
+
setMeta3(target, property, void 0, {
|
|
115
|
+
http: {
|
|
116
|
+
headers
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
__name(Header, "Header");
|
|
122
|
+
function Get(route = "") {
|
|
123
|
+
return Route(route, "get");
|
|
124
|
+
}
|
|
125
|
+
__name(Get, "Get");
|
|
126
|
+
function Post(route = "") {
|
|
127
|
+
return Route(route, "post");
|
|
128
|
+
}
|
|
129
|
+
__name(Post, "Post");
|
|
130
|
+
function Put(route = "") {
|
|
131
|
+
return Route(route, "put");
|
|
132
|
+
}
|
|
133
|
+
__name(Put, "Put");
|
|
134
|
+
function Patch(route = "") {
|
|
135
|
+
return Route(route, "patch");
|
|
136
|
+
}
|
|
137
|
+
__name(Patch, "Patch");
|
|
138
|
+
function Delete(route = "") {
|
|
139
|
+
return Route(route, "delete");
|
|
140
|
+
}
|
|
141
|
+
__name(Delete, "Delete");
|
|
142
|
+
function Controller(prefix = "") {
|
|
143
|
+
return (target) => {
|
|
144
|
+
setMeta3(target, void 0, void 0, {
|
|
145
|
+
controller: "http",
|
|
146
|
+
http: {
|
|
147
|
+
prefix
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
__name(Controller, "Controller");
|
|
153
|
+
|
|
154
|
+
// src/decorators/rpc.ts
|
|
155
|
+
import { setMeta as setMeta4 } from "phecda-core";
|
|
156
|
+
function Queue(queue = "", isEvent) {
|
|
157
|
+
return (target, property) => {
|
|
158
|
+
setMeta4(target, property, void 0, {
|
|
159
|
+
rpc: {
|
|
160
|
+
queue,
|
|
161
|
+
isEvent
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
__name(Queue, "Queue");
|
|
167
|
+
function Rpc() {
|
|
168
|
+
return (target) => {
|
|
169
|
+
setMeta4(target, void 0, void 0, {
|
|
170
|
+
controller: "rpc"
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
__name(Rpc, "Rpc");
|
|
175
|
+
|
|
176
|
+
// src/decorators/ctx.ts
|
|
177
|
+
import { SHARE_KEY, setMeta as setMeta5 } from "phecda-core";
|
|
178
|
+
var Ctx = /* @__PURE__ */ __name((target, property) => {
|
|
179
|
+
setMeta5(target, SHARE_KEY, void 0, {
|
|
180
|
+
ctxs: [
|
|
181
|
+
property
|
|
182
|
+
]
|
|
183
|
+
});
|
|
184
|
+
}, "Ctx");
|
|
185
|
+
function Define(key, value) {
|
|
186
|
+
return (target, property, index) => {
|
|
187
|
+
if (typeof index === "number") {
|
|
188
|
+
setMeta5(target, property, void 0, {
|
|
189
|
+
params: [
|
|
190
|
+
{
|
|
191
|
+
define: {
|
|
192
|
+
[key]: value
|
|
193
|
+
},
|
|
194
|
+
index
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
} else {
|
|
199
|
+
setMeta5(target, property, void 0, {
|
|
200
|
+
define: {
|
|
201
|
+
[key]: value
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
__name(Define, "Define");
|
|
208
|
+
|
|
209
|
+
export {
|
|
210
|
+
BaseParam,
|
|
211
|
+
Body,
|
|
212
|
+
Head,
|
|
213
|
+
Query,
|
|
214
|
+
Param,
|
|
215
|
+
Arg,
|
|
216
|
+
Guard,
|
|
217
|
+
Plugin,
|
|
218
|
+
Interceptor,
|
|
219
|
+
Filter,
|
|
220
|
+
Pipe,
|
|
221
|
+
Route,
|
|
222
|
+
Header,
|
|
223
|
+
Get,
|
|
224
|
+
Post,
|
|
225
|
+
Put,
|
|
226
|
+
Patch,
|
|
227
|
+
Delete,
|
|
228
|
+
Controller,
|
|
229
|
+
Queue,
|
|
230
|
+
Rpc,
|
|
231
|
+
Ctx,
|
|
232
|
+
Define
|
|
233
|
+
};
|
|
@@ -21,11 +21,11 @@ var Meta = class {
|
|
|
21
21
|
// src/core.ts
|
|
22
22
|
import "reflect-metadata";
|
|
23
23
|
import EventEmitter from "node:events";
|
|
24
|
-
import {
|
|
24
|
+
import { getInject, getMergedMeta, getMetaKey, getMetaParams, getTag, invokeInit, invokeUnmount, isPhecda, setInject } from "phecda-core";
|
|
25
25
|
import Debug from "debug";
|
|
26
|
-
var debug = Debug("phecda-server(
|
|
26
|
+
var debug = Debug("phecda-server(createPhecda)");
|
|
27
27
|
var emitter = new EventEmitter();
|
|
28
|
-
async function
|
|
28
|
+
async function createPhecda(models, opts = {}) {
|
|
29
29
|
const moduleMap = /* @__PURE__ */ new Map();
|
|
30
30
|
const meta = [];
|
|
31
31
|
const modelMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -33,8 +33,8 @@ async function Factory(models, opts = {}) {
|
|
|
33
33
|
const dependenceGraph = /* @__PURE__ */ new Map();
|
|
34
34
|
const { parseModule = /* @__PURE__ */ __name((module) => module, "parseModule"), parseMeta = /* @__PURE__ */ __name((meta2) => meta2, "parseMeta"), generators } = opts;
|
|
35
35
|
if (!getInject("watcher")) {
|
|
36
|
-
setInject("watcher", ({ eventName, instance,
|
|
37
|
-
const fn = typeof instance[
|
|
36
|
+
setInject("watcher", ({ eventName, instance, property, options }) => {
|
|
37
|
+
const fn = typeof instance[property] === "function" ? instance[property].bind(instance) : (v) => instance[property] = v;
|
|
38
38
|
if (options?.once) emitter.once(eventName, fn);
|
|
39
39
|
else emitter.on(eventName, fn);
|
|
40
40
|
return () => {
|
|
@@ -46,7 +46,7 @@ async function Factory(models, opts = {}) {
|
|
|
46
46
|
if (!moduleMap.has(tag)) return;
|
|
47
47
|
const module = moduleMap.get(tag);
|
|
48
48
|
debug(`unmount module "${String(tag)}"`);
|
|
49
|
-
await
|
|
49
|
+
await invokeUnmount(module);
|
|
50
50
|
debug(`del module "${String(tag)}"`);
|
|
51
51
|
moduleMap.delete(tag);
|
|
52
52
|
modelMap.delete(module);
|
|
@@ -111,7 +111,7 @@ async function Factory(models, opts = {}) {
|
|
|
111
111
|
}
|
|
112
112
|
meta.push(...getMetaFromInstance(module, tag, Model.name).map(parseMeta).filter((item) => !!item));
|
|
113
113
|
debug(`init module "${String(tag)}"`);
|
|
114
|
-
if (!IS_ONLY_GENERATE) await
|
|
114
|
+
if (!IS_ONLY_GENERATE) await invokeInit(module);
|
|
115
115
|
debug(`add module "${String(tag)}"`);
|
|
116
116
|
moduleMap.set(tag, module);
|
|
117
117
|
modelMap.set(module, Model);
|
|
@@ -156,81 +156,82 @@ async function Factory(models, opts = {}) {
|
|
|
156
156
|
destroy
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
__name(
|
|
159
|
+
__name(createPhecda, "createPhecda");
|
|
160
|
+
var Factory = createPhecda;
|
|
160
161
|
function getMetaFromInstance(instance, tag, name) {
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
...state,
|
|
162
|
+
const propertyKeys = getMetaKey(instance).filter((item) => typeof item === "string");
|
|
163
|
+
const baseMeta = getMergedMeta(instance, void 0);
|
|
164
|
+
const ctxs = baseMeta.ctxs;
|
|
165
|
+
return propertyKeys.filter((i) => typeof instance[i] === "function").map((i) => {
|
|
166
|
+
const meta = getMergedMeta(instance, i);
|
|
167
|
+
const metaData = {
|
|
168
|
+
...meta,
|
|
169
169
|
name,
|
|
170
170
|
tag,
|
|
171
171
|
func: i
|
|
172
172
|
};
|
|
173
|
-
if (
|
|
173
|
+
if (baseMeta.controller) {
|
|
174
174
|
if (typeof tag !== "string") log(`can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
...
|
|
179
|
-
...state[baseState.controller]
|
|
175
|
+
metaData.controller = baseMeta.controller;
|
|
176
|
+
metaData[baseMeta.controller] = {
|
|
177
|
+
...baseMeta[baseMeta.controller],
|
|
178
|
+
...meta[baseMeta.controller]
|
|
180
179
|
};
|
|
181
|
-
const params =
|
|
182
|
-
|
|
183
|
-
if (!
|
|
184
|
-
if (!
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
...
|
|
193
|
-
...state.define
|
|
180
|
+
const params = getMetaParams(instance, i).map((item) => getMergedMeta(instance, i, item));
|
|
181
|
+
params.forEach((item, index) => {
|
|
182
|
+
if (!item.pipe) item.pipe = meta.pipe || baseMeta.pipe;
|
|
183
|
+
if (!item.define) item.define = {};
|
|
184
|
+
item.index = index;
|
|
185
|
+
});
|
|
186
|
+
metaData.ctxs = ctxs;
|
|
187
|
+
metaData.params = params;
|
|
188
|
+
metaData.filter = meta.filter || baseMeta.filter;
|
|
189
|
+
metaData.define = {
|
|
190
|
+
...baseMeta.define,
|
|
191
|
+
...meta.define
|
|
194
192
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
])
|
|
212
|
-
];
|
|
193
|
+
for (const item of [
|
|
194
|
+
"plugins",
|
|
195
|
+
"guards",
|
|
196
|
+
"interceptors"
|
|
197
|
+
]) {
|
|
198
|
+
const set = new Set(baseMeta[item]);
|
|
199
|
+
if (meta[item]) {
|
|
200
|
+
meta[item].forEach((part) => {
|
|
201
|
+
set.delete(part);
|
|
202
|
+
set.add(part);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
metaData[item] = [
|
|
206
|
+
...set
|
|
207
|
+
];
|
|
208
|
+
}
|
|
213
209
|
}
|
|
214
|
-
return new Meta(
|
|
210
|
+
return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || []);
|
|
215
211
|
});
|
|
216
212
|
}
|
|
217
213
|
__name(getMetaFromInstance, "getMetaFromInstance");
|
|
214
|
+
function deepFreeze(object) {
|
|
215
|
+
Object.freeze(object);
|
|
216
|
+
Object.getOwnPropertyNames(object).forEach((prop) => {
|
|
217
|
+
if (object[prop] !== null && (typeof object[prop] === "object" || typeof object[prop] === "function") && !Object.isFrozen(object[prop])) deepFreeze(object[prop]);
|
|
218
|
+
});
|
|
219
|
+
return object;
|
|
220
|
+
}
|
|
221
|
+
__name(deepFreeze, "deepFreeze");
|
|
218
222
|
function getParamTypes(Model, key) {
|
|
219
223
|
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
220
224
|
}
|
|
221
225
|
__name(getParamTypes, "getParamTypes");
|
|
222
|
-
function
|
|
223
|
-
|
|
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();
|
|
226
|
+
function isObject(o) {
|
|
227
|
+
return Object.prototype.toString.call(o) === "[object Object]";
|
|
227
228
|
}
|
|
228
|
-
__name(
|
|
229
|
-
var createPhecda = Factory;
|
|
229
|
+
__name(isObject, "isObject");
|
|
230
230
|
|
|
231
231
|
export {
|
|
232
232
|
Meta,
|
|
233
233
|
emitter,
|
|
234
|
+
createPhecda,
|
|
234
235
|
Factory,
|
|
235
|
-
|
|
236
|
+
isObject
|
|
236
237
|
};
|
|
@@ -23,9 +23,9 @@ require('reflect-metadata');
|
|
|
23
23
|
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
24
24
|
var _phecdacore = require('phecda-core');
|
|
25
25
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
26
|
-
var debug = _debug2.default.call(void 0, "phecda-server(
|
|
26
|
+
var debug = _debug2.default.call(void 0, "phecda-server(createPhecda)");
|
|
27
27
|
var emitter = new (0, _events2.default)();
|
|
28
|
-
async function
|
|
28
|
+
async function createPhecda(models, opts = {}) {
|
|
29
29
|
const moduleMap = /* @__PURE__ */ new Map();
|
|
30
30
|
const meta = [];
|
|
31
31
|
const modelMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -33,8 +33,8 @@ async function Factory(models, opts = {}) {
|
|
|
33
33
|
const dependenceGraph = /* @__PURE__ */ new Map();
|
|
34
34
|
const { parseModule = /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (module) => module, "parseModule"), parseMeta = /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (meta2) => meta2, "parseMeta"), generators } = opts;
|
|
35
35
|
if (!_phecdacore.getInject.call(void 0, "watcher")) {
|
|
36
|
-
_phecdacore.setInject.call(void 0, "watcher", ({ eventName, instance,
|
|
37
|
-
const fn = typeof instance[
|
|
36
|
+
_phecdacore.setInject.call(void 0, "watcher", ({ eventName, instance, property, options }) => {
|
|
37
|
+
const fn = typeof instance[property] === "function" ? instance[property].bind(instance) : (v) => instance[property] = v;
|
|
38
38
|
if (_optionalChain([options, 'optionalAccess', _ => _.once])) emitter.once(eventName, fn);
|
|
39
39
|
else emitter.on(eventName, fn);
|
|
40
40
|
return () => {
|
|
@@ -46,7 +46,7 @@ async function Factory(models, opts = {}) {
|
|
|
46
46
|
if (!moduleMap.has(tag)) return;
|
|
47
47
|
const module = moduleMap.get(tag);
|
|
48
48
|
debug(`unmount module "${String(tag)}"`);
|
|
49
|
-
await _phecdacore.
|
|
49
|
+
await _phecdacore.invokeUnmount.call(void 0, module);
|
|
50
50
|
debug(`del module "${String(tag)}"`);
|
|
51
51
|
moduleMap.delete(tag);
|
|
52
52
|
modelMap.delete(module);
|
|
@@ -111,7 +111,7 @@ async function Factory(models, opts = {}) {
|
|
|
111
111
|
}
|
|
112
112
|
meta.push(...getMetaFromInstance(module, tag, Model.name).map(parseMeta).filter((item) => !!item));
|
|
113
113
|
debug(`init module "${String(tag)}"`);
|
|
114
|
-
if (!_chunkGHFSIZUOjs.IS_ONLY_GENERATE) await _phecdacore.
|
|
114
|
+
if (!_chunkGHFSIZUOjs.IS_ONLY_GENERATE) await _phecdacore.invokeInit.call(void 0, module);
|
|
115
115
|
debug(`add module "${String(tag)}"`);
|
|
116
116
|
moduleMap.set(tag, module);
|
|
117
117
|
modelMap.set(module, Model);
|
|
@@ -156,81 +156,82 @@ async function Factory(models, opts = {}) {
|
|
|
156
156
|
destroy
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
_chunkGHFSIZUOjs.__name.call(void 0,
|
|
159
|
+
_chunkGHFSIZUOjs.__name.call(void 0, createPhecda, "createPhecda");
|
|
160
|
+
var Factory = createPhecda;
|
|
160
161
|
function getMetaFromInstance(instance, tag, name) {
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
...state,
|
|
162
|
+
const propertyKeys = _phecdacore.getMetaKey.call(void 0, instance).filter((item) => typeof item === "string");
|
|
163
|
+
const baseMeta = _phecdacore.getMergedMeta.call(void 0, instance, void 0);
|
|
164
|
+
const ctxs = baseMeta.ctxs;
|
|
165
|
+
return propertyKeys.filter((i) => typeof instance[i] === "function").map((i) => {
|
|
166
|
+
const meta = _phecdacore.getMergedMeta.call(void 0, instance, i);
|
|
167
|
+
const metaData = {
|
|
168
|
+
...meta,
|
|
169
169
|
name,
|
|
170
170
|
tag,
|
|
171
171
|
func: i
|
|
172
172
|
};
|
|
173
|
-
if (
|
|
173
|
+
if (baseMeta.controller) {
|
|
174
174
|
if (typeof tag !== "string") _chunkGHFSIZUOjs.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
...
|
|
179
|
-
...state[baseState.controller]
|
|
175
|
+
metaData.controller = baseMeta.controller;
|
|
176
|
+
metaData[baseMeta.controller] = {
|
|
177
|
+
...baseMeta[baseMeta.controller],
|
|
178
|
+
...meta[baseMeta.controller]
|
|
180
179
|
};
|
|
181
|
-
const params =
|
|
182
|
-
|
|
183
|
-
if (!
|
|
184
|
-
if (!
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
...
|
|
193
|
-
...state.define
|
|
180
|
+
const params = _phecdacore.getMetaParams.call(void 0, instance, i).map((item) => _phecdacore.getMergedMeta.call(void 0, instance, i, item));
|
|
181
|
+
params.forEach((item, index) => {
|
|
182
|
+
if (!item.pipe) item.pipe = meta.pipe || baseMeta.pipe;
|
|
183
|
+
if (!item.define) item.define = {};
|
|
184
|
+
item.index = index;
|
|
185
|
+
});
|
|
186
|
+
metaData.ctxs = ctxs;
|
|
187
|
+
metaData.params = params;
|
|
188
|
+
metaData.filter = meta.filter || baseMeta.filter;
|
|
189
|
+
metaData.define = {
|
|
190
|
+
...baseMeta.define,
|
|
191
|
+
...meta.define
|
|
194
192
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
])
|
|
212
|
-
];
|
|
193
|
+
for (const item of [
|
|
194
|
+
"plugins",
|
|
195
|
+
"guards",
|
|
196
|
+
"interceptors"
|
|
197
|
+
]) {
|
|
198
|
+
const set = new Set(baseMeta[item]);
|
|
199
|
+
if (meta[item]) {
|
|
200
|
+
meta[item].forEach((part) => {
|
|
201
|
+
set.delete(part);
|
|
202
|
+
set.add(part);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
metaData[item] = [
|
|
206
|
+
...set
|
|
207
|
+
];
|
|
208
|
+
}
|
|
213
209
|
}
|
|
214
|
-
return new Meta(
|
|
210
|
+
return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || []);
|
|
215
211
|
});
|
|
216
212
|
}
|
|
217
213
|
_chunkGHFSIZUOjs.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
|
|
214
|
+
function deepFreeze(object) {
|
|
215
|
+
Object.freeze(object);
|
|
216
|
+
Object.getOwnPropertyNames(object).forEach((prop) => {
|
|
217
|
+
if (object[prop] !== null && (typeof object[prop] === "object" || typeof object[prop] === "function") && !Object.isFrozen(object[prop])) deepFreeze(object[prop]);
|
|
218
|
+
});
|
|
219
|
+
return object;
|
|
220
|
+
}
|
|
221
|
+
_chunkGHFSIZUOjs.__name.call(void 0, deepFreeze, "deepFreeze");
|
|
218
222
|
function getParamTypes(Model, key) {
|
|
219
223
|
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
220
224
|
}
|
|
221
225
|
_chunkGHFSIZUOjs.__name.call(void 0, getParamTypes, "getParamTypes");
|
|
222
|
-
function
|
|
223
|
-
|
|
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();
|
|
226
|
+
function isObject(o) {
|
|
227
|
+
return Object.prototype.toString.call(o) === "[object Object]";
|
|
227
228
|
}
|
|
228
|
-
_chunkGHFSIZUOjs.__name.call(void 0,
|
|
229
|
-
|
|
229
|
+
_chunkGHFSIZUOjs.__name.call(void 0, isObject, "isObject");
|
|
230
|
+
|
|
230
231
|
|
|
231
232
|
|
|
232
233
|
|
|
233
234
|
|
|
234
235
|
|
|
235
236
|
|
|
236
|
-
exports.Meta = Meta; exports.emitter = emitter; exports.Factory = Factory; exports.
|
|
237
|
+
exports.Meta = Meta; exports.emitter = emitter; exports.createPhecda = createPhecda; exports.Factory = Factory; exports.isObject = isObject;
|