phecda-server 5.0.0 → 5.0.2
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/schema.json +7 -0
- package/dist/{chunk-5VMFQOJ7.mjs → chunk-AB4OX3WV.mjs} +13 -5
- package/dist/{chunk-VMXI3KFJ.js → chunk-BXLBWRHS.js} +12 -12
- package/dist/{chunk-C7MN5B36.mjs → chunk-W5EOVGQD.mjs} +1 -1
- package/dist/{chunk-5YYZLGGN.js → chunk-YERBWZCS.js} +13 -5
- package/dist/{core-eb646fe5.d.ts → core-fd134ffa.d.ts} +6 -15
- package/dist/helper-73e8d2f0.d.ts +18 -0
- package/dist/helper-f29f082f.d.ts +19 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +23 -23
- package/dist/index.mjs +2 -2
- package/dist/rpc/bullmq/index.d.ts +2 -3
- package/dist/rpc/bullmq/index.js +14 -17
- package/dist/rpc/bullmq/index.mjs +9 -12
- package/dist/rpc/kafka/index.d.ts +2 -3
- package/dist/rpc/kafka/index.js +14 -17
- package/dist/rpc/kafka/index.mjs +9 -12
- package/dist/rpc/nats/index.d.ts +2 -3
- package/dist/rpc/nats/index.js +13 -16
- package/dist/rpc/nats/index.mjs +9 -12
- package/dist/rpc/rabbitmq/index.d.ts +2 -3
- package/dist/rpc/rabbitmq/index.js +14 -17
- package/dist/rpc/rabbitmq/index.mjs +9 -12
- package/dist/rpc/redis/index.d.ts +2 -3
- package/dist/rpc/redis/index.js +14 -17
- package/dist/rpc/redis/index.mjs +9 -12
- package/dist/server/elysia/index.d.ts +4 -4
- package/dist/server/elysia/index.js +30 -30
- package/dist/server/elysia/index.mjs +17 -17
- package/dist/server/express/index.d.ts +4 -4
- package/dist/server/express/index.js +28 -28
- package/dist/server/express/index.mjs +16 -16
- package/dist/server/fastify/index.d.ts +4 -4
- package/dist/server/fastify/index.js +30 -30
- package/dist/server/fastify/index.mjs +17 -17
- package/dist/server/h3/index.d.ts +5 -10
- package/dist/server/h3/index.js +28 -28
- package/dist/server/h3/index.mjs +16 -16
- package/dist/server/hono/index.d.ts +4 -4
- package/dist/server/hono/index.js +28 -28
- package/dist/server/hono/index.mjs +16 -16
- package/dist/server/hyper-express/index.d.ts +4 -4
- package/dist/server/hyper-express/index.js +28 -28
- package/dist/server/hyper-express/index.mjs +16 -16
- package/dist/server/koa/index.d.ts +4 -4
- package/dist/server/koa/index.js +28 -28
- package/dist/server/koa/index.mjs +16 -16
- package/dist/test.d.ts +1 -2
- package/dist/test.js +8 -1
- package/dist/test.mjs +8 -1
- package/package.json +2 -2
- package/register/loader.mjs +36 -8
- package/dist/helper-88b19c66.d.ts +0 -12
- package/dist/helper-9e206c66.d.ts +0 -12
|
@@ -1,13 +1,13 @@
|
|
|
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 _chunkBXLBWRHSjs = require('../../chunk-BXLBWRHS.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
@@ -16,13 +16,11 @@ var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
|
16
16
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
17
17
|
var _elysia = require('elysia');
|
|
18
18
|
var debug = _debug2.default.call(void 0, "phecda-server/elysia");
|
|
19
|
-
function bind(app, data,
|
|
20
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
19
|
+
function bind(app, data, opts = {}) {
|
|
20
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
21
21
|
route: "/__PHECDA_SERVER__",
|
|
22
|
-
globalGuards: [],
|
|
23
|
-
globalInterceptors: [],
|
|
24
22
|
plugins: [],
|
|
25
|
-
...
|
|
23
|
+
...opts
|
|
26
24
|
};
|
|
27
25
|
const { moduleMap, meta } = data;
|
|
28
26
|
const metaMap = /* @__PURE__ */ new Map();
|
|
@@ -33,14 +31,6 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
33
31
|
if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
|
|
34
32
|
continue;
|
|
35
33
|
debug(`register method "${func}" in module "${tag}"`);
|
|
36
|
-
item.data.guards = [
|
|
37
|
-
...globalGuards,
|
|
38
|
-
...item.data.guards
|
|
39
|
-
];
|
|
40
|
-
item.data.interceptors = [
|
|
41
|
-
...globalInterceptors,
|
|
42
|
-
...item.data.interceptors
|
|
43
|
-
];
|
|
44
34
|
if (metaMap.has(tag))
|
|
45
35
|
metaMap.get(tag)[func] = item;
|
|
46
36
|
else
|
|
@@ -52,27 +42,27 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
52
42
|
_chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
53
43
|
async function createRoute() {
|
|
54
44
|
const parallelRouter = new (0, _elysia.Elysia)();
|
|
55
|
-
|
|
45
|
+
_chunkYERBWZCSjs.Context.usePlugin(plugins).forEach((p) => p(parallelRouter));
|
|
56
46
|
parallelRouter.post(route, async (c) => {
|
|
57
47
|
const { body } = c;
|
|
58
48
|
async function errorHandler(e) {
|
|
59
|
-
const error = await
|
|
49
|
+
const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
|
|
60
50
|
c.set.status = error.status;
|
|
61
51
|
return error;
|
|
62
52
|
}
|
|
63
53
|
_chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
64
54
|
if (!Array.isArray(body))
|
|
65
|
-
return errorHandler(new (0,
|
|
55
|
+
return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
|
|
66
56
|
try {
|
|
67
57
|
return Promise.all(body.map((item, i) => {
|
|
68
58
|
return new Promise(async (resolve) => {
|
|
69
59
|
const { tag, func } = item;
|
|
70
60
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
71
61
|
if (!metaMap.has(tag))
|
|
72
|
-
return resolve(await
|
|
62
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
73
63
|
const meta2 = metaMap.get(tag)[func];
|
|
74
64
|
if (!meta2)
|
|
75
|
-
return resolve(await
|
|
65
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
76
66
|
const { data: { params } } = meta2;
|
|
77
67
|
const contextData = {
|
|
78
68
|
type: "elysia",
|
|
@@ -84,10 +74,15 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
84
74
|
tag,
|
|
85
75
|
func,
|
|
86
76
|
app,
|
|
87
|
-
...
|
|
77
|
+
..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, c.headers)
|
|
88
78
|
};
|
|
89
|
-
const context = new (0,
|
|
90
|
-
context.run(
|
|
79
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
80
|
+
context.run({
|
|
81
|
+
globalGuards,
|
|
82
|
+
globalInterceptors,
|
|
83
|
+
globalFilter,
|
|
84
|
+
globalPipe
|
|
85
|
+
}, resolve, resolve);
|
|
91
86
|
});
|
|
92
87
|
})).then((ret) => {
|
|
93
88
|
return ret;
|
|
@@ -104,7 +99,7 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
104
99
|
const funcRouter = new (0, _elysia.Elysia)();
|
|
105
100
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
106
101
|
continue;
|
|
107
|
-
|
|
102
|
+
_chunkYERBWZCSjs.Context.usePlugin(plugins2).forEach((p) => p(funcRouter));
|
|
108
103
|
funcRouter[http.type](http.prefix + http.route, async (c) => {
|
|
109
104
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
110
105
|
const contextData = {
|
|
@@ -120,10 +115,15 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
120
115
|
headers: c.headers,
|
|
121
116
|
app
|
|
122
117
|
};
|
|
123
|
-
const context = new (0,
|
|
118
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
124
119
|
if (http.headers)
|
|
125
120
|
c.set.headers = http.headers;
|
|
126
|
-
return context.run(
|
|
121
|
+
return context.run({
|
|
122
|
+
globalGuards,
|
|
123
|
+
globalInterceptors,
|
|
124
|
+
globalFilter,
|
|
125
|
+
globalPipe
|
|
126
|
+
}, (returnData) => returnData, (err) => {
|
|
127
127
|
c.set.status = err.status;
|
|
128
128
|
return err;
|
|
129
129
|
});
|
|
@@ -133,15 +133,15 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
_chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
|
|
136
|
-
|
|
136
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
137
137
|
plugins,
|
|
138
138
|
guards: globalGuards,
|
|
139
139
|
interceptors: globalInterceptors
|
|
140
140
|
});
|
|
141
141
|
handleMeta();
|
|
142
142
|
createRoute();
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
_chunkYERBWZCSjs.HMR.call(void 0, async () => {
|
|
144
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
145
145
|
plugins,
|
|
146
146
|
guards: globalGuards,
|
|
147
147
|
interceptors: globalInterceptors
|
|
@@ -151,7 +151,7 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
151
151
|
}
|
|
152
152
|
_chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
|
|
153
153
|
function Elysia(opts) {
|
|
154
|
-
return
|
|
154
|
+
return _chunkBXLBWRHSjs.Define.call(void 0, "elysia", opts);
|
|
155
155
|
}
|
|
156
156
|
_chunkYR5Q5F2Kjs.__name.call(void 0, Elysia, "Elysia");
|
|
157
157
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Define
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-W5EOVGQD.mjs";
|
|
4
4
|
import {
|
|
5
5
|
BadRequestException,
|
|
6
6
|
Context,
|
|
7
7
|
HMR,
|
|
8
8
|
argToReq,
|
|
9
9
|
detectAopDep
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-AB4OX3WV.mjs";
|
|
11
11
|
import {
|
|
12
12
|
__name
|
|
13
13
|
} from "../../chunk-ITTD2GBR.mjs";
|
|
@@ -16,13 +16,11 @@ import {
|
|
|
16
16
|
import Debug from "debug";
|
|
17
17
|
import { Elysia as App } from "elysia";
|
|
18
18
|
var debug = Debug("phecda-server/elysia");
|
|
19
|
-
function bind(app, data,
|
|
20
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
19
|
+
function bind(app, data, opts = {}) {
|
|
20
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
21
21
|
route: "/__PHECDA_SERVER__",
|
|
22
|
-
globalGuards: [],
|
|
23
|
-
globalInterceptors: [],
|
|
24
22
|
plugins: [],
|
|
25
|
-
...
|
|
23
|
+
...opts
|
|
26
24
|
};
|
|
27
25
|
const { moduleMap, meta } = data;
|
|
28
26
|
const metaMap = /* @__PURE__ */ new Map();
|
|
@@ -33,14 +31,6 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
33
31
|
if (controller !== "http" || !http?.type)
|
|
34
32
|
continue;
|
|
35
33
|
debug(`register method "${func}" in module "${tag}"`);
|
|
36
|
-
item.data.guards = [
|
|
37
|
-
...globalGuards,
|
|
38
|
-
...item.data.guards
|
|
39
|
-
];
|
|
40
|
-
item.data.interceptors = [
|
|
41
|
-
...globalInterceptors,
|
|
42
|
-
...item.data.interceptors
|
|
43
|
-
];
|
|
44
34
|
if (metaMap.has(tag))
|
|
45
35
|
metaMap.get(tag)[func] = item;
|
|
46
36
|
else
|
|
@@ -87,7 +77,12 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
87
77
|
...argToReq(params, item.args, c.headers)
|
|
88
78
|
};
|
|
89
79
|
const context = new Context(contextData);
|
|
90
|
-
context.run(
|
|
80
|
+
context.run({
|
|
81
|
+
globalGuards,
|
|
82
|
+
globalInterceptors,
|
|
83
|
+
globalFilter,
|
|
84
|
+
globalPipe
|
|
85
|
+
}, resolve, resolve);
|
|
91
86
|
});
|
|
92
87
|
})).then((ret) => {
|
|
93
88
|
return ret;
|
|
@@ -123,7 +118,12 @@ function bind(app, data, ServerOptions = {}) {
|
|
|
123
118
|
const context = new Context(contextData);
|
|
124
119
|
if (http.headers)
|
|
125
120
|
c.set.headers = http.headers;
|
|
126
|
-
return context.run(
|
|
121
|
+
return context.run({
|
|
122
|
+
globalGuards,
|
|
123
|
+
globalInterceptors,
|
|
124
|
+
globalFilter,
|
|
125
|
+
globalPipe
|
|
126
|
+
}, (returnData) => returnData, (err) => {
|
|
127
127
|
c.set.status = err.status;
|
|
128
128
|
return err;
|
|
129
129
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request, Response, Router } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { a as HttpContext, H as HttpOptions } from '../../helper-f29f082f.js';
|
|
3
|
+
import { F as Factory } from '../../core-fd134ffa.js';
|
|
4
|
+
import 'node:http';
|
|
4
5
|
import 'phecda-core';
|
|
5
|
-
import 'http';
|
|
6
6
|
|
|
7
7
|
interface ExpressCtx extends HttpContext {
|
|
8
8
|
type: 'express';
|
|
@@ -11,6 +11,6 @@ interface ExpressCtx extends HttpContext {
|
|
|
11
11
|
next: Function;
|
|
12
12
|
app: Router;
|
|
13
13
|
}
|
|
14
|
-
declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>,
|
|
14
|
+
declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
|
|
15
15
|
|
|
16
16
|
export { ExpressCtx, bind };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
@@ -12,13 +12,11 @@ var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
|
12
12
|
// src/server/express/bind.ts
|
|
13
13
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
14
14
|
var debug = _debug2.default.call(void 0, "phecda-server/express");
|
|
15
|
-
function bind(router, data,
|
|
16
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
15
|
+
function bind(router, data, opts = {}) {
|
|
16
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
17
17
|
route: "/__PHECDA_SERVER__",
|
|
18
|
-
globalGuards: [],
|
|
19
|
-
globalInterceptors: [],
|
|
20
18
|
plugins: [],
|
|
21
|
-
...
|
|
19
|
+
...opts
|
|
22
20
|
};
|
|
23
21
|
const { moduleMap, meta } = data;
|
|
24
22
|
const originStack = router.stack.slice(0, router.stack.length);
|
|
@@ -30,14 +28,6 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
30
28
|
if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _ => _.type]))
|
|
31
29
|
continue;
|
|
32
30
|
debug(`register method "${func}" in module "${tag}"`);
|
|
33
|
-
item.data.guards = [
|
|
34
|
-
...globalGuards,
|
|
35
|
-
...item.data.guards
|
|
36
|
-
];
|
|
37
|
-
item.data.interceptors = [
|
|
38
|
-
...globalInterceptors,
|
|
39
|
-
...item.data.interceptors
|
|
40
|
-
];
|
|
41
31
|
if (metaMap.has(tag))
|
|
42
32
|
metaMap.get(tag)[func] = item;
|
|
43
33
|
else
|
|
@@ -48,25 +38,25 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
48
38
|
}
|
|
49
39
|
_chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
50
40
|
async function createRoute() {
|
|
51
|
-
router.post(route, ...
|
|
41
|
+
router.post(route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins), async (req, res, next) => {
|
|
52
42
|
const { body } = req;
|
|
53
43
|
async function errorHandler(e) {
|
|
54
|
-
const error = await
|
|
44
|
+
const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
|
|
55
45
|
return res.status(error.status).json(error);
|
|
56
46
|
}
|
|
57
47
|
_chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
58
48
|
if (!Array.isArray(body))
|
|
59
|
-
return errorHandler(new (0,
|
|
49
|
+
return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
|
|
60
50
|
try {
|
|
61
51
|
return Promise.all(body.map((item, i) => {
|
|
62
52
|
return new Promise(async (resolve) => {
|
|
63
53
|
const { tag, func } = item;
|
|
64
54
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
65
55
|
if (!metaMap.has(tag))
|
|
66
|
-
return resolve(await
|
|
56
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
67
57
|
const meta2 = metaMap.get(tag)[func];
|
|
68
58
|
if (!meta2)
|
|
69
|
-
return resolve(await
|
|
59
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
70
60
|
const { data: { params } } = meta2;
|
|
71
61
|
const contextData = {
|
|
72
62
|
type: "express",
|
|
@@ -80,10 +70,15 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
80
70
|
func,
|
|
81
71
|
next,
|
|
82
72
|
app: router,
|
|
83
|
-
...
|
|
73
|
+
..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, req.headers)
|
|
84
74
|
};
|
|
85
|
-
const context = new (0,
|
|
86
|
-
context.run(
|
|
75
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
76
|
+
context.run({
|
|
77
|
+
globalGuards,
|
|
78
|
+
globalInterceptors,
|
|
79
|
+
globalFilter,
|
|
80
|
+
globalPipe
|
|
81
|
+
}, resolve, resolve);
|
|
87
82
|
});
|
|
88
83
|
})).then((ret) => {
|
|
89
84
|
res.json(ret);
|
|
@@ -98,7 +93,7 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
98
93
|
const { data: { plugins: plugins2, http } } = meta2;
|
|
99
94
|
if (!_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
100
95
|
continue;
|
|
101
|
-
router[http.type](http.prefix + http.route, ...
|
|
96
|
+
router[http.type](http.prefix + http.route, ..._chunkYERBWZCSjs.Context.usePlugin(plugins2), async (req, res, next) => {
|
|
102
97
|
debug(`invoke method "${func}" in module "${tag}"`);
|
|
103
98
|
const contextData = {
|
|
104
99
|
type: "express",
|
|
@@ -115,12 +110,17 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
115
110
|
app: router,
|
|
116
111
|
next
|
|
117
112
|
};
|
|
118
|
-
const context = new (0,
|
|
113
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
119
114
|
if (http.headers) {
|
|
120
115
|
for (const name in http.headers)
|
|
121
116
|
res.set(name, http.headers[name]);
|
|
122
117
|
}
|
|
123
|
-
await context.run(
|
|
118
|
+
await context.run({
|
|
119
|
+
globalGuards,
|
|
120
|
+
globalInterceptors,
|
|
121
|
+
globalFilter,
|
|
122
|
+
globalPipe
|
|
123
|
+
}, (returnData) => {
|
|
124
124
|
if (res.writableEnded)
|
|
125
125
|
return;
|
|
126
126
|
if (typeof returnData === "string")
|
|
@@ -137,16 +137,16 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
_chunkYR5Q5F2Kjs.__name.call(void 0, createRoute, "createRoute");
|
|
140
|
-
|
|
140
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
141
141
|
plugins,
|
|
142
142
|
guards: globalGuards,
|
|
143
143
|
interceptors: globalInterceptors
|
|
144
144
|
});
|
|
145
145
|
handleMeta();
|
|
146
146
|
createRoute();
|
|
147
|
-
|
|
147
|
+
_chunkYERBWZCSjs.HMR.call(void 0, async () => {
|
|
148
148
|
router.stack = originStack;
|
|
149
|
-
|
|
149
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
150
150
|
plugins,
|
|
151
151
|
guards: globalGuards,
|
|
152
152
|
interceptors: globalInterceptors
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
HMR,
|
|
5
5
|
argToReq,
|
|
6
6
|
detectAopDep
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-AB4OX3WV.mjs";
|
|
8
8
|
import {
|
|
9
9
|
__name
|
|
10
10
|
} from "../../chunk-ITTD2GBR.mjs";
|
|
@@ -12,13 +12,11 @@ import {
|
|
|
12
12
|
// src/server/express/bind.ts
|
|
13
13
|
import Debug from "debug";
|
|
14
14
|
var debug = Debug("phecda-server/express");
|
|
15
|
-
function bind(router, data,
|
|
16
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
15
|
+
function bind(router, data, opts = {}) {
|
|
16
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
17
17
|
route: "/__PHECDA_SERVER__",
|
|
18
|
-
globalGuards: [],
|
|
19
|
-
globalInterceptors: [],
|
|
20
18
|
plugins: [],
|
|
21
|
-
...
|
|
19
|
+
...opts
|
|
22
20
|
};
|
|
23
21
|
const { moduleMap, meta } = data;
|
|
24
22
|
const originStack = router.stack.slice(0, router.stack.length);
|
|
@@ -30,14 +28,6 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
30
28
|
if (controller !== "http" || !http?.type)
|
|
31
29
|
continue;
|
|
32
30
|
debug(`register method "${func}" in module "${tag}"`);
|
|
33
|
-
item.data.guards = [
|
|
34
|
-
...globalGuards,
|
|
35
|
-
...item.data.guards
|
|
36
|
-
];
|
|
37
|
-
item.data.interceptors = [
|
|
38
|
-
...globalInterceptors,
|
|
39
|
-
...item.data.interceptors
|
|
40
|
-
];
|
|
41
31
|
if (metaMap.has(tag))
|
|
42
32
|
metaMap.get(tag)[func] = item;
|
|
43
33
|
else
|
|
@@ -83,7 +73,12 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
83
73
|
...argToReq(params, item.args, req.headers)
|
|
84
74
|
};
|
|
85
75
|
const context = new Context(contextData);
|
|
86
|
-
context.run(
|
|
76
|
+
context.run({
|
|
77
|
+
globalGuards,
|
|
78
|
+
globalInterceptors,
|
|
79
|
+
globalFilter,
|
|
80
|
+
globalPipe
|
|
81
|
+
}, resolve, resolve);
|
|
87
82
|
});
|
|
88
83
|
})).then((ret) => {
|
|
89
84
|
res.json(ret);
|
|
@@ -120,7 +115,12 @@ function bind(router, data, ServerOptions = {}) {
|
|
|
120
115
|
for (const name in http.headers)
|
|
121
116
|
res.set(name, http.headers[name]);
|
|
122
117
|
}
|
|
123
|
-
await context.run(
|
|
118
|
+
await context.run({
|
|
119
|
+
globalGuards,
|
|
120
|
+
globalInterceptors,
|
|
121
|
+
globalFilter,
|
|
122
|
+
globalPipe
|
|
123
|
+
}, (returnData) => {
|
|
124
124
|
if (res.writableEnded)
|
|
125
125
|
return;
|
|
126
126
|
if (typeof returnData === "string")
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply, FastifyInstance, FastifyPluginCallback, RouteShorthandOptions } from 'fastify';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { a as HttpContext, H as HttpOptions } from '../../helper-f29f082f.js';
|
|
3
|
+
import { F as Factory } from '../../core-fd134ffa.js';
|
|
4
|
+
import 'node:http';
|
|
4
5
|
import 'phecda-core';
|
|
5
|
-
import 'http';
|
|
6
6
|
|
|
7
7
|
interface FastifyCtx extends HttpContext {
|
|
8
8
|
type: 'fastify';
|
|
@@ -10,7 +10,7 @@ interface FastifyCtx extends HttpContext {
|
|
|
10
10
|
response: FastifyReply;
|
|
11
11
|
app: FastifyInstance;
|
|
12
12
|
}
|
|
13
|
-
declare function bind(data: Awaited<ReturnType<typeof Factory>>,
|
|
13
|
+
declare function bind(data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): FastifyPluginCallback;
|
|
14
14
|
declare function Fastify(opts: RouteShorthandOptions): any;
|
|
15
15
|
|
|
16
16
|
export { Fastify, FastifyCtx, bind };
|
|
@@ -1,13 +1,13 @@
|
|
|
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 _chunkBXLBWRHSjs = require('../../chunk-BXLBWRHS.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkYERBWZCSjs = require('../../chunk-YERBWZCS.js');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
@@ -15,13 +15,11 @@ var _chunkYR5Q5F2Kjs = require('../../chunk-YR5Q5F2K.js');
|
|
|
15
15
|
// src/server/fastify/bind.ts
|
|
16
16
|
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
17
17
|
var debug = _debug2.default.call(void 0, "phecda-server/fastify");
|
|
18
|
-
function bind(data,
|
|
19
|
-
const { globalGuards, globalInterceptors, route, plugins } = {
|
|
18
|
+
function bind(data, opts = {}) {
|
|
19
|
+
const { globalGuards, globalInterceptors, route, plugins, globalFilter, globalPipe } = {
|
|
20
20
|
route: "/__PHECDA_SERVER__",
|
|
21
|
-
globalGuards: [],
|
|
22
|
-
globalInterceptors: [],
|
|
23
21
|
plugins: [],
|
|
24
|
-
...
|
|
22
|
+
...opts
|
|
25
23
|
};
|
|
26
24
|
const { moduleMap, meta } = data;
|
|
27
25
|
const metaMap = /* @__PURE__ */ new Map();
|
|
@@ -32,14 +30,6 @@ function bind(data, ServerOptions = {}) {
|
|
|
32
30
|
if (controller !== "http" || !_optionalChain([http, 'optionalAccess', _2 => _2.type]))
|
|
33
31
|
continue;
|
|
34
32
|
debug(`register method "${func}" in module "${tag}"`);
|
|
35
|
-
item.data.guards = [
|
|
36
|
-
...globalGuards,
|
|
37
|
-
...item.data.guards
|
|
38
|
-
];
|
|
39
|
-
item.data.interceptors = [
|
|
40
|
-
...globalInterceptors,
|
|
41
|
-
...item.data.interceptors
|
|
42
|
-
];
|
|
43
33
|
if (metaMap.has(tag))
|
|
44
34
|
metaMap.get(tag)[func] = item;
|
|
45
35
|
else
|
|
@@ -49,14 +39,14 @@ function bind(data, ServerOptions = {}) {
|
|
|
49
39
|
}
|
|
50
40
|
}
|
|
51
41
|
_chunkYR5Q5F2Kjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
52
|
-
|
|
42
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
53
43
|
plugins,
|
|
54
44
|
guards: globalGuards,
|
|
55
45
|
interceptors: globalInterceptors
|
|
56
46
|
});
|
|
57
47
|
handleMeta();
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
_chunkYERBWZCSjs.HMR.call(void 0, async () => {
|
|
49
|
+
_chunkYERBWZCSjs.detectAopDep.call(void 0, meta, {
|
|
60
50
|
plugins,
|
|
61
51
|
guards: globalGuards,
|
|
62
52
|
interceptors: globalInterceptors
|
|
@@ -66,7 +56,7 @@ function bind(data, ServerOptions = {}) {
|
|
|
66
56
|
return (fastify, _, done) => {
|
|
67
57
|
fastify.register((fastify2, _opts, done2) => {
|
|
68
58
|
plugins.forEach((p) => {
|
|
69
|
-
const plugin =
|
|
59
|
+
const plugin = _chunkYERBWZCSjs.Context.usePlugin([
|
|
70
60
|
p
|
|
71
61
|
])[0];
|
|
72
62
|
if (plugin) {
|
|
@@ -77,22 +67,22 @@ function bind(data, ServerOptions = {}) {
|
|
|
77
67
|
fastify2.post(route, async (req, res) => {
|
|
78
68
|
const { body } = req;
|
|
79
69
|
async function errorHandler(e) {
|
|
80
|
-
const error = await
|
|
70
|
+
const error = await _chunkYERBWZCSjs.Context.filterRecord.default(e);
|
|
81
71
|
return res.status(error.status).send(error);
|
|
82
72
|
}
|
|
83
73
|
_chunkYR5Q5F2Kjs.__name.call(void 0, errorHandler, "errorHandler");
|
|
84
74
|
if (!Array.isArray(body))
|
|
85
|
-
return errorHandler(new (0,
|
|
75
|
+
return errorHandler(new (0, _chunkYERBWZCSjs.BadRequestException)("data format should be an array"));
|
|
86
76
|
try {
|
|
87
77
|
return Promise.all(body.map((item, i) => {
|
|
88
78
|
return new Promise(async (resolve) => {
|
|
89
79
|
const { tag, func } = item;
|
|
90
80
|
debug(`(parallel)invoke method "${func}" in module "${tag}"`);
|
|
91
81
|
if (!metaMap.has(tag))
|
|
92
|
-
return resolve(await
|
|
82
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`module "${tag}" doesn't exist`)));
|
|
93
83
|
const meta2 = metaMap.get(tag)[func];
|
|
94
84
|
if (!meta2)
|
|
95
|
-
return resolve(await
|
|
85
|
+
return resolve(await _chunkYERBWZCSjs.Context.filterRecord.default(new (0, _chunkYERBWZCSjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
|
|
96
86
|
const { data: { params } } = meta2;
|
|
97
87
|
const contextData = {
|
|
98
88
|
type: "fastify",
|
|
@@ -105,10 +95,15 @@ function bind(data, ServerOptions = {}) {
|
|
|
105
95
|
tag,
|
|
106
96
|
func,
|
|
107
97
|
app: fastify2,
|
|
108
|
-
...
|
|
98
|
+
..._chunkYERBWZCSjs.argToReq.call(void 0, params, item.args, req.headers)
|
|
109
99
|
};
|
|
110
|
-
const context = new (0,
|
|
111
|
-
context.run(
|
|
100
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
101
|
+
context.run({
|
|
102
|
+
globalGuards,
|
|
103
|
+
globalInterceptors,
|
|
104
|
+
globalFilter,
|
|
105
|
+
globalPipe
|
|
106
|
+
}, resolve, resolve);
|
|
112
107
|
});
|
|
113
108
|
})).then((ret) => {
|
|
114
109
|
res.send(ret);
|
|
@@ -126,7 +121,7 @@ function bind(data, ServerOptions = {}) {
|
|
|
126
121
|
if (!_optionalChain([http, 'optionalAccess', _3 => _3.type]))
|
|
127
122
|
continue;
|
|
128
123
|
fastify.register((fastify2, _opts, done2) => {
|
|
129
|
-
|
|
124
|
+
_chunkYERBWZCSjs.Context.usePlugin(plugins2).forEach((p) => {
|
|
130
125
|
p[Symbol.for("skip-override")] = true;
|
|
131
126
|
fastify2.register(p);
|
|
132
127
|
});
|
|
@@ -146,12 +141,17 @@ function bind(data, ServerOptions = {}) {
|
|
|
146
141
|
headers: req.headers,
|
|
147
142
|
app: fastify2
|
|
148
143
|
};
|
|
149
|
-
const context = new (0,
|
|
144
|
+
const context = new (0, _chunkYERBWZCSjs.Context)(contextData);
|
|
150
145
|
if (http.headers) {
|
|
151
146
|
for (const name in http.headers)
|
|
152
147
|
res.header(name, http.headers[name]);
|
|
153
148
|
}
|
|
154
|
-
return context.run(
|
|
149
|
+
return context.run({
|
|
150
|
+
globalGuards,
|
|
151
|
+
globalInterceptors,
|
|
152
|
+
globalFilter,
|
|
153
|
+
globalPipe
|
|
154
|
+
}, (returnData) => {
|
|
155
155
|
if (res.sent)
|
|
156
156
|
return;
|
|
157
157
|
return returnData;
|
|
@@ -170,7 +170,7 @@ function bind(data, ServerOptions = {}) {
|
|
|
170
170
|
}
|
|
171
171
|
_chunkYR5Q5F2Kjs.__name.call(void 0, bind, "bind");
|
|
172
172
|
function Fastify(opts) {
|
|
173
|
-
return
|
|
173
|
+
return _chunkBXLBWRHSjs.Define.call(void 0, "fastify", opts);
|
|
174
174
|
}
|
|
175
175
|
_chunkYR5Q5F2Kjs.__name.call(void 0, Fastify, "Fastify");
|
|
176
176
|
|