phecda-server 5.0.0-beta.24 → 5.0.0-beta.26
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-3HC6NOU4.mjs +429 -0
- package/dist/chunk-4PPLKCJH.js +429 -0
- package/dist/{chunk-MUTWLASF.mjs → chunk-A5ZVLFVC.mjs} +11 -4
- package/dist/chunk-CBOR4TIF.mjs +15 -0
- package/dist/{chunk-6UJL6PS3.mjs → chunk-CWWDF2XM.mjs} +1 -3
- package/dist/{chunk-PC6CFB6S.js → chunk-JCJY474C.js} +2 -4
- package/dist/{chunk-2TLXS2XO.js → chunk-JLCVUZMA.js} +25 -27
- package/dist/{chunk-XCXOCS2Z.js → chunk-LEP6MMFD.js} +3 -3
- package/dist/chunk-MNU4PVTO.mjs +14 -0
- package/dist/chunk-NFXZ2GOU.js +15 -0
- package/dist/{chunk-BZFD4POH.js → chunk-NGIT3MFT.js} +61 -54
- package/dist/{chunk-LISNM5WU.mjs → chunk-Q22XENNV.mjs} +1 -1
- package/dist/{chunk-O7NCAS3L.mjs → chunk-R32D5D5N.mjs} +7 -9
- package/dist/chunk-XDKIHIO7.js +14 -0
- package/dist/{core-510d1263.d.ts → core-cee9c690.d.ts} +6 -5
- package/dist/helper-290e001c.d.ts +12 -0
- package/dist/helper-9e206c66.d.ts +12 -0
- package/dist/index.d.ts +14 -9
- package/dist/index.js +32 -383
- package/dist/index.mjs +43 -394
- package/dist/rpc/bullmq/index.d.ts +18 -0
- package/dist/rpc/bullmq/index.js +225 -0
- package/dist/rpc/bullmq/index.mjs +225 -0
- package/dist/rpc/kafka/index.d.ts +6 -9
- package/dist/rpc/kafka/index.js +115 -86
- package/dist/rpc/kafka/index.mjs +113 -84
- package/dist/rpc/nats/index.d.ts +16 -0
- package/dist/rpc/nats/index.js +205 -0
- package/dist/rpc/nats/index.mjs +205 -0
- package/dist/rpc/rabbitmq/index.d.ts +5 -8
- package/dist/rpc/rabbitmq/index.js +107 -58
- package/dist/rpc/rabbitmq/index.mjs +105 -56
- package/dist/rpc/redis/index.d.ts +5 -8
- package/dist/rpc/redis/index.js +123 -70
- package/dist/rpc/redis/index.mjs +121 -68
- package/dist/server/express/index.d.ts +4 -9
- package/dist/server/express/index.js +63 -52
- package/dist/server/express/index.mjs +46 -35
- package/dist/server/fastify/index.d.ts +7 -10
- package/dist/server/fastify/index.js +74 -51
- package/dist/server/fastify/index.mjs +57 -34
- package/dist/server/h3/index.d.ts +4 -4
- package/dist/server/h3/index.js +59 -48
- package/dist/server/h3/index.mjs +45 -34
- package/dist/server/hyper-express/index.d.ts +4 -9
- package/dist/server/hyper-express/index.js +61 -50
- package/dist/server/hyper-express/index.mjs +44 -33
- package/dist/server/koa/index.d.ts +4 -9
- package/dist/server/koa/index.js +64 -53
- package/dist/server/koa/index.mjs +47 -36
- package/dist/test.d.ts +1 -1
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/package.json +21 -2
- package/register/loader.mjs +69 -24
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Context,
|
|
3
|
+
addFilter,
|
|
4
|
+
addGuard,
|
|
5
|
+
addInterceptor,
|
|
6
|
+
addPipe,
|
|
7
|
+
addPlugin
|
|
8
|
+
} from "./chunk-A5ZVLFVC.mjs";
|
|
9
|
+
import {
|
|
10
|
+
UNMOUNT_SYMBOL,
|
|
11
|
+
__name
|
|
12
|
+
} from "./chunk-CWWDF2XM.mjs";
|
|
13
|
+
|
|
14
|
+
// src/decorators/index.ts
|
|
15
|
+
import { SHARE_KEY as SHARE_KEY3, getOwnState as getOwnState4, set, setState as setState4, setStateKey as setStateKey4 } from "phecda-core";
|
|
16
|
+
|
|
17
|
+
// src/decorators/param.ts
|
|
18
|
+
import { getOwnState, setState, setStateKey } from "phecda-core";
|
|
19
|
+
function BaseParam(type, key) {
|
|
20
|
+
return (target, k, index) => {
|
|
21
|
+
setStateKey(target, k);
|
|
22
|
+
const state = getOwnState(target, k);
|
|
23
|
+
if (!state.params)
|
|
24
|
+
state.params = [];
|
|
25
|
+
const existItem = state.params.find((item) => item.index === index);
|
|
26
|
+
if (existItem)
|
|
27
|
+
Object.assign(existItem, {
|
|
28
|
+
type,
|
|
29
|
+
key
|
|
30
|
+
});
|
|
31
|
+
else
|
|
32
|
+
state.params.push({
|
|
33
|
+
type,
|
|
34
|
+
key,
|
|
35
|
+
index
|
|
36
|
+
});
|
|
37
|
+
setState(target, k, state);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
__name(BaseParam, "BaseParam");
|
|
41
|
+
function Pipe(key, opts) {
|
|
42
|
+
return (target, k, index) => {
|
|
43
|
+
setStateKey(target, k);
|
|
44
|
+
const state = getOwnState(target, k);
|
|
45
|
+
if (!state.params)
|
|
46
|
+
state.params = [];
|
|
47
|
+
const existItem = state.params.find((item) => item.index === index);
|
|
48
|
+
if (existItem)
|
|
49
|
+
Object.assign(existItem, {
|
|
50
|
+
pipe: key,
|
|
51
|
+
pipeOpts: opts
|
|
52
|
+
});
|
|
53
|
+
else
|
|
54
|
+
state.params.push({
|
|
55
|
+
pipe: key,
|
|
56
|
+
pipeOpts: opts,
|
|
57
|
+
index
|
|
58
|
+
});
|
|
59
|
+
setState(target, k, state);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
__name(Pipe, "Pipe");
|
|
63
|
+
function Body(key = "") {
|
|
64
|
+
return BaseParam("body", key);
|
|
65
|
+
}
|
|
66
|
+
__name(Body, "Body");
|
|
67
|
+
function Head(key) {
|
|
68
|
+
return BaseParam("headers", key.toLowerCase());
|
|
69
|
+
}
|
|
70
|
+
__name(Head, "Head");
|
|
71
|
+
function Query(key = "") {
|
|
72
|
+
return BaseParam("query", key);
|
|
73
|
+
}
|
|
74
|
+
__name(Query, "Query");
|
|
75
|
+
function Param(key) {
|
|
76
|
+
return BaseParam("params", key);
|
|
77
|
+
}
|
|
78
|
+
__name(Param, "Param");
|
|
79
|
+
function Arg() {
|
|
80
|
+
return BaseParam("params", "");
|
|
81
|
+
}
|
|
82
|
+
__name(Arg, "Arg");
|
|
83
|
+
|
|
84
|
+
// src/decorators/route.ts
|
|
85
|
+
import { SHARE_KEY, getOwnState as getOwnState2, setState as setState2, setStateKey as setStateKey2 } from "phecda-core";
|
|
86
|
+
function Route(route, type) {
|
|
87
|
+
return (target, key) => {
|
|
88
|
+
if (!key)
|
|
89
|
+
key = SHARE_KEY;
|
|
90
|
+
target = key === SHARE_KEY ? target.prototype : target;
|
|
91
|
+
setStateKey2(target, key);
|
|
92
|
+
const state = getOwnState2(target, key);
|
|
93
|
+
state.http = {
|
|
94
|
+
route,
|
|
95
|
+
type
|
|
96
|
+
};
|
|
97
|
+
setState2(target, key, state);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
__name(Route, "Route");
|
|
101
|
+
function Get(route = "") {
|
|
102
|
+
return Route(route, "get");
|
|
103
|
+
}
|
|
104
|
+
__name(Get, "Get");
|
|
105
|
+
function Post(route = "") {
|
|
106
|
+
return Route(route, "post");
|
|
107
|
+
}
|
|
108
|
+
__name(Post, "Post");
|
|
109
|
+
function Put(route = "") {
|
|
110
|
+
return Route(route, "put");
|
|
111
|
+
}
|
|
112
|
+
__name(Put, "Put");
|
|
113
|
+
function Patch(route = "") {
|
|
114
|
+
return Route(route, "patch");
|
|
115
|
+
}
|
|
116
|
+
__name(Patch, "Patch");
|
|
117
|
+
function Delete(route = "") {
|
|
118
|
+
return Route(route, "delete");
|
|
119
|
+
}
|
|
120
|
+
__name(Delete, "Delete");
|
|
121
|
+
function Controller(route = "") {
|
|
122
|
+
return Route(route);
|
|
123
|
+
}
|
|
124
|
+
__name(Controller, "Controller");
|
|
125
|
+
function Event(isEvent = true) {
|
|
126
|
+
return (target, key) => {
|
|
127
|
+
if (!key)
|
|
128
|
+
key = SHARE_KEY;
|
|
129
|
+
target = key === SHARE_KEY ? target.prototype : target;
|
|
130
|
+
setStateKey2(target, key);
|
|
131
|
+
const state = getOwnState2(target, key);
|
|
132
|
+
if (!state.rpc)
|
|
133
|
+
state.rpc = {};
|
|
134
|
+
state.rpc.isEvent = isEvent;
|
|
135
|
+
setState2(target, key, state);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
__name(Event, "Event");
|
|
139
|
+
function Queue(queue) {
|
|
140
|
+
return (target, key) => {
|
|
141
|
+
if (!key)
|
|
142
|
+
key = SHARE_KEY;
|
|
143
|
+
target = key === SHARE_KEY ? target.prototype : target;
|
|
144
|
+
setStateKey2(target, key);
|
|
145
|
+
const state = getOwnState2(target, key) || {};
|
|
146
|
+
if (!state.rpc)
|
|
147
|
+
state.rpc = {};
|
|
148
|
+
state.rpc.queue = queue;
|
|
149
|
+
setState2(target, key, state);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
__name(Queue, "Queue");
|
|
153
|
+
|
|
154
|
+
// src/decorators/aop.ts
|
|
155
|
+
import { SHARE_KEY as SHARE_KEY2, getOwnState as getOwnState3, setState as setState3, setStateKey as setStateKey3 } from "phecda-core";
|
|
156
|
+
function Guard(...guards) {
|
|
157
|
+
return (target, key) => {
|
|
158
|
+
if (!key)
|
|
159
|
+
key = SHARE_KEY2;
|
|
160
|
+
target = key === SHARE_KEY2 ? target.prototype : target;
|
|
161
|
+
setStateKey3(target, key);
|
|
162
|
+
const state = getOwnState3(target, key);
|
|
163
|
+
if (!state.guards)
|
|
164
|
+
state.guards = [];
|
|
165
|
+
state.guards.push(...guards);
|
|
166
|
+
setState3(target, key, state);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
__name(Guard, "Guard");
|
|
170
|
+
function Plugin(...plugins) {
|
|
171
|
+
return (target, key) => {
|
|
172
|
+
if (!key)
|
|
173
|
+
key = SHARE_KEY2;
|
|
174
|
+
target = key === SHARE_KEY2 ? target.prototype : target;
|
|
175
|
+
setStateKey3(target, key);
|
|
176
|
+
const state = getOwnState3(target, key);
|
|
177
|
+
if (!state.plugins)
|
|
178
|
+
state.plugins = [];
|
|
179
|
+
state.plugins.push(...plugins);
|
|
180
|
+
setState3(target, key, state);
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
__name(Plugin, "Plugin");
|
|
184
|
+
function Interceptor(...interceptors) {
|
|
185
|
+
return (target, key) => {
|
|
186
|
+
if (!key)
|
|
187
|
+
key = SHARE_KEY2;
|
|
188
|
+
target = key === SHARE_KEY2 ? target.prototype : target;
|
|
189
|
+
setStateKey3(target, key);
|
|
190
|
+
const state = getOwnState3(target, key);
|
|
191
|
+
if (!state.interceptors)
|
|
192
|
+
state.interceptors = [];
|
|
193
|
+
state.interceptors.push(...interceptors);
|
|
194
|
+
setState3(target, key, state);
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
__name(Interceptor, "Interceptor");
|
|
198
|
+
function Filter(filter) {
|
|
199
|
+
return (target, key) => {
|
|
200
|
+
if (!key)
|
|
201
|
+
key = SHARE_KEY2;
|
|
202
|
+
target = key === SHARE_KEY2 ? target.prototype : target;
|
|
203
|
+
setStateKey3(target, key);
|
|
204
|
+
const state = getOwnState3(target, key);
|
|
205
|
+
state.filter = filter;
|
|
206
|
+
setState3(target, key, state);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
__name(Filter, "Filter");
|
|
210
|
+
|
|
211
|
+
// src/decorators/index.ts
|
|
212
|
+
function Header(name, value) {
|
|
213
|
+
return (target, k) => {
|
|
214
|
+
setStateKey4(target, k);
|
|
215
|
+
const state = getOwnState4(target, k);
|
|
216
|
+
if (!state.header)
|
|
217
|
+
state.header = {};
|
|
218
|
+
state.header[name] = value;
|
|
219
|
+
setState4(target, k, state);
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
__name(Header, "Header");
|
|
223
|
+
function Ctx(target, key) {
|
|
224
|
+
set(target, "context", key);
|
|
225
|
+
}
|
|
226
|
+
__name(Ctx, "Ctx");
|
|
227
|
+
function Define(key, value) {
|
|
228
|
+
return (target, k) => {
|
|
229
|
+
if (!k) {
|
|
230
|
+
k = SHARE_KEY3;
|
|
231
|
+
target = target.prototype;
|
|
232
|
+
}
|
|
233
|
+
setStateKey4(target, k);
|
|
234
|
+
const state = getOwnState4(target, k);
|
|
235
|
+
if (!state.define)
|
|
236
|
+
state.define = {};
|
|
237
|
+
state.define[key] = value;
|
|
238
|
+
setState4(target, k, state);
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
__name(Define, "Define");
|
|
242
|
+
|
|
243
|
+
// src/index.ts
|
|
244
|
+
export * from "phecda-core";
|
|
245
|
+
|
|
246
|
+
// src/modules/dev.ts
|
|
247
|
+
import { Empty, Unmount } from "phecda-core";
|
|
248
|
+
var __decorate = function(decorators, target, key, desc) {
|
|
249
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
250
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
251
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
252
|
+
else
|
|
253
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
254
|
+
if (d = decorators[i])
|
|
255
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
256
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
257
|
+
};
|
|
258
|
+
var __metadata = function(k, v) {
|
|
259
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
260
|
+
return Reflect.metadata(k, v);
|
|
261
|
+
};
|
|
262
|
+
var Dev = /* @__PURE__ */ __name(class Dev2 {
|
|
263
|
+
[UNMOUNT_SYMBOL] = [];
|
|
264
|
+
context;
|
|
265
|
+
onUnmount(cb) {
|
|
266
|
+
this[UNMOUNT_SYMBOL].push(cb);
|
|
267
|
+
}
|
|
268
|
+
async unmount() {
|
|
269
|
+
for (const cb of this[UNMOUNT_SYMBOL])
|
|
270
|
+
await cb();
|
|
271
|
+
}
|
|
272
|
+
}, "Dev");
|
|
273
|
+
__decorate([
|
|
274
|
+
Unmount,
|
|
275
|
+
__metadata("design:type", Function),
|
|
276
|
+
__metadata("design:paramtypes", [])
|
|
277
|
+
], Dev.prototype, "unmount", null);
|
|
278
|
+
Dev = __decorate([
|
|
279
|
+
Empty
|
|
280
|
+
], Dev);
|
|
281
|
+
|
|
282
|
+
// src/modules/filter.ts
|
|
283
|
+
import { getTag } from "phecda-core";
|
|
284
|
+
var PFilter = class extends Dev {
|
|
285
|
+
key;
|
|
286
|
+
constructor(tag) {
|
|
287
|
+
super();
|
|
288
|
+
this.key = tag || getTag(this);
|
|
289
|
+
addFilter(this.key, this.use.bind(this));
|
|
290
|
+
this.onUnmount(() => {
|
|
291
|
+
delete Context.filterRecord[this.key];
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
__name(PFilter, "PFilter");
|
|
296
|
+
|
|
297
|
+
// src/modules/guard.ts
|
|
298
|
+
import { getTag as getTag2 } from "phecda-core";
|
|
299
|
+
var PGuard = class extends Dev {
|
|
300
|
+
key;
|
|
301
|
+
constructor(tag) {
|
|
302
|
+
super();
|
|
303
|
+
this.key = tag || getTag2(this);
|
|
304
|
+
addGuard(this.key, this.use.bind(this));
|
|
305
|
+
this.onUnmount(() => {
|
|
306
|
+
delete Context.guardRecord[this.key];
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
__name(PGuard, "PGuard");
|
|
311
|
+
|
|
312
|
+
// src/modules/interceptor.ts
|
|
313
|
+
import { getTag as getTag3 } from "phecda-core";
|
|
314
|
+
var PInterceptor = class extends Dev {
|
|
315
|
+
key;
|
|
316
|
+
constructor(tag) {
|
|
317
|
+
super();
|
|
318
|
+
this.key = tag || getTag3(this);
|
|
319
|
+
this.onUnmount(() => {
|
|
320
|
+
delete Context.interceptorRecord[this.key];
|
|
321
|
+
});
|
|
322
|
+
addInterceptor(this.key, this.use.bind(this));
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
__name(PInterceptor, "PInterceptor");
|
|
326
|
+
|
|
327
|
+
// src/modules/pipe.ts
|
|
328
|
+
import { getTag as getTag4 } from "phecda-core";
|
|
329
|
+
var PPipe = class extends Dev {
|
|
330
|
+
key;
|
|
331
|
+
constructor(tag) {
|
|
332
|
+
super();
|
|
333
|
+
this.key = tag || getTag4(this);
|
|
334
|
+
addPipe(this.key, this.use.bind(this));
|
|
335
|
+
this.onUnmount(() => {
|
|
336
|
+
delete Context.pipeRecord[this.key];
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
__name(PPipe, "PPipe");
|
|
341
|
+
|
|
342
|
+
// src/modules/plugin.ts
|
|
343
|
+
import { getTag as getTag5 } from "phecda-core";
|
|
344
|
+
var PPlugin = class extends Dev {
|
|
345
|
+
key;
|
|
346
|
+
constructor(tag) {
|
|
347
|
+
super();
|
|
348
|
+
this.key = tag || getTag5(this);
|
|
349
|
+
addPlugin(this.key, this.use.bind(this));
|
|
350
|
+
this.onUnmount(() => {
|
|
351
|
+
delete Context.pluginRecord[this.key];
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
__name(PPlugin, "PPlugin");
|
|
356
|
+
|
|
357
|
+
// src/modules/extension.ts
|
|
358
|
+
import { getTag as getTag6 } from "phecda-core";
|
|
359
|
+
var PExtension = class extends Dev {
|
|
360
|
+
key;
|
|
361
|
+
constructor(tag) {
|
|
362
|
+
super();
|
|
363
|
+
const key = this.key = tag || getTag6(this);
|
|
364
|
+
if (this.pipe) {
|
|
365
|
+
addPipe(key, this.pipe.bind(this));
|
|
366
|
+
this.onUnmount(() => {
|
|
367
|
+
delete Context.pipeRecord[key];
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
if (this.plugin) {
|
|
371
|
+
addPlugin(key, this.plugin.bind(this));
|
|
372
|
+
this.onUnmount(() => {
|
|
373
|
+
delete Context.pluginRecord[key];
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
if (this.intercept) {
|
|
377
|
+
addInterceptor(key, this.intercept.bind(this));
|
|
378
|
+
this.onUnmount(() => {
|
|
379
|
+
delete Context.interceptorRecord[key];
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
if (this.guard) {
|
|
383
|
+
addGuard(key, this.guard.bind(this));
|
|
384
|
+
this.onUnmount(() => {
|
|
385
|
+
delete Context.guardRecord[key];
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
if (this.filter) {
|
|
389
|
+
addFilter(key, this.filter.bind(this));
|
|
390
|
+
this.onUnmount(() => {
|
|
391
|
+
delete Context.filterRecord[key];
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
__name(PExtension, "PExtension");
|
|
397
|
+
|
|
398
|
+
export {
|
|
399
|
+
BaseParam,
|
|
400
|
+
Pipe,
|
|
401
|
+
Body,
|
|
402
|
+
Head,
|
|
403
|
+
Query,
|
|
404
|
+
Param,
|
|
405
|
+
Arg,
|
|
406
|
+
Route,
|
|
407
|
+
Get,
|
|
408
|
+
Post,
|
|
409
|
+
Put,
|
|
410
|
+
Patch,
|
|
411
|
+
Delete,
|
|
412
|
+
Controller,
|
|
413
|
+
Event,
|
|
414
|
+
Queue,
|
|
415
|
+
Guard,
|
|
416
|
+
Plugin,
|
|
417
|
+
Interceptor,
|
|
418
|
+
Filter,
|
|
419
|
+
Header,
|
|
420
|
+
Ctx,
|
|
421
|
+
Define,
|
|
422
|
+
Dev,
|
|
423
|
+
PFilter,
|
|
424
|
+
PGuard,
|
|
425
|
+
PInterceptor,
|
|
426
|
+
PPipe,
|
|
427
|
+
PPlugin,
|
|
428
|
+
PExtension
|
|
429
|
+
};
|