phecda-server 6.1.0 → 7.0.0-alpha.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.
- package/assets/ps.json +24 -24
- package/bin/cli.mjs +165 -157
- package/dist/{chunk-NL6QBQAR.js → chunk-7YQ57BQS.js} +21 -22
- package/dist/chunk-GSPBHZBH.js +534 -0
- package/dist/{chunk-J7B24YSE.mjs → chunk-HMVLXNV3.mjs} +5 -14
- package/dist/{chunk-TVT62GIX.js → chunk-J5CFUN4V.js} +8 -1
- package/dist/{chunk-JDV2XJYE.js → chunk-MBCHNDAY.js} +27 -36
- package/dist/{chunk-2CFYUXPM.mjs → chunk-V7EI76QQ.mjs} +136 -141
- package/dist/{chunk-G7TD2VB7.mjs → chunk-WHJ5FALK.mjs} +7 -0
- package/dist/{chunk-3H3T54IC.mjs → chunk-XYVMNY2X.mjs} +4 -5
- package/dist/{core-P1CsH6jz.d.mts → core-BIcUwV18.d.mts} +1 -1
- package/dist/{core-BlN0Spy9.d.ts → core-CYwEPfN4.d.ts} +1 -1
- package/dist/helper.d.mts +4 -6
- package/dist/helper.d.ts +4 -6
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/{server → http}/elysia/index.d.mts +5 -5
- package/dist/{server → http}/elysia/index.d.ts +5 -5
- package/dist/{server → http}/elysia/index.js +80 -62
- package/dist/{server → http}/elysia/index.mjs +50 -32
- package/dist/{server → http}/express/index.d.mts +5 -5
- package/dist/{server → http}/express/index.d.ts +5 -5
- package/dist/{server → http}/express/index.js +71 -55
- package/dist/{server → http}/express/index.mjs +42 -26
- package/dist/{server → http}/fastify/index.d.mts +5 -5
- package/dist/{server → http}/fastify/index.d.ts +5 -5
- package/dist/{server → http}/fastify/index.js +72 -72
- package/dist/{server → http}/fastify/index.mjs +47 -47
- package/dist/{server → http}/h3/index.d.mts +5 -5
- package/dist/{server → http}/h3/index.d.ts +5 -5
- package/dist/http/h3/index.js +160 -0
- package/dist/{server → http}/h3/index.mjs +68 -62
- package/dist/{server → http}/hono/index.d.mts +5 -5
- package/dist/{server → http}/hono/index.d.ts +5 -5
- package/dist/{server → http}/hono/index.js +69 -54
- package/dist/{server → http}/hono/index.mjs +41 -26
- package/dist/{server → http}/hyper-express/index.d.mts +5 -5
- package/dist/{server → http}/hyper-express/index.d.ts +5 -5
- package/dist/{server → http}/hyper-express/index.js +69 -56
- package/dist/{server → http}/hyper-express/index.mjs +41 -28
- package/dist/{server → http}/koa/index.d.mts +5 -5
- package/dist/{server → http}/koa/index.d.ts +5 -5
- package/dist/{server → http}/koa/index.js +71 -55
- package/dist/{server → http}/koa/index.mjs +42 -26
- package/dist/index.d.mts +52 -41
- package/dist/index.d.ts +52 -41
- package/dist/index.js +59 -81
- package/dist/index.mjs +39 -61
- package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
- package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
- package/dist/rpc/bullmq/index.d.mts +6 -6
- package/dist/rpc/bullmq/index.d.ts +6 -6
- package/dist/rpc/bullmq/index.js +24 -24
- package/dist/rpc/bullmq/index.mjs +14 -14
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +25 -21
- package/dist/rpc/kafka/index.mjs +15 -11
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +22 -21
- package/dist/rpc/nats/index.mjs +13 -12
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +23 -22
- package/dist/rpc/rabbitmq/index.mjs +12 -11
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +24 -20
- package/dist/rpc/redis/index.mjs +15 -11
- package/dist/test.d.mts +3 -3
- package/dist/test.d.ts +3 -3
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/{types-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
- package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
- package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
- package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
- package/package.json +23 -23
- package/register/loader.mjs +366 -367
- package/dist/chunk-DVTBLV6I.js +0 -539
- package/dist/server/h3/index.js +0 -154
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkJ5CFUN4Vjs = require('./chunk-J5CFUN4V.js');
|
|
4
4
|
|
|
5
5
|
// src/decorators/param.ts
|
|
6
6
|
var _phecdacore = require('phecda-core');
|
|
@@ -10,42 +10,42 @@ function BaseParam(data) {
|
|
|
10
10
|
_phecdacore.setMeta.call(void 0, target, property, index, data);
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, BaseParam, "BaseParam");
|
|
14
14
|
function Body(key = "") {
|
|
15
15
|
return BaseParam({
|
|
16
16
|
type: "body",
|
|
17
17
|
key
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Body, "Body");
|
|
21
21
|
function Head(key) {
|
|
22
22
|
return BaseParam({
|
|
23
23
|
type: "headers",
|
|
24
24
|
key: key.toLowerCase()
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Head, "Head");
|
|
28
28
|
function Query(key = "") {
|
|
29
29
|
return BaseParam({
|
|
30
30
|
type: "query",
|
|
31
31
|
key
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Query, "Query");
|
|
35
35
|
function Param(key) {
|
|
36
36
|
return BaseParam({
|
|
37
37
|
type: "params",
|
|
38
38
|
key
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Param, "Param");
|
|
42
42
|
function Arg(target, k, index) {
|
|
43
43
|
BaseParam({
|
|
44
44
|
type: "args",
|
|
45
45
|
key: `${index}`
|
|
46
46
|
})(target, k, index);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Arg, "Arg");
|
|
49
49
|
|
|
50
50
|
// src/decorators/aop.ts
|
|
51
51
|
|
|
@@ -56,23 +56,15 @@ function Guard(...guards) {
|
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
function
|
|
59
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Guard, "Guard");
|
|
60
|
+
function Addon(...addons) {
|
|
61
61
|
return (target, property) => {
|
|
62
62
|
_phecdacore.setMeta.call(void 0, target, property, void 0, {
|
|
63
|
-
|
|
63
|
+
addons
|
|
64
64
|
});
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
function Interceptor(...interceptors) {
|
|
69
|
-
return (target, property) => {
|
|
70
|
-
_phecdacore.setMeta.call(void 0, target, property, void 0, {
|
|
71
|
-
interceptors
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
_chunkTVT62GIXjs.__name.call(void 0, Interceptor, "Interceptor");
|
|
67
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Addon, "Addon");
|
|
76
68
|
function Filter(filter) {
|
|
77
69
|
return (target, property) => {
|
|
78
70
|
_phecdacore.setMeta.call(void 0, target, property, void 0, {
|
|
@@ -80,7 +72,7 @@ function Filter(filter) {
|
|
|
80
72
|
});
|
|
81
73
|
};
|
|
82
74
|
}
|
|
83
|
-
|
|
75
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Filter, "Filter");
|
|
84
76
|
function Pipe(pipe) {
|
|
85
77
|
return (target, property, index) => {
|
|
86
78
|
if (typeof index === "number") {
|
|
@@ -94,7 +86,7 @@ function Pipe(pipe) {
|
|
|
94
86
|
});
|
|
95
87
|
};
|
|
96
88
|
}
|
|
97
|
-
|
|
89
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Pipe, "Pipe");
|
|
98
90
|
|
|
99
91
|
// src/decorators/http.ts
|
|
100
92
|
|
|
@@ -108,7 +100,7 @@ function Route(route, type) {
|
|
|
108
100
|
});
|
|
109
101
|
};
|
|
110
102
|
}
|
|
111
|
-
|
|
103
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Route, "Route");
|
|
112
104
|
function Header(headers) {
|
|
113
105
|
return (target, property) => {
|
|
114
106
|
_phecdacore.setMeta.call(void 0, target, property, void 0, {
|
|
@@ -118,31 +110,31 @@ function Header(headers) {
|
|
|
118
110
|
});
|
|
119
111
|
};
|
|
120
112
|
}
|
|
121
|
-
|
|
113
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Header, "Header");
|
|
122
114
|
function Get(route = "") {
|
|
123
115
|
return Route(route, "get");
|
|
124
116
|
}
|
|
125
|
-
|
|
117
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Get, "Get");
|
|
126
118
|
function Post(route = "") {
|
|
127
119
|
return Route(route, "post");
|
|
128
120
|
}
|
|
129
|
-
|
|
121
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Post, "Post");
|
|
130
122
|
function Put(route = "") {
|
|
131
123
|
return Route(route, "put");
|
|
132
124
|
}
|
|
133
|
-
|
|
125
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Put, "Put");
|
|
134
126
|
function Search(route = "") {
|
|
135
127
|
return Route(route, "search");
|
|
136
128
|
}
|
|
137
|
-
|
|
129
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Search, "Search");
|
|
138
130
|
function Patch(route = "") {
|
|
139
131
|
return Route(route, "patch");
|
|
140
132
|
}
|
|
141
|
-
|
|
133
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Patch, "Patch");
|
|
142
134
|
function Delete(route = "") {
|
|
143
135
|
return Route(route, "delete");
|
|
144
136
|
}
|
|
145
|
-
|
|
137
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Delete, "Delete");
|
|
146
138
|
function Controller(prefix = "") {
|
|
147
139
|
return (target) => {
|
|
148
140
|
_phecdacore.setMeta.call(void 0, target, void 0, void 0, {
|
|
@@ -153,7 +145,7 @@ function Controller(prefix = "") {
|
|
|
153
145
|
});
|
|
154
146
|
};
|
|
155
147
|
}
|
|
156
|
-
|
|
148
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Controller, "Controller");
|
|
157
149
|
|
|
158
150
|
// src/decorators/rpc.ts
|
|
159
151
|
|
|
@@ -167,7 +159,7 @@ function Queue(queue = "", isEvent) {
|
|
|
167
159
|
});
|
|
168
160
|
};
|
|
169
161
|
}
|
|
170
|
-
|
|
162
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Queue, "Queue");
|
|
171
163
|
function Rpc() {
|
|
172
164
|
return (target) => {
|
|
173
165
|
_phecdacore.setMeta.call(void 0, target, void 0, void 0, {
|
|
@@ -175,11 +167,11 @@ function Rpc() {
|
|
|
175
167
|
});
|
|
176
168
|
};
|
|
177
169
|
}
|
|
178
|
-
|
|
170
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Rpc, "Rpc");
|
|
179
171
|
|
|
180
172
|
// src/decorators/ctx.ts
|
|
181
173
|
|
|
182
|
-
var Ctx = /* @__PURE__ */
|
|
174
|
+
var Ctx = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (target, property) => {
|
|
183
175
|
_phecdacore.setMeta.call(void 0, target, _phecdacore.SHARE_KEY, void 0, {
|
|
184
176
|
ctxs: [
|
|
185
177
|
property
|
|
@@ -208,8 +200,7 @@ function Define(key, value) {
|
|
|
208
200
|
}
|
|
209
201
|
};
|
|
210
202
|
}
|
|
211
|
-
|
|
212
|
-
|
|
203
|
+
_chunkJ5CFUN4Vjs.__name.call(void 0, Define, "Define");
|
|
213
204
|
|
|
214
205
|
|
|
215
206
|
|
|
@@ -235,4 +226,4 @@ _chunkTVT62GIXjs.__name.call(void 0, Define, "Define");
|
|
|
235
226
|
|
|
236
227
|
|
|
237
228
|
|
|
238
|
-
exports.BaseParam = BaseParam; exports.Body = Body; exports.Head = Head; exports.Query = Query; exports.Param = Param; exports.Arg = Arg; exports.Guard = Guard; exports.
|
|
229
|
+
exports.BaseParam = BaseParam; exports.Body = Body; exports.Head = Head; exports.Query = Query; exports.Param = Param; exports.Arg = Arg; exports.Guard = Guard; exports.Addon = Addon; exports.Filter = Filter; exports.Pipe = Pipe; exports.Route = Route; exports.Header = Header; exports.Get = Get; exports.Post = Post; exports.Put = Put; exports.Search = Search; exports.Patch = Patch; exports.Delete = Delete; exports.Controller = Controller; exports.Queue = Queue; exports.Rpc = Rpc; exports.Ctx = Ctx; exports.Define = Define;
|
|
@@ -5,13 +5,14 @@ import {
|
|
|
5
5
|
LOG_LEVEL,
|
|
6
6
|
__name,
|
|
7
7
|
log
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-WHJ5FALK.mjs";
|
|
9
9
|
|
|
10
10
|
// src/helper.ts
|
|
11
|
-
import
|
|
11
|
+
import pc2 from "picocolors";
|
|
12
12
|
|
|
13
13
|
// src/context.ts
|
|
14
14
|
import Debug from "debug";
|
|
15
|
+
import pc from "picocolors";
|
|
15
16
|
|
|
16
17
|
// src/pipe.ts
|
|
17
18
|
var defaultPipe = /* @__PURE__ */ __name(({ arg }) => {
|
|
@@ -228,143 +229,132 @@ var Context = class _Context {
|
|
|
228
229
|
default: defaultPipe
|
|
229
230
|
};
|
|
230
231
|
static guardRecord = {};
|
|
231
|
-
static
|
|
232
|
-
static pluginRecord = {};
|
|
233
|
-
postInterceptors;
|
|
232
|
+
static addonRecord = {};
|
|
234
233
|
constructor(data) {
|
|
235
234
|
this.data = data;
|
|
236
235
|
if (IS_HMR)
|
|
237
236
|
data._context = this;
|
|
238
237
|
}
|
|
239
|
-
|
|
240
|
-
const {
|
|
241
|
-
const {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
await this.useGuard([
|
|
238
|
+
static getAop(meta, opts) {
|
|
239
|
+
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
240
|
+
const { data: { guards, filter, params, tag, func } } = meta;
|
|
241
|
+
const resolved = {
|
|
242
|
+
guards: [
|
|
245
243
|
...globalGuards,
|
|
246
244
|
...guards
|
|
247
|
-
]
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
245
|
+
],
|
|
246
|
+
pipe: params.map((item) => item.pipe || globalPipe),
|
|
247
|
+
filter: filter || globalFilter
|
|
248
|
+
};
|
|
249
|
+
if (process.env.DEBUG) {
|
|
250
|
+
const { guards: guards2, pipe, filter: filter2 } = resolved;
|
|
251
|
+
debug(`func "${tag}-${func}" aop:
|
|
252
|
+
${pc.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
|
|
253
|
+
${pc.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
|
|
254
|
+
${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
guards: this.getGuards(resolved.guards),
|
|
258
|
+
pipe: this.getPipe(resolved.pipe),
|
|
259
|
+
filter: this.getFilter(resolved.filter)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async run({ guards, filter, pipe }, successCb, failCb) {
|
|
263
|
+
const { meta, moduleMap } = this.data;
|
|
264
|
+
const { paramsType, data: { ctxs, tag, params, func } } = meta;
|
|
265
|
+
try {
|
|
266
|
+
let res;
|
|
267
|
+
const nextHandler = /* @__PURE__ */ __name((index) => {
|
|
268
|
+
return async () => {
|
|
269
|
+
if (index === guards.length) {
|
|
270
|
+
const instance = moduleMap.get(tag);
|
|
271
|
+
if (ctxs) {
|
|
272
|
+
ctxs.forEach((ctx) => instance[ctx] = this.data);
|
|
273
|
+
}
|
|
274
|
+
const args = await Promise.all(params.map((item, i) => pipe[i]({
|
|
275
|
+
arg: resolveDep(this.data[item.type], item.key),
|
|
276
|
+
reflect: paramsType[item.index],
|
|
277
|
+
...item
|
|
278
|
+
}, this.data)));
|
|
279
|
+
res = await instance[func](...args);
|
|
280
|
+
} else {
|
|
281
|
+
let nextPromise;
|
|
282
|
+
async function next() {
|
|
283
|
+
return nextPromise = nextHandler(index + 1)().then((ret2) => {
|
|
284
|
+
if (ret2 !== void 0) {
|
|
285
|
+
debug(`The ${index + 1}th guard on "${tag}-${func}" rewrite the response value.`);
|
|
286
|
+
res = ret2;
|
|
287
|
+
}
|
|
288
|
+
return res;
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
__name(next, "next");
|
|
292
|
+
const ret = await guards[index](this.data, next);
|
|
293
|
+
if (ret !== void 0) {
|
|
294
|
+
res = ret;
|
|
295
|
+
} else {
|
|
296
|
+
if (!nextPromise) await next();
|
|
297
|
+
else await nextPromise;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
259
300
|
};
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
ctxs.forEach((ctx) => instance[ctx] = this.data);
|
|
264
|
-
}
|
|
265
|
-
const returnData = await instance[func](...args);
|
|
266
|
-
const i2 = await this.usePostInterceptor(returnData);
|
|
267
|
-
if (i2 !== void 0) return successCb(i2);
|
|
268
|
-
return successCb(returnData);
|
|
301
|
+
}, "nextHandler");
|
|
302
|
+
await nextHandler(0)();
|
|
303
|
+
return successCb(res);
|
|
269
304
|
} catch (e) {
|
|
270
|
-
const err = await
|
|
305
|
+
const err = await filter(e, this.data);
|
|
271
306
|
return failCb(err);
|
|
272
307
|
}
|
|
273
308
|
}
|
|
274
|
-
|
|
275
|
-
return
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
|
|
279
|
-
} else {
|
|
280
|
-
debug(`Can't find pipe named "${item.pipe}" when handling the ${item.index + 1}th argument of the func "${this.data.func}" on module "${this.data.tag}",use default pipe instead`);
|
|
281
|
-
return _Context.pipeRecord.default(item, this.data);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return _Context.pipeRecord[item.pipe || "default"](item, this.data);
|
|
285
|
-
}));
|
|
286
|
-
}
|
|
287
|
-
useFilter(arg, filter = "default") {
|
|
288
|
-
if (!_Context.filterRecord[filter]) {
|
|
289
|
-
if (IS_STRICT) {
|
|
290
|
-
throw new FrameworkException(`can't find filter named "${filter}"`);
|
|
291
|
-
} else {
|
|
292
|
-
debug(`Can't find filter named "${filter}" when handling func "${this.data.func}" on module "${this.data.tag}",use default filter instead`);
|
|
293
|
-
return _Context.filterRecord.default(arg, this.data);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return _Context.filterRecord[filter](arg, this.data);
|
|
297
|
-
}
|
|
298
|
-
async useGuard(guards) {
|
|
299
|
-
for (const guard of new Set(guards)) {
|
|
300
|
-
if (!(guard in _Context.guardRecord)) {
|
|
301
|
-
if (IS_STRICT) throw new FrameworkException(`Can't find guard named "${guard}"`);
|
|
302
|
-
else debug(`Can't find guard named "${guard}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
if (!await _Context.guardRecord[guard](this.data)) throw new ForbiddenException(`Guard exception--[${guard}]`);
|
|
306
|
-
}
|
|
309
|
+
static getPipe(pipe) {
|
|
310
|
+
return pipe.map((pipe2) => {
|
|
311
|
+
return _Context.pipeRecord[pipe2] || _Context.pipeRecord.default;
|
|
312
|
+
});
|
|
307
313
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const ret = await cb(data);
|
|
311
|
-
if (ret !== void 0) return ret;
|
|
312
|
-
}
|
|
314
|
+
static getFilter(filter = "default") {
|
|
315
|
+
return _Context.filterRecord[filter] || _Context.filterRecord.default;
|
|
313
316
|
}
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
for (const
|
|
317
|
-
if (
|
|
318
|
-
if (IS_STRICT) throw new FrameworkException(`can't find interceptor named "${interceptor}"`);
|
|
319
|
-
else debug(`Can't find interceptor named "${interceptor}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
const interceptRet = await _Context.interceptorRecord[interceptor](this.data);
|
|
323
|
-
if (interceptRet !== void 0) {
|
|
324
|
-
if (typeof interceptRet === "function") cb.push(interceptRet);
|
|
325
|
-
else return interceptRet;
|
|
326
|
-
}
|
|
317
|
+
static getGuards(guards) {
|
|
318
|
+
const ret = [];
|
|
319
|
+
for (const guard of new Set(guards)) {
|
|
320
|
+
if (guard in _Context.guardRecord) ret.push(_Context.guardRecord[guard]);
|
|
327
321
|
}
|
|
328
|
-
|
|
322
|
+
return ret.sort((a, b) => b.priority - a.priority).map((item) => item.value);
|
|
329
323
|
}
|
|
330
|
-
static
|
|
324
|
+
static applyAddons(addons, router, framework) {
|
|
331
325
|
const ret = [];
|
|
332
|
-
for (const
|
|
333
|
-
if (
|
|
334
|
-
if (IS_STRICT) throw new FrameworkException(`can't find middleware named '${m}'`);
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
const plugin = _Context.pluginRecord[m](framework);
|
|
338
|
-
plugin && ret.push(plugin);
|
|
326
|
+
for (const a of new Set(addons)) {
|
|
327
|
+
if (a in _Context.addonRecord) ret.push(_Context.addonRecord[a]);
|
|
339
328
|
}
|
|
340
|
-
|
|
329
|
+
ret.sort((a, b) => b.priority - a.priority).forEach((item) => item.value(router, framework));
|
|
341
330
|
}
|
|
342
331
|
};
|
|
343
|
-
function
|
|
344
|
-
if (Context.
|
|
345
|
-
Context.
|
|
346
|
-
}
|
|
347
|
-
__name(addPlugin, "addPlugin");
|
|
348
|
-
function addPipe(key, handler) {
|
|
349
|
-
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler) log(`overwrite Pipe "${String(key)}"`, "warn");
|
|
350
|
-
Context.pipeRecord[key] = handler;
|
|
332
|
+
function addPipe(key, pipe) {
|
|
333
|
+
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) debug(`overwrite Pipe "${String(key)}"`, "warn");
|
|
334
|
+
Context.pipeRecord[key] = pipe;
|
|
351
335
|
}
|
|
352
336
|
__name(addPipe, "addPipe");
|
|
353
|
-
function addFilter(key,
|
|
354
|
-
if (Context.filterRecord[key] && Context.filterRecord[key] !==
|
|
355
|
-
Context.filterRecord[key] =
|
|
337
|
+
function addFilter(key, filter) {
|
|
338
|
+
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) debug(`overwrite Filter "${String(key)}"`, "warn");
|
|
339
|
+
Context.filterRecord[key] = filter;
|
|
356
340
|
}
|
|
357
341
|
__name(addFilter, "addFilter");
|
|
358
|
-
function addGuard(key,
|
|
359
|
-
if (Context.guardRecord[key] && Context.guardRecord[key] !==
|
|
360
|
-
Context.guardRecord[key] =
|
|
342
|
+
function addGuard(key, guard, priority = 0) {
|
|
343
|
+
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) debug(`overwrite Guard "${String(key)}"`, "warn");
|
|
344
|
+
Context.guardRecord[key] = {
|
|
345
|
+
value: guard,
|
|
346
|
+
priority
|
|
347
|
+
};
|
|
361
348
|
}
|
|
362
349
|
__name(addGuard, "addGuard");
|
|
363
|
-
function
|
|
364
|
-
if (Context.
|
|
365
|
-
Context.
|
|
350
|
+
function addAddon(key, addon, priority = 0) {
|
|
351
|
+
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) debug(`overwrite Addon "${String(key)}"`, "warn");
|
|
352
|
+
Context.addonRecord[key] = {
|
|
353
|
+
value: addon,
|
|
354
|
+
priority
|
|
355
|
+
};
|
|
366
356
|
}
|
|
367
|
-
__name(
|
|
357
|
+
__name(addAddon, "addAddon");
|
|
368
358
|
|
|
369
359
|
// src/hmr.ts
|
|
370
360
|
function HMR(cb) {
|
|
@@ -372,7 +362,7 @@ function HMR(cb) {
|
|
|
372
362
|
}
|
|
373
363
|
__name(HMR, "HMR");
|
|
374
364
|
|
|
375
|
-
// src/
|
|
365
|
+
// src/http/helper.ts
|
|
376
366
|
function resolveDep(ret, key) {
|
|
377
367
|
if (key) return ret?.[key];
|
|
378
368
|
return ret;
|
|
@@ -432,71 +422,77 @@ function createControllerMetaMap(meta, filter) {
|
|
|
432
422
|
return metaMap;
|
|
433
423
|
}
|
|
434
424
|
__name(createControllerMetaMap, "createControllerMetaMap");
|
|
435
|
-
function detectAopDep(meta, { guards,
|
|
436
|
-
const
|
|
425
|
+
function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
426
|
+
const addonSet = /* @__PURE__ */ new Set();
|
|
437
427
|
const guardSet = /* @__PURE__ */ new Set();
|
|
438
|
-
const interceptorSet = /* @__PURE__ */ new Set();
|
|
439
428
|
const pipeSet = /* @__PURE__ */ new Set();
|
|
440
429
|
const filterSet = /* @__PURE__ */ new Set();
|
|
441
430
|
const warningSet = /* @__PURE__ */ new Set();
|
|
442
431
|
function handleMeta() {
|
|
443
|
-
|
|
432
|
+
addonSet.clear();
|
|
444
433
|
guardSet.clear();
|
|
445
|
-
interceptorSet.clear();
|
|
446
434
|
pipeSet.clear();
|
|
447
435
|
filterSet.clear();
|
|
448
436
|
warningSet.clear();
|
|
449
|
-
|
|
450
|
-
|
|
437
|
+
addons?.forEach((item) => {
|
|
438
|
+
addonSet.add(item);
|
|
451
439
|
});
|
|
452
440
|
guards?.forEach((item) => {
|
|
453
441
|
guardSet.add(item);
|
|
454
442
|
});
|
|
455
|
-
interceptors?.forEach((item) => {
|
|
456
|
-
interceptorSet.add(item);
|
|
457
|
-
});
|
|
458
443
|
meta.forEach(({ data }) => {
|
|
459
444
|
if (data.controller !== controller) {
|
|
460
|
-
if (data[controller]) warningSet.add(`
|
|
445
|
+
if (data[controller]) warningSet.add(`Should use ${controller} controller to decorate class "${data.name}" or method "${data.func}"`);
|
|
461
446
|
return;
|
|
462
447
|
}
|
|
463
448
|
if (data.filter) filterSet.add(data.filter);
|
|
464
|
-
data.interceptors.forEach((i) => interceptorSet.add(i));
|
|
465
449
|
data.guards.forEach((i) => guardSet.add(i));
|
|
466
|
-
data.
|
|
450
|
+
data.addons.forEach((i) => addonSet.add(i));
|
|
467
451
|
data.params.forEach((i) => {
|
|
468
452
|
if (i.pipe) pipeSet.add(i.pipe);
|
|
469
453
|
});
|
|
470
454
|
});
|
|
471
|
-
const
|
|
472
|
-
...
|
|
473
|
-
].filter((i) => !Context.
|
|
455
|
+
const missAddons = [
|
|
456
|
+
...addonSet
|
|
457
|
+
].filter((i) => !Context.addonRecord[i]);
|
|
474
458
|
const missGuards = [
|
|
475
459
|
...guardSet
|
|
476
460
|
].filter((i) => !Context.guardRecord[i]);
|
|
477
|
-
const missInterceptors = [
|
|
478
|
-
...interceptorSet
|
|
479
|
-
].filter((i) => !Context.interceptorRecord[i]);
|
|
480
461
|
const missPipes = [
|
|
481
462
|
...pipeSet
|
|
482
463
|
].filter((i) => !Context.pipeRecord[i]);
|
|
483
464
|
const missFilters = [
|
|
484
465
|
...filterSet
|
|
485
466
|
].filter((i) => !Context.filterRecord[i]);
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
if (
|
|
467
|
+
function exit() {
|
|
468
|
+
if (IS_STRICT) process.exit(5);
|
|
469
|
+
}
|
|
470
|
+
__name(exit, "exit");
|
|
471
|
+
if (missAddons.length) {
|
|
472
|
+
log(`${pc2.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
|
|
473
|
+
exit();
|
|
474
|
+
}
|
|
475
|
+
if (missGuards.length) {
|
|
476
|
+
log(`${pc2.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
477
|
+
exit();
|
|
478
|
+
}
|
|
479
|
+
if (missPipes.length) {
|
|
480
|
+
log(`${pc2.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
481
|
+
exit();
|
|
482
|
+
}
|
|
483
|
+
if (missFilters.length) {
|
|
484
|
+
log(`${pc2.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
485
|
+
exit();
|
|
486
|
+
}
|
|
491
487
|
warningSet.forEach((warn) => log(warn, "warn"));
|
|
488
|
+
if (warningSet.size) exit();
|
|
492
489
|
}
|
|
493
490
|
__name(handleMeta, "handleMeta");
|
|
494
491
|
handleMeta();
|
|
495
492
|
HMR(handleMeta);
|
|
496
493
|
return {
|
|
497
|
-
|
|
494
|
+
addonSet,
|
|
498
495
|
guardSet,
|
|
499
|
-
interceptorSet,
|
|
500
496
|
pipeSet,
|
|
501
497
|
filterSet
|
|
502
498
|
};
|
|
@@ -523,11 +519,10 @@ export {
|
|
|
523
519
|
TimerException,
|
|
524
520
|
WorkerException,
|
|
525
521
|
Context,
|
|
526
|
-
addPlugin,
|
|
527
522
|
addPipe,
|
|
528
523
|
addFilter,
|
|
529
524
|
addGuard,
|
|
530
|
-
|
|
525
|
+
addAddon,
|
|
531
526
|
HMR,
|
|
532
527
|
resolveDep,
|
|
533
528
|
argToReq,
|
|
@@ -50,6 +50,12 @@ function log(msg, level = "log") {
|
|
|
50
50
|
console[level](`${pc.magenta("[phecda-server]")} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`);
|
|
51
51
|
}
|
|
52
52
|
__name(log, "log");
|
|
53
|
+
function runMiddleware(ctx, middleware) {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
middleware(ctx.getRequest(), ctx.getResponse(), resolve);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
__name(runMiddleware, "runMiddleware");
|
|
53
59
|
|
|
54
60
|
export {
|
|
55
61
|
__name,
|
|
@@ -62,5 +68,6 @@ export {
|
|
|
62
68
|
setLogger,
|
|
63
69
|
getLogger,
|
|
64
70
|
log,
|
|
71
|
+
runMiddleware,
|
|
65
72
|
Mixin
|
|
66
73
|
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
IS_ONLY_GENERATE,
|
|
4
4
|
__name,
|
|
5
5
|
log
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-WHJ5FALK.mjs";
|
|
7
7
|
|
|
8
8
|
// src/meta.ts
|
|
9
9
|
var Meta = class {
|
|
@@ -23,7 +23,7 @@ import "reflect-metadata";
|
|
|
23
23
|
import EventEmitter from "node:events";
|
|
24
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(Factory)");
|
|
27
27
|
var emitter = new EventEmitter();
|
|
28
28
|
function defaultServerInject() {
|
|
29
29
|
if (!getInject("watcher")) {
|
|
@@ -222,9 +222,8 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
222
222
|
...meta.define
|
|
223
223
|
};
|
|
224
224
|
for (const item of [
|
|
225
|
-
"
|
|
226
|
-
"guards"
|
|
227
|
-
"interceptors"
|
|
225
|
+
"addons",
|
|
226
|
+
"guards"
|
|
228
227
|
]) {
|
|
229
228
|
const set = new Set(baseMeta[item]);
|
|
230
229
|
if (meta[item]) {
|
package/dist/helper.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ControllerMetaData, M as Meta, a as ControllerMeta } from './meta-
|
|
1
|
+
import { C as ControllerMetaData, M as Meta, a as ControllerMeta } from './meta-BXKLFTgG.mjs';
|
|
2
2
|
import 'phecda-core';
|
|
3
3
|
|
|
4
4
|
declare function HMR(cb: (...args: any) => any): void;
|
|
@@ -12,14 +12,12 @@ declare function shallowClone(obj: any): any;
|
|
|
12
12
|
declare function mergeObject(...args: any[]): any;
|
|
13
13
|
|
|
14
14
|
declare function createControllerMetaMap(meta: Meta[], filter: (meta: Meta) => boolean | void): Map<string, Record<string, ControllerMeta>>;
|
|
15
|
-
declare function detectAopDep(meta: Meta[], { guards,
|
|
15
|
+
declare function detectAopDep(meta: Meta[], { guards, addons }?: {
|
|
16
16
|
guards?: string[];
|
|
17
|
-
|
|
18
|
-
plugins?: string[];
|
|
17
|
+
addons?: string[];
|
|
19
18
|
}, controller?: string): {
|
|
20
|
-
|
|
19
|
+
addonSet: Set<string>;
|
|
21
20
|
guardSet: Set<string>;
|
|
22
|
-
interceptorSet: Set<string>;
|
|
23
21
|
pipeSet: Set<string>;
|
|
24
22
|
filterSet: Set<string>;
|
|
25
23
|
};
|