phecda-server 7.0.0-alpha.7 → 7.0.0-alpha.8
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/bin/cli.mjs +10 -1
- package/dist/{chunk-MENRZSGW.js → chunk-7EMAZGYO.js} +86 -56
- package/dist/{chunk-JPSXNDXP.mjs → chunk-7NWDKK7D.mjs} +1 -1
- package/dist/{chunk-RGSKKTHD.mjs → chunk-B45BN7LY.mjs} +4 -4
- package/dist/{chunk-VYMSCWXC.js → chunk-BBNJVYVX.js} +24 -24
- package/dist/{chunk-XSMUJ77A.js → chunk-QJIAXSLZ.js} +19 -19
- package/dist/{chunk-IRXNF6ZE.mjs → chunk-SGMQZRP6.mjs} +39 -9
- package/dist/{chunk-M5HGFUCV.js → chunk-VSGYTGHY.js} +2 -2
- package/dist/{chunk-C5BVKEGW.mjs → chunk-YKP4ODZA.mjs} +2 -2
- package/dist/{core-CzElxZoF.d.ts → core-BGEsBtTG.d.ts} +1 -1
- package/dist/{core-DU7gQKSk.d.mts → core-BcKywWLd.d.mts} +1 -1
- package/dist/helper.d.mts +3 -2
- package/dist/helper.d.ts +3 -2
- package/dist/helper.js +5 -3
- package/dist/helper.mjs +4 -2
- package/dist/http/elysia/index.d.mts +4 -4
- package/dist/http/elysia/index.d.ts +4 -4
- package/dist/http/elysia/index.js +42 -41
- package/dist/http/elysia/index.mjs +6 -5
- package/dist/http/express/index.d.mts +4 -4
- package/dist/http/express/index.d.ts +4 -4
- package/dist/http/express/index.js +39 -38
- package/dist/http/express/index.mjs +5 -4
- package/dist/http/fastify/index.d.mts +4 -4
- package/dist/http/fastify/index.d.ts +4 -4
- package/dist/http/fastify/index.js +40 -39
- package/dist/http/fastify/index.mjs +6 -5
- package/dist/http/h3/index.d.mts +4 -4
- package/dist/http/h3/index.d.ts +4 -4
- package/dist/http/h3/index.js +40 -39
- package/dist/http/h3/index.mjs +6 -5
- package/dist/http/hono/index.d.mts +4 -4
- package/dist/http/hono/index.d.ts +4 -4
- package/dist/http/hono/index.js +35 -35
- package/dist/http/hono/index.mjs +2 -2
- package/dist/http/hyper-express/index.d.mts +4 -4
- package/dist/http/hyper-express/index.d.ts +4 -4
- package/dist/http/hyper-express/index.js +37 -36
- package/dist/http/hyper-express/index.mjs +5 -4
- package/dist/http/koa/index.d.mts +4 -4
- package/dist/http/koa/index.d.ts +4 -4
- package/dist/http/koa/index.js +39 -38
- package/dist/http/koa/index.mjs +5 -4
- package/dist/index.d.mts +35 -33
- package/dist/index.d.ts +35 -33
- package/dist/index.js +43 -42
- package/dist/index.mjs +15 -14
- package/dist/{meta-BTnLXuCa.d.ts → meta-B_HW7cWh.d.mts} +3 -3
- package/dist/{meta-BTnLXuCa.d.mts → meta-B_HW7cWh.d.ts} +3 -3
- package/dist/rpc/bullmq/index.d.mts +4 -4
- package/dist/rpc/bullmq/index.d.ts +4 -4
- package/dist/rpc/bullmq/index.js +14 -14
- package/dist/rpc/bullmq/index.mjs +2 -2
- package/dist/rpc/kafka/index.d.mts +4 -4
- package/dist/rpc/kafka/index.d.ts +4 -4
- package/dist/rpc/kafka/index.js +14 -14
- package/dist/rpc/kafka/index.mjs +2 -2
- package/dist/rpc/nats/index.d.mts +4 -4
- package/dist/rpc/nats/index.d.ts +4 -4
- package/dist/rpc/nats/index.js +13 -13
- package/dist/rpc/nats/index.mjs +2 -2
- package/dist/rpc/rabbitmq/index.d.mts +4 -4
- package/dist/rpc/rabbitmq/index.d.ts +4 -4
- package/dist/rpc/rabbitmq/index.js +15 -15
- package/dist/rpc/rabbitmq/index.mjs +2 -2
- package/dist/rpc/redis/index.d.mts +4 -4
- package/dist/rpc/redis/index.d.ts +4 -4
- package/dist/rpc/redis/index.js +13 -13
- package/dist/rpc/redis/index.mjs +2 -2
- package/dist/test.d.mts +2 -2
- package/dist/test.d.ts +2 -2
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/{types--E-OCZhC.d.ts → types-C2SQ9U9V.d.mts} +3 -3
- package/dist/{types-CbfaGkPA.d.ts → types-CYF0vha6.d.ts} +3 -3
- package/dist/{types-BYqBeqrs.d.mts → types-DEQb_e59.d.mts} +3 -3
- package/dist/{types-BxlzVoRv.d.mts → types-PFPIQWVF.d.ts} +3 -3
- package/package.json +3 -2
- package/register/loader.mjs +2 -2
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkVSGYTGHYjs = require('./chunk-VSGYTGHY.js');
|
|
7
7
|
|
|
8
8
|
// src/meta.ts
|
|
9
9
|
var Meta = class {
|
|
10
10
|
static {
|
|
11
|
-
|
|
11
|
+
_chunkVSGYTGHYjs.__name.call(void 0, this, "Meta");
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
|
|
@@ -37,11 +37,11 @@ function defaultServerInject() {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
_chunkVSGYTGHYjs.__name.call(void 0, defaultServerInject, "defaultServerInject");
|
|
41
41
|
var phecdaNamespace = /* @__PURE__ */ new Map();
|
|
42
42
|
var ServerPhecda = (_class = class {
|
|
43
43
|
static {
|
|
44
|
-
|
|
44
|
+
_chunkVSGYTGHYjs.__name.call(void 0, this, "ServerPhecda");
|
|
45
45
|
}
|
|
46
46
|
__init() {this.moduleMap = /* @__PURE__ */ new Map()}
|
|
47
47
|
__init2() {this.meta = []}
|
|
@@ -53,7 +53,7 @@ var ServerPhecda = (_class = class {
|
|
|
53
53
|
|
|
54
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
55
|
defaultServerInject();
|
|
56
|
-
const { namespace = "default", parseModule = /* @__PURE__ */
|
|
56
|
+
const { namespace = "default", parseModule = /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (module) => module, "parseModule"), parseMeta = /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (meta) => meta, "parseMeta"), generators = [] } = options;
|
|
57
57
|
phecdaNamespace.set(namespace, this);
|
|
58
58
|
this.parseMeta = parseMeta;
|
|
59
59
|
this.parseModule = parseModule;
|
|
@@ -61,8 +61,8 @@ var ServerPhecda = (_class = class {
|
|
|
61
61
|
}
|
|
62
62
|
async start(models) {
|
|
63
63
|
for (const model of models) await this.buildDepModule(model);
|
|
64
|
-
const generateCode = /* @__PURE__ */
|
|
65
|
-
if (
|
|
64
|
+
const generateCode = /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, async () => {
|
|
65
|
+
if (_chunkVSGYTGHYjs.IS_DEV) {
|
|
66
66
|
return Promise.all(this.generators.map((generator) => {
|
|
67
67
|
debug(`generate "${generator.name}" code to ${generator.path}`);
|
|
68
68
|
return generator.output(this.meta);
|
|
@@ -70,9 +70,9 @@ var ServerPhecda = (_class = class {
|
|
|
70
70
|
}
|
|
71
71
|
}, "generateCode");
|
|
72
72
|
generateCode().then(() => {
|
|
73
|
-
if (
|
|
73
|
+
if (_chunkVSGYTGHYjs.IS_ONLY_GENERATE) process.exit(4);
|
|
74
74
|
});
|
|
75
|
-
if (
|
|
75
|
+
if (_chunkVSGYTGHYjs.IS_DEV) {
|
|
76
76
|
if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
|
|
77
77
|
_optionalChain([globalThis, 'access', _2 => _2.__PS_HMR__, 'optionalAccess', _3 => _3.push, 'call', _4 => _4(async (files) => {
|
|
78
78
|
debug("reload files ");
|
|
@@ -148,7 +148,7 @@ var ServerPhecda = (_class = class {
|
|
|
148
148
|
if (this.moduleMap.has(tag)) {
|
|
149
149
|
module = this.moduleMap.get(tag);
|
|
150
150
|
if (!module) {
|
|
151
|
-
|
|
151
|
+
_chunkVSGYTGHYjs.log.call(void 0, `Exist Circular-Dependency or Multiple modules with the same tag [${String(tag)}]`, "warn");
|
|
152
152
|
return {
|
|
153
153
|
module: this.createProxyModule(tag),
|
|
154
154
|
tag
|
|
@@ -156,8 +156,8 @@ var ServerPhecda = (_class = class {
|
|
|
156
156
|
}
|
|
157
157
|
if (this.modelMap.get(module) !== Model && !this.modelSet.has(Model)) {
|
|
158
158
|
this.modelSet.add(Model);
|
|
159
|
-
if (module instanceof Model)
|
|
160
|
-
else
|
|
159
|
+
if (module instanceof Model) _chunkVSGYTGHYjs.log.call(void 0, `Module taged ${String(tag)} has been overridden`);
|
|
160
|
+
else _chunkVSGYTGHYjs.log.call(void 0, `Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Model.name}"`, "warn");
|
|
161
161
|
}
|
|
162
162
|
return {
|
|
163
163
|
module,
|
|
@@ -180,7 +180,7 @@ var ServerPhecda = (_class = class {
|
|
|
180
180
|
}
|
|
181
181
|
this.meta.push(...getMetaFromInstance(module, tag, Model.name).map(this.parseMeta).filter((item) => !!item));
|
|
182
182
|
debug(`init module "${String(tag)}"`);
|
|
183
|
-
if (!
|
|
183
|
+
if (!_chunkVSGYTGHYjs.IS_ONLY_GENERATE) await _phecdacore.invokeInit.call(void 0, module);
|
|
184
184
|
debug(`add module "${String(tag)}"`);
|
|
185
185
|
this.moduleMap.set(tag, module);
|
|
186
186
|
this.modelMap.set(module, Model);
|
|
@@ -203,7 +203,7 @@ async function Factory(models, opts = {}) {
|
|
|
203
203
|
await phecda.start(models);
|
|
204
204
|
return phecda;
|
|
205
205
|
}
|
|
206
|
-
|
|
206
|
+
_chunkVSGYTGHYjs.__name.call(void 0, Factory, "Factory");
|
|
207
207
|
function useS(nsOrModel, namespace) {
|
|
208
208
|
if (!nsOrModel) {
|
|
209
209
|
namespace = "default";
|
|
@@ -216,7 +216,7 @@ function useS(nsOrModel, namespace) {
|
|
|
216
216
|
if (nsOrModel && typeof nsOrModel !== "string") return serverPhecda.get(nsOrModel);
|
|
217
217
|
else return serverPhecda;
|
|
218
218
|
}
|
|
219
|
-
|
|
219
|
+
_chunkVSGYTGHYjs.__name.call(void 0, useS, "useS");
|
|
220
220
|
function getMetaFromInstance(instance, tag, name) {
|
|
221
221
|
const propertyKeys = _phecdacore.getMetaKey.call(void 0, instance).filter((item) => typeof item === "string");
|
|
222
222
|
const baseMeta = _phecdacore.getMergedMeta.call(void 0, instance, void 0);
|
|
@@ -230,7 +230,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
230
230
|
func: i
|
|
231
231
|
};
|
|
232
232
|
if (baseMeta.controller) {
|
|
233
|
-
if (typeof tag !== "string")
|
|
233
|
+
if (typeof tag !== "string") _chunkVSGYTGHYjs.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
|
|
234
234
|
metaData.controller = baseMeta.controller;
|
|
235
235
|
metaData[baseMeta.controller] = {
|
|
236
236
|
...baseMeta[baseMeta.controller],
|
|
@@ -268,7 +268,7 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
268
268
|
return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || []);
|
|
269
269
|
});
|
|
270
270
|
}
|
|
271
|
-
|
|
271
|
+
_chunkVSGYTGHYjs.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
|
|
272
272
|
function deepFreeze(object) {
|
|
273
273
|
Object.freeze(object);
|
|
274
274
|
Object.getOwnPropertyNames(object).forEach((prop) => {
|
|
@@ -276,13 +276,13 @@ function deepFreeze(object) {
|
|
|
276
276
|
});
|
|
277
277
|
return object;
|
|
278
278
|
}
|
|
279
|
-
|
|
279
|
+
_chunkVSGYTGHYjs.__name.call(void 0, deepFreeze, "deepFreeze");
|
|
280
280
|
function getParamTypes(Model, key) {
|
|
281
281
|
const paramTypes = Reflect.getMetadata("design:paramtypes", Model, key);
|
|
282
282
|
if (typeof paramTypes === "function") return paramTypes();
|
|
283
283
|
else return paramTypes;
|
|
284
284
|
}
|
|
285
|
-
|
|
285
|
+
_chunkVSGYTGHYjs.__name.call(void 0, getParamTypes, "getParamTypes");
|
|
286
286
|
|
|
287
287
|
|
|
288
288
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ERROR_SYMBOL,
|
|
3
|
-
|
|
3
|
+
IS_DEV,
|
|
4
4
|
IS_STRICT,
|
|
5
5
|
LOG_LEVEL,
|
|
6
6
|
__name,
|
|
7
7
|
log
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YKP4ODZA.mjs";
|
|
9
9
|
|
|
10
10
|
// src/helper.ts
|
|
11
11
|
import pc2 from "picocolors";
|
|
@@ -230,10 +230,25 @@ var Context = class _Context {
|
|
|
230
230
|
};
|
|
231
231
|
static guardRecord = {};
|
|
232
232
|
static addonRecord = {};
|
|
233
|
+
ctx;
|
|
234
|
+
canGetCtx;
|
|
233
235
|
constructor(data) {
|
|
234
236
|
this.data = data;
|
|
235
|
-
|
|
237
|
+
this.canGetCtx = true;
|
|
238
|
+
if (IS_DEV)
|
|
236
239
|
data._context = this;
|
|
240
|
+
const that = this;
|
|
241
|
+
this.ctx = new Proxy(data, {
|
|
242
|
+
get(target, p) {
|
|
243
|
+
if (IS_DEV && !that.canGetCtx) throw new FrameworkException("ctx must be obtained within the same request cycle in controller");
|
|
244
|
+
if (!(p in target)) log(`attribute "${p}" does not exist on ctx, which might be due to a missing AOP role (such as a guard).`, "warn", data.tag);
|
|
245
|
+
return target[p];
|
|
246
|
+
},
|
|
247
|
+
set(target, p, newValue) {
|
|
248
|
+
target[p] = newValue;
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
237
252
|
}
|
|
238
253
|
static getAop(meta, opts) {
|
|
239
254
|
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
@@ -269,14 +284,20 @@ ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
269
284
|
if (index === guards.length) {
|
|
270
285
|
const instance = moduleMap.get(tag);
|
|
271
286
|
if (ctxs) {
|
|
272
|
-
ctxs.forEach((ctx) => instance[ctx] = this.
|
|
287
|
+
ctxs.forEach((ctx) => instance[ctx] = this.ctx);
|
|
273
288
|
}
|
|
274
289
|
const args = await Promise.all(params.map((item, i) => pipe[i]({
|
|
275
290
|
arg: resolveDep(this.data[item.type], item.key),
|
|
276
291
|
reflect: paramsType[item.index],
|
|
277
292
|
...item
|
|
278
|
-
}, this.
|
|
293
|
+
}, this.ctx)));
|
|
294
|
+
if (IS_DEV) {
|
|
295
|
+
Promise.resolve().then(() => {
|
|
296
|
+
this.canGetCtx = false;
|
|
297
|
+
});
|
|
298
|
+
}
|
|
279
299
|
res = await instance[func](...args);
|
|
300
|
+
this.canGetCtx = true;
|
|
280
301
|
} else {
|
|
281
302
|
let nextPromise;
|
|
282
303
|
async function next() {
|
|
@@ -289,7 +310,7 @@ ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
289
310
|
});
|
|
290
311
|
}
|
|
291
312
|
__name(next, "next");
|
|
292
|
-
const ret = await guards[index](this.
|
|
313
|
+
const ret = await guards[index](this.ctx, next);
|
|
293
314
|
if (ret !== void 0) {
|
|
294
315
|
res = ret;
|
|
295
316
|
} else {
|
|
@@ -302,7 +323,7 @@ ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
302
323
|
await nextHandler(0)();
|
|
303
324
|
return successCb(res);
|
|
304
325
|
} catch (e) {
|
|
305
|
-
const err = await filter(e, this.
|
|
326
|
+
const err = await filter(e, this.ctx);
|
|
306
327
|
return failCb(err);
|
|
307
328
|
}
|
|
308
329
|
}
|
|
@@ -358,7 +379,7 @@ __name(addAddon, "addAddon");
|
|
|
358
379
|
|
|
359
380
|
// src/hmr.ts
|
|
360
381
|
function HMR(cb) {
|
|
361
|
-
if (
|
|
382
|
+
if (IS_DEV) globalThis.__PS_HMR__?.push(cb);
|
|
362
383
|
}
|
|
363
384
|
__name(HMR, "HMR");
|
|
364
385
|
|
|
@@ -498,6 +519,14 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
498
519
|
};
|
|
499
520
|
}
|
|
500
521
|
__name(detectAopDep, "detectAopDep");
|
|
522
|
+
function joinUrl(base, ...paths) {
|
|
523
|
+
const joinedPath = [
|
|
524
|
+
base,
|
|
525
|
+
...paths
|
|
526
|
+
].filter((p) => p).map((path) => path.replace(/(^\/)/g, "")).join("/");
|
|
527
|
+
return `/${joinedPath}`;
|
|
528
|
+
}
|
|
529
|
+
__name(joinUrl, "joinUrl");
|
|
501
530
|
|
|
502
531
|
export {
|
|
503
532
|
defaultPipe,
|
|
@@ -530,5 +559,6 @@ export {
|
|
|
530
559
|
shallowClone,
|
|
531
560
|
mergeObject,
|
|
532
561
|
createControllerMetaMap,
|
|
533
|
-
detectAopDep
|
|
562
|
+
detectAopDep,
|
|
563
|
+
joinUrl
|
|
534
564
|
};
|
|
@@ -3,7 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/common.ts
|
|
5
5
|
var ERROR_SYMBOL = "__PS_ERROR__";
|
|
6
|
-
var
|
|
6
|
+
var IS_DEV = process.env.NODE_ENV === "development";
|
|
7
7
|
var IS_ONLY_GENERATE = !!process.env.PS_GENERATE;
|
|
8
8
|
var IS_STRICT = !!process.env.PS_STRICT;
|
|
9
9
|
var LOG_LEVEL = Number(process.env.PS_LOG_LEVEL || 0);
|
|
@@ -124,4 +124,4 @@ __name(runMiddleware, "runMiddleware");
|
|
|
124
124
|
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.
|
|
127
|
+
exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.LOG_LEVEL = LOG_LEVEL; exports.IS_READY = IS_READY; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.getLogger = getLogger; exports.log = log; exports.runMiddleware = runMiddleware; exports.Mixin = _tsmixer.Mixin;
|
|
@@ -3,7 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/common.ts
|
|
5
5
|
var ERROR_SYMBOL = "__PS_ERROR__";
|
|
6
|
-
var
|
|
6
|
+
var IS_DEV = process.env.NODE_ENV === "development";
|
|
7
7
|
var IS_ONLY_GENERATE = !!process.env.PS_GENERATE;
|
|
8
8
|
var IS_STRICT = !!process.env.PS_STRICT;
|
|
9
9
|
var LOG_LEVEL = Number(process.env.PS_LOG_LEVEL || 0);
|
|
@@ -113,7 +113,7 @@ __name(runMiddleware, "runMiddleware");
|
|
|
113
113
|
export {
|
|
114
114
|
__name,
|
|
115
115
|
ERROR_SYMBOL,
|
|
116
|
-
|
|
116
|
+
IS_DEV,
|
|
117
117
|
IS_ONLY_GENERATE,
|
|
118
118
|
IS_STRICT,
|
|
119
119
|
LOG_LEVEL,
|
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-B_HW7cWh.mjs';
|
|
2
2
|
import 'phecda-core';
|
|
3
3
|
|
|
4
4
|
declare function HMR(cb: (...args: any) => any): void;
|
|
@@ -21,5 +21,6 @@ declare function detectAopDep(meta: Meta[], { guards, addons }?: {
|
|
|
21
21
|
pipeSet: Set<string>;
|
|
22
22
|
filterSet: Set<string>;
|
|
23
23
|
};
|
|
24
|
+
declare function joinUrl(base: string, ...paths: string[]): string;
|
|
24
25
|
|
|
25
|
-
export { HMR, argToReq, createControllerMetaMap, detectAopDep, genClientQueue, mergeObject, resolveDep, shallowClone };
|
|
26
|
+
export { HMR, argToReq, createControllerMetaMap, detectAopDep, genClientQueue, joinUrl, mergeObject, resolveDep, shallowClone };
|
package/dist/helper.d.ts
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-B_HW7cWh.js';
|
|
2
2
|
import 'phecda-core';
|
|
3
3
|
|
|
4
4
|
declare function HMR(cb: (...args: any) => any): void;
|
|
@@ -21,5 +21,6 @@ declare function detectAopDep(meta: Meta[], { guards, addons }?: {
|
|
|
21
21
|
pipeSet: Set<string>;
|
|
22
22
|
filterSet: Set<string>;
|
|
23
23
|
};
|
|
24
|
+
declare function joinUrl(base: string, ...paths: string[]): string;
|
|
24
25
|
|
|
25
|
-
export { HMR, argToReq, createControllerMetaMap, detectAopDep, genClientQueue, mergeObject, resolveDep, shallowClone };
|
|
26
|
+
export { HMR, argToReq, createControllerMetaMap, detectAopDep, genClientQueue, joinUrl, mergeObject, resolveDep, shallowClone };
|
package/dist/helper.js
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var _chunkMENRZSGWjs = require('./chunk-MENRZSGW.js');
|
|
11
|
-
require('./chunk-M5HGFUCV.js');
|
|
12
10
|
|
|
11
|
+
var _chunk7EMAZGYOjs = require('./chunk-7EMAZGYO.js');
|
|
12
|
+
require('./chunk-VSGYTGHY.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -18,4 +18,6 @@ require('./chunk-M5HGFUCV.js');
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
exports.HMR = _chunk7EMAZGYOjs.HMR; exports.argToReq = _chunk7EMAZGYOjs.argToReq; exports.createControllerMetaMap = _chunk7EMAZGYOjs.createControllerMetaMap; exports.detectAopDep = _chunk7EMAZGYOjs.detectAopDep; exports.genClientQueue = _chunk7EMAZGYOjs.genClientQueue; exports.joinUrl = _chunk7EMAZGYOjs.joinUrl; exports.mergeObject = _chunk7EMAZGYOjs.mergeObject; exports.resolveDep = _chunk7EMAZGYOjs.resolveDep; exports.shallowClone = _chunk7EMAZGYOjs.shallowClone;
|
package/dist/helper.mjs
CHANGED
|
@@ -4,17 +4,19 @@ import {
|
|
|
4
4
|
createControllerMetaMap,
|
|
5
5
|
detectAopDep,
|
|
6
6
|
genClientQueue,
|
|
7
|
+
joinUrl,
|
|
7
8
|
mergeObject,
|
|
8
9
|
resolveDep,
|
|
9
10
|
shallowClone
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-SGMQZRP6.mjs";
|
|
12
|
+
import "./chunk-YKP4ODZA.mjs";
|
|
12
13
|
export {
|
|
13
14
|
HMR,
|
|
14
15
|
argToReq,
|
|
15
16
|
createControllerMetaMap,
|
|
16
17
|
detectAopDep,
|
|
17
18
|
genClientQueue,
|
|
19
|
+
joinUrl,
|
|
18
20
|
mergeObject,
|
|
19
21
|
resolveDep,
|
|
20
22
|
shallowClone
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
|
|
2
2
|
import { BaseMacro } from 'elysia/dist/types';
|
|
3
|
-
import { H as
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
3
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-C2SQ9U9V.mjs';
|
|
4
|
+
import { F as Factory } from '../../core-BcKywWLd.mjs';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../meta-
|
|
6
|
+
import '../../meta-B_HW7cWh.mjs';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
|
-
interface ElysiaCtx extends
|
|
9
|
+
interface ElysiaCtx extends HttpCtx {
|
|
10
10
|
type: 'elysia';
|
|
11
11
|
app: Elysia$1;
|
|
12
12
|
context: Context;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
|
|
2
2
|
import { BaseMacro } from 'elysia/dist/types';
|
|
3
|
-
import { H as
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
3
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-PFPIQWVF.js';
|
|
4
|
+
import { F as Factory } from '../../core-BGEsBtTG.js';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../meta-
|
|
6
|
+
import '../../meta-B_HW7cWh.js';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
|
-
interface ElysiaCtx extends
|
|
9
|
+
interface ElysiaCtx extends HttpCtx {
|
|
10
10
|
type: 'elysia';
|
|
11
11
|
app: Elysia$1;
|
|
12
12
|
context: Context;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkBBNJVYVXjs = require('../../chunk-BBNJVYVX.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var _chunkMENRZSGWjs = require('../../chunk-MENRZSGW.js');
|
|
11
10
|
|
|
11
|
+
var _chunk7EMAZGYOjs = require('../../chunk-7EMAZGYO.js');
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
var _chunkVSGYTGHYjs = require('../../chunk-VSGYTGHY.js');
|
|
14
15
|
|
|
15
16
|
// src/http/elysia/bind.ts
|
|
16
17
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
@@ -19,14 +20,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/elysia");
|
|
|
19
20
|
function bind(app, data, opts = {}) {
|
|
20
21
|
const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
|
|
21
22
|
const { moduleMap, meta } = data;
|
|
22
|
-
const metaMap =
|
|
23
|
+
const metaMap = _chunk7EMAZGYOjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
23
24
|
const { controller, http, func, tag } = meta2.data;
|
|
24
25
|
if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
|
|
25
26
|
debug(`register method "${func}" in module "${tag}"`);
|
|
26
27
|
return true;
|
|
27
28
|
}
|
|
28
29
|
});
|
|
29
|
-
|
|
30
|
+
_chunk7EMAZGYOjs.detectAopDep.call(void 0, meta, {
|
|
30
31
|
addons: [
|
|
31
32
|
...globalAddons,
|
|
32
33
|
...parallelAddons
|
|
@@ -35,29 +36,29 @@ function bind(app, data, opts = {}) {
|
|
|
35
36
|
});
|
|
36
37
|
registerRoute();
|
|
37
38
|
function registerRoute() {
|
|
38
|
-
|
|
39
|
+
_chunk7EMAZGYOjs.Context.applyAddons(globalAddons, app, "elysia");
|
|
39
40
|
if (parallelRoute) {
|
|
40
41
|
const parallelRouter = new (0, _elysia.Elysia)();
|
|
41
|
-
|
|
42
|
+
_chunk7EMAZGYOjs.Context.applyAddons(parallelAddons, app, "elysia");
|
|
42
43
|
parallelRouter.post(parallelRoute, async (c) => {
|
|
43
44
|
const { body } = c;
|
|
44
45
|
async function errorHandler(e) {
|
|
45
|
-
const error = await
|
|
46
|
+
const error = await _chunk7EMAZGYOjs.Context.filterRecord.default(e);
|
|
46
47
|
c.set.status = error.status;
|
|
47
48
|
return error;
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
if (!Array.isArray(body)) return errorHandler(new (0,
|
|
50
|
+
_chunkVSGYTGHYjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
51
|
+
if (!Array.isArray(body)) return errorHandler(new (0, _chunk7EMAZGYOjs.BadRequestException)("data format should be an array"));
|
|
51
52
|
try {
|
|
52
53
|
return Promise.all(body.map((item, i) => {
|
|
53
54
|
return new Promise(async (resolve) => {
|
|
54
55
|
const { tag, func } = item;
|
|
55
56
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
56
|
-
if (!metaMap.has(tag)) return resolve(await
|
|
57
|
+
if (!metaMap.has(tag)) return resolve(await _chunk7EMAZGYOjs.Context.filterRecord.default(new (0, _chunk7EMAZGYOjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
57
58
|
const meta2 = metaMap.get(tag)[func];
|
|
58
|
-
if (!meta2) return resolve(await
|
|
59
|
+
if (!meta2) return resolve(await _chunk7EMAZGYOjs.Context.filterRecord.default(new (0, _chunk7EMAZGYOjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
59
60
|
const { data: { params } } = meta2;
|
|
60
|
-
const aop =
|
|
61
|
+
const aop = _chunk7EMAZGYOjs.Context.getAop(meta2, {
|
|
61
62
|
globalGuards,
|
|
62
63
|
globalFilter,
|
|
63
64
|
globalPipe
|
|
@@ -73,24 +74,24 @@ function bind(app, data, opts = {}) {
|
|
|
73
74
|
tag,
|
|
74
75
|
func,
|
|
75
76
|
app,
|
|
76
|
-
...
|
|
77
|
-
getCookie: /* @__PURE__ */
|
|
78
|
-
setCookie: /* @__PURE__ */
|
|
77
|
+
..._chunk7EMAZGYOjs.argToReq.call(void 0, params, item.args, c.headers),
|
|
78
|
+
getCookie: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
|
|
79
|
+
setCookie: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
|
|
79
80
|
...opts2,
|
|
80
81
|
value
|
|
81
82
|
}), "setCookie"),
|
|
82
|
-
delCookie: /* @__PURE__ */
|
|
83
|
-
redirect: /* @__PURE__ */
|
|
84
|
-
setResHeaders: /* @__PURE__ */
|
|
85
|
-
setResStatus: /* @__PURE__ */
|
|
86
|
-
getRequest: /* @__PURE__ */
|
|
83
|
+
delCookie: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
|
|
84
|
+
redirect: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
|
|
85
|
+
setResHeaders: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
|
|
86
|
+
setResStatus: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
|
|
87
|
+
getRequest: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, () => {
|
|
87
88
|
throw new Error("elysia can't support getRequest");
|
|
88
89
|
}, "getRequest"),
|
|
89
|
-
getResponse: /* @__PURE__ */
|
|
90
|
+
getResponse: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, () => {
|
|
90
91
|
throw new Error("elysia can't support getResponse");
|
|
91
92
|
}, "getResponse")
|
|
92
93
|
};
|
|
93
|
-
const context = new (0,
|
|
94
|
+
const context = new (0, _chunk7EMAZGYOjs.Context)(contextData);
|
|
94
95
|
context.run(aop, resolve, resolve);
|
|
95
96
|
});
|
|
96
97
|
})).then((ret) => {
|
|
@@ -112,14 +113,14 @@ function bind(app, data, opts = {}) {
|
|
|
112
113
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
|
|
113
114
|
let aop;
|
|
114
115
|
if (!dynamic) {
|
|
115
|
-
aop =
|
|
116
|
+
aop = _chunk7EMAZGYOjs.Context.getAop(meta2, {
|
|
116
117
|
globalFilter,
|
|
117
118
|
globalGuards,
|
|
118
119
|
globalPipe
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
-
subApp[http.type](http.prefix
|
|
122
|
+
_chunk7EMAZGYOjs.Context.applyAddons(addons, subApp, "elysia");
|
|
123
|
+
subApp[http.type](_chunk7EMAZGYOjs.joinUrl.call(void 0, http.prefix, http.route), async (c) => {
|
|
123
124
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
124
125
|
const contextData = {
|
|
125
126
|
type: "elysia",
|
|
@@ -134,33 +135,33 @@ function bind(app, data, opts = {}) {
|
|
|
134
135
|
params: c.params,
|
|
135
136
|
headers: c.headers,
|
|
136
137
|
app,
|
|
137
|
-
getCookie: /* @__PURE__ */
|
|
138
|
-
setCookie: /* @__PURE__ */
|
|
138
|
+
getCookie: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
|
|
139
|
+
setCookie: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
|
|
139
140
|
...opts2,
|
|
140
141
|
value
|
|
141
142
|
}), "setCookie"),
|
|
142
|
-
delCookie: /* @__PURE__ */
|
|
143
|
-
redirect: /* @__PURE__ */
|
|
144
|
-
setResHeaders: /* @__PURE__ */
|
|
145
|
-
setResStatus: /* @__PURE__ */
|
|
146
|
-
getRequest: /* @__PURE__ */
|
|
143
|
+
delCookie: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
|
|
144
|
+
redirect: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
|
|
145
|
+
setResHeaders: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
|
|
146
|
+
setResStatus: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
|
|
147
|
+
getRequest: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, () => {
|
|
147
148
|
throw new Error("elysia can't support getRequest");
|
|
148
149
|
}, "getRequest"),
|
|
149
|
-
getResponse: /* @__PURE__ */
|
|
150
|
+
getResponse: /* @__PURE__ */ _chunkVSGYTGHYjs.__name.call(void 0, () => {
|
|
150
151
|
throw new Error("elysia can't support getResponse");
|
|
151
152
|
}, "getResponse")
|
|
152
153
|
};
|
|
153
154
|
if (dynamic) {
|
|
154
|
-
aop =
|
|
155
|
+
aop = _chunk7EMAZGYOjs.Context.getAop(meta2, {
|
|
155
156
|
globalFilter,
|
|
156
157
|
globalGuards,
|
|
157
158
|
globalPipe
|
|
158
159
|
});
|
|
159
160
|
}
|
|
160
|
-
const context = new (0,
|
|
161
|
+
const context = new (0, _chunk7EMAZGYOjs.Context)(contextData);
|
|
161
162
|
if (http.headers) c.set.headers = http.headers;
|
|
162
163
|
if (dynamic) {
|
|
163
|
-
aop =
|
|
164
|
+
aop = _chunk7EMAZGYOjs.Context.getAop(meta2, {
|
|
164
165
|
globalFilter,
|
|
165
166
|
globalGuards,
|
|
166
167
|
globalPipe
|
|
@@ -175,13 +176,13 @@ function bind(app, data, opts = {}) {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
|
-
|
|
179
|
+
_chunkVSGYTGHYjs.__name.call(void 0, registerRoute, "registerRoute");
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
+
_chunkVSGYTGHYjs.__name.call(void 0, bind, "bind");
|
|
181
182
|
function Elysia(opts) {
|
|
182
|
-
return
|
|
183
|
+
return _chunkBBNJVYVXjs.Define.call(void 0, "elysia", opts);
|
|
183
184
|
}
|
|
184
|
-
|
|
185
|
+
_chunkVSGYTGHYjs.__name.call(void 0, Elysia, "Elysia");
|
|
185
186
|
|
|
186
187
|
|
|
187
188
|
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Define
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-7NWDKK7D.mjs";
|
|
4
4
|
import {
|
|
5
5
|
BadRequestException,
|
|
6
6
|
Context,
|
|
7
7
|
argToReq,
|
|
8
8
|
createControllerMetaMap,
|
|
9
|
-
detectAopDep
|
|
10
|
-
|
|
9
|
+
detectAopDep,
|
|
10
|
+
joinUrl
|
|
11
|
+
} from "../../chunk-SGMQZRP6.mjs";
|
|
11
12
|
import {
|
|
12
13
|
__name
|
|
13
|
-
} from "../../chunk-
|
|
14
|
+
} from "../../chunk-YKP4ODZA.mjs";
|
|
14
15
|
|
|
15
16
|
// src/http/elysia/bind.ts
|
|
16
17
|
import Debug from "debug";
|
|
@@ -119,7 +120,7 @@ function bind(app, data, opts = {}) {
|
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
Context.applyAddons(addons, subApp, "elysia");
|
|
122
|
-
subApp[http.type](http.prefix
|
|
123
|
+
subApp[http.type](joinUrl(http.prefix, http.route), async (c) => {
|
|
123
124
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
124
125
|
const contextData = {
|
|
125
126
|
type: "elysia",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Request, Response, Router, RequestHandler } from 'express';
|
|
2
|
-
import { H as
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-C2SQ9U9V.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-BcKywWLd.mjs';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-B_HW7cWh.mjs';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
|
-
interface ExpressCtx extends
|
|
8
|
+
interface ExpressCtx extends HttpCtx {
|
|
9
9
|
type: 'express';
|
|
10
10
|
request: Request;
|
|
11
11
|
response: Response;
|