phecda-server 7.0.0-alpha.5 → 7.0.0-alpha.6
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-2ESEXJQM.mjs → chunk-3C7Z3IJN.mjs} +1 -1
- package/dist/{chunk-KFFS2P7I.js → chunk-62FBZWGW.js} +58 -27
- package/dist/{chunk-3ISYBU3P.mjs → chunk-HTY3H33L.mjs} +1 -1
- package/dist/{chunk-PXLG75ED.mjs → chunk-ICI5KUDX.mjs} +1 -1
- package/dist/{chunk-K54JYYXK.js → chunk-JF4YU32E.js} +51 -51
- package/dist/chunk-KSDE5G57.mjs +106 -0
- package/dist/{chunk-Y2OLA5OJ.js → chunk-UKRQVTEY.js} +24 -24
- package/dist/{chunk-TR5Z4SDI.js → chunk-WYI2F7LD.js} +19 -19
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/http/elysia/index.js +40 -40
- package/dist/http/elysia/index.mjs +3 -3
- package/dist/http/express/index.js +37 -37
- package/dist/http/express/index.mjs +2 -2
- package/dist/http/fastify/index.js +38 -38
- package/dist/http/fastify/index.mjs +3 -3
- package/dist/http/h3/index.js +37 -37
- package/dist/http/h3/index.mjs +2 -2
- package/dist/http/hono/index.js +35 -35
- package/dist/http/hono/index.mjs +2 -2
- package/dist/http/hyper-express/index.js +35 -35
- package/dist/http/hyper-express/index.mjs +2 -2
- package/dist/http/koa/index.js +37 -37
- package/dist/http/koa/index.mjs +2 -2
- package/dist/index.d.mts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +41 -38
- package/dist/index.mjs +7 -4
- package/dist/rpc/bullmq/index.js +14 -14
- package/dist/rpc/bullmq/index.mjs +2 -2
- package/dist/rpc/kafka/index.js +14 -14
- package/dist/rpc/kafka/index.mjs +2 -2
- package/dist/rpc/nats/index.js +13 -13
- package/dist/rpc/nats/index.mjs +2 -2
- package/dist/rpc/rabbitmq/index.js +15 -15
- package/dist/rpc/rabbitmq/index.mjs +2 -2
- package/dist/rpc/redis/index.js +13 -13
- package/dist/rpc/redis/index.mjs +2 -2
- package/dist/test.d.mts +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/package.json +1 -1
- package/dist/chunk-UXGJD2PK.mjs +0 -75
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _class;var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/common.ts
|
|
@@ -17,38 +17,69 @@ var PS_EXIT_CODE = /* @__PURE__ */ function(PS_EXIT_CODE2) {
|
|
|
17
17
|
// src/utils.ts
|
|
18
18
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
19
19
|
var _tsmixer = require('ts-mixer');
|
|
20
|
-
var
|
|
21
|
-
|
|
20
|
+
var InternalLogger = (_class = class InternalLogger2 {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
|
|
21
|
+
static {
|
|
22
|
+
__name(this, "InternalLogger");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
__init() {this.color = {
|
|
26
|
+
debug: "bgMagenta",
|
|
27
|
+
error: "red",
|
|
28
|
+
info: "gray",
|
|
29
|
+
warn: "yellow",
|
|
30
|
+
log: "green"
|
|
31
|
+
}}
|
|
32
|
+
__init2() {this.dateFormatter = new Intl.DateTimeFormat(void 0, {
|
|
33
|
+
year: "numeric",
|
|
34
|
+
hour: "numeric",
|
|
35
|
+
minute: "numeric",
|
|
36
|
+
second: "numeric",
|
|
37
|
+
day: "2-digit",
|
|
38
|
+
month: "2-digit"
|
|
39
|
+
})}
|
|
40
|
+
diffTimestamp() {
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
if (!this.time) return "";
|
|
43
|
+
const diff = now - this.time;
|
|
44
|
+
this.time = now;
|
|
45
|
+
return diff ? _picocolors2.default.yellow(` +${diff}`) : "";
|
|
46
|
+
}
|
|
47
|
+
colorize(message, logLevel) {
|
|
48
|
+
return _picocolors2.default[this.color[logLevel]](message);
|
|
49
|
+
}
|
|
50
|
+
isAllowLog(level) {
|
|
51
|
+
const logLevel = {
|
|
52
|
+
debug: -1,
|
|
53
|
+
info: 0,
|
|
54
|
+
log: 1,
|
|
55
|
+
warn: 2,
|
|
56
|
+
error: 3
|
|
57
|
+
}[level];
|
|
58
|
+
if (logLevel < LOG_LEVEL) return false;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
log(msg, level, ctx) {
|
|
62
|
+
if (!this.isAllowLog(level)) return;
|
|
63
|
+
msg = this.colorize(msg, level);
|
|
64
|
+
const pidMsg = this.colorize(`[phecda-server] ${process.pid}`, level);
|
|
65
|
+
const ctxMsg = ctx ? this.colorize(_picocolors2.default.bold(`[${ctx}] `), level) : "";
|
|
66
|
+
const timeDiff = this.diffTimestamp();
|
|
67
|
+
const levelMsg = this.colorize(level.toUpperCase().padStart(7, " "), level);
|
|
68
|
+
process.stdout.write(`${pidMsg} ${this.dateFormatter.format(Date.now())} ${levelMsg} ${ctxMsg}${msg}${timeDiff}
|
|
69
|
+
`);
|
|
70
|
+
}
|
|
71
|
+
}, _class);
|
|
72
|
+
var _logger = new InternalLogger();
|
|
22
73
|
function setLogger(logger) {
|
|
23
|
-
|
|
74
|
+
_logger = logger;
|
|
24
75
|
}
|
|
25
76
|
__name(setLogger, "setLogger");
|
|
26
77
|
function getLogger() {
|
|
27
|
-
return
|
|
78
|
+
return _logger;
|
|
28
79
|
}
|
|
29
80
|
__name(getLogger, "getLogger");
|
|
30
|
-
function log(msg, level = "log") {
|
|
31
|
-
|
|
32
|
-
const logLevel = {
|
|
33
|
-
debug: -1,
|
|
34
|
-
info: 0,
|
|
35
|
-
log: 1,
|
|
36
|
-
warn: 2,
|
|
37
|
-
error: 3
|
|
38
|
-
}[level];
|
|
39
|
-
if (logLevel < LOG_LEVEL) return;
|
|
40
|
-
const color = {
|
|
41
|
-
debug: "bgMagenta",
|
|
42
|
-
error: "red",
|
|
43
|
-
info: "gray",
|
|
44
|
-
warn: "yellow",
|
|
45
|
-
log: "green"
|
|
46
|
-
}[level];
|
|
47
|
-
const date = /* @__PURE__ */ new Date();
|
|
48
|
-
const current = Date.now();
|
|
49
|
-
const interval = time && current - time ? `+${current - time}` : "";
|
|
50
|
-
time = current;
|
|
51
|
-
console[level](`${_picocolors2.default.magenta("[phecda-server]")} ${_picocolors2.default.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${_picocolors2.default[color](msg)} ${_picocolors2.default.gray(interval)}`);
|
|
81
|
+
function log(msg, level = "log", ctx) {
|
|
82
|
+
_logger.log(msg, level, ctx);
|
|
52
83
|
}
|
|
53
84
|
__name(log, "log");
|
|
54
85
|
function runMiddleware(ctx, middleware) {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunk62FBZWGWjs = require('./chunk-62FBZWGW.js');
|
|
9
9
|
|
|
10
10
|
// src/helper.ts
|
|
11
11
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
@@ -15,14 +15,14 @@ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
// src/pipe.ts
|
|
18
|
-
var defaultPipe = /* @__PURE__ */
|
|
18
|
+
var defaultPipe = /* @__PURE__ */ _chunk62FBZWGWjs.__name.call(void 0, ({ arg }) => {
|
|
19
19
|
return arg;
|
|
20
20
|
}, "defaultPipe");
|
|
21
21
|
|
|
22
22
|
// src/exception/base.ts
|
|
23
23
|
var Exception = class extends Error {
|
|
24
24
|
static {
|
|
25
|
-
|
|
25
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "Exception");
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
|
|
@@ -35,7 +35,7 @@ var Exception = class extends Error {
|
|
|
35
35
|
message: this.message,
|
|
36
36
|
description: this.description,
|
|
37
37
|
status: this.status,
|
|
38
|
-
[
|
|
38
|
+
[_chunk62FBZWGWjs.ERROR_SYMBOL]: true
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
};
|
|
@@ -43,7 +43,7 @@ var Exception = class extends Error {
|
|
|
43
43
|
// src/exception/undefine.ts
|
|
44
44
|
var UndefinedException = class extends Exception {
|
|
45
45
|
static {
|
|
46
|
-
|
|
46
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "UndefinedException");
|
|
47
47
|
}
|
|
48
48
|
constructor(message) {
|
|
49
49
|
super(message, 500, "Undefined error");
|
|
@@ -53,7 +53,7 @@ var UndefinedException = class extends Exception {
|
|
|
53
53
|
// src/exception/validate.ts
|
|
54
54
|
var ValidateException = class extends Exception {
|
|
55
55
|
static {
|
|
56
|
-
|
|
56
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "ValidateException");
|
|
57
57
|
}
|
|
58
58
|
constructor(message) {
|
|
59
59
|
super(message, 400, "Validate exception");
|
|
@@ -63,7 +63,7 @@ var ValidateException = class extends Exception {
|
|
|
63
63
|
// src/exception/forbidden.ts
|
|
64
64
|
var ForbiddenException = class extends Exception {
|
|
65
65
|
static {
|
|
66
|
-
|
|
66
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "ForbiddenException");
|
|
67
67
|
}
|
|
68
68
|
constructor(message) {
|
|
69
69
|
super(message, 403, "Forbidden resource");
|
|
@@ -73,7 +73,7 @@ var ForbiddenException = class extends Exception {
|
|
|
73
73
|
// src/exception/bad-request.ts
|
|
74
74
|
var BadRequestException = class extends Exception {
|
|
75
75
|
static {
|
|
76
|
-
|
|
76
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "BadRequestException");
|
|
77
77
|
}
|
|
78
78
|
constructor(message) {
|
|
79
79
|
super(message, 400, "Bad Request");
|
|
@@ -83,7 +83,7 @@ var BadRequestException = class extends Exception {
|
|
|
83
83
|
// src/exception/not-found.ts
|
|
84
84
|
var NotFoundException = class extends Exception {
|
|
85
85
|
static {
|
|
86
|
-
|
|
86
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "NotFoundException");
|
|
87
87
|
}
|
|
88
88
|
constructor(message) {
|
|
89
89
|
super(message, 404, "Not Found");
|
|
@@ -93,7 +93,7 @@ var NotFoundException = class extends Exception {
|
|
|
93
93
|
// src/exception/conflict.ts
|
|
94
94
|
var ConflictException = class extends Exception {
|
|
95
95
|
static {
|
|
96
|
-
|
|
96
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "ConflictException");
|
|
97
97
|
}
|
|
98
98
|
constructor(message) {
|
|
99
99
|
super(message, 409, "Conflict");
|
|
@@ -103,7 +103,7 @@ var ConflictException = class extends Exception {
|
|
|
103
103
|
// src/exception/bad-gateway.ts
|
|
104
104
|
var BadGatewayException = class extends Exception {
|
|
105
105
|
static {
|
|
106
|
-
|
|
106
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "BadGatewayException");
|
|
107
107
|
}
|
|
108
108
|
constructor(message) {
|
|
109
109
|
super(message, 502, "Bad Gatrway");
|
|
@@ -113,7 +113,7 @@ var BadGatewayException = class extends Exception {
|
|
|
113
113
|
// src/exception/invalid-input.ts
|
|
114
114
|
var InvalidInputException = class extends Exception {
|
|
115
115
|
static {
|
|
116
|
-
|
|
116
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "InvalidInputException");
|
|
117
117
|
}
|
|
118
118
|
constructor(message) {
|
|
119
119
|
super(message, 502, "Invalid Input");
|
|
@@ -123,7 +123,7 @@ var InvalidInputException = class extends Exception {
|
|
|
123
123
|
// src/exception/media-type.ts
|
|
124
124
|
var UnsupportedMediaTypeException = class extends Exception {
|
|
125
125
|
static {
|
|
126
|
-
|
|
126
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "UnsupportedMediaTypeException");
|
|
127
127
|
}
|
|
128
128
|
constructor(message) {
|
|
129
129
|
super(message, 415, "Unsupported Media Type");
|
|
@@ -133,7 +133,7 @@ var UnsupportedMediaTypeException = class extends Exception {
|
|
|
133
133
|
// src/exception/payload-large.ts
|
|
134
134
|
var PayloadLargeException = class extends Exception {
|
|
135
135
|
static {
|
|
136
|
-
|
|
136
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "PayloadLargeException");
|
|
137
137
|
}
|
|
138
138
|
constructor(message) {
|
|
139
139
|
super(message, 413, "Payload Too Large");
|
|
@@ -143,7 +143,7 @@ var PayloadLargeException = class extends Exception {
|
|
|
143
143
|
// src/exception/timeout.ts
|
|
144
144
|
var TimeoutException = class extends Exception {
|
|
145
145
|
static {
|
|
146
|
-
|
|
146
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "TimeoutException");
|
|
147
147
|
}
|
|
148
148
|
constructor(message) {
|
|
149
149
|
super(message, 408, "Request Timeout");
|
|
@@ -153,7 +153,7 @@ var TimeoutException = class extends Exception {
|
|
|
153
153
|
// src/exception/unauthorized.ts
|
|
154
154
|
var UnauthorizedException = class extends Exception {
|
|
155
155
|
static {
|
|
156
|
-
|
|
156
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "UnauthorizedException");
|
|
157
157
|
}
|
|
158
158
|
constructor(message) {
|
|
159
159
|
super(message, 401, "Unauthorized");
|
|
@@ -163,7 +163,7 @@ var UnauthorizedException = class extends Exception {
|
|
|
163
163
|
// src/exception/unavailable-service.ts
|
|
164
164
|
var ServiceUnavailableException = class extends Exception {
|
|
165
165
|
static {
|
|
166
|
-
|
|
166
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "ServiceUnavailableException");
|
|
167
167
|
}
|
|
168
168
|
constructor(message) {
|
|
169
169
|
super(message, 503, "Service Unavailable");
|
|
@@ -173,7 +173,7 @@ var ServiceUnavailableException = class extends Exception {
|
|
|
173
173
|
// src/exception/framework.ts
|
|
174
174
|
var FrameworkException = class extends Exception {
|
|
175
175
|
static {
|
|
176
|
-
|
|
176
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "FrameworkException");
|
|
177
177
|
}
|
|
178
178
|
constructor(message) {
|
|
179
179
|
super(`[phecda-server] ${message}`, 500, "Framework Error");
|
|
@@ -183,7 +183,7 @@ var FrameworkException = class extends Exception {
|
|
|
183
183
|
// src/exception/timer.ts
|
|
184
184
|
var TimerException = class extends Exception {
|
|
185
185
|
static {
|
|
186
|
-
|
|
186
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "TimerException");
|
|
187
187
|
}
|
|
188
188
|
constructor(message) {
|
|
189
189
|
super(message, 0, "Timer Error");
|
|
@@ -193,7 +193,7 @@ var TimerException = class extends Exception {
|
|
|
193
193
|
// src/exception/worker.ts
|
|
194
194
|
var WorkerException = class extends Exception {
|
|
195
195
|
static {
|
|
196
|
-
|
|
196
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "WorkerException");
|
|
197
197
|
}
|
|
198
198
|
constructor(message) {
|
|
199
199
|
super(message, 0, "Worker Error");
|
|
@@ -201,14 +201,14 @@ var WorkerException = class extends Exception {
|
|
|
201
201
|
};
|
|
202
202
|
|
|
203
203
|
// src/filter.ts
|
|
204
|
-
var defaultFilter = /* @__PURE__ */
|
|
204
|
+
var defaultFilter = /* @__PURE__ */ _chunk62FBZWGWjs.__name.call(void 0, (e) => {
|
|
205
205
|
if (!(e instanceof Exception)) {
|
|
206
|
-
|
|
207
|
-
if (
|
|
206
|
+
_chunk62FBZWGWjs.log.call(void 0, e.message, "error");
|
|
207
|
+
if (_chunk62FBZWGWjs.LOG_LEVEL <= 0) console.error(e.stack);
|
|
208
208
|
e = new UndefinedException(e.message || e);
|
|
209
209
|
} else {
|
|
210
|
-
|
|
211
|
-
if (
|
|
210
|
+
_chunk62FBZWGWjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
|
|
211
|
+
if (_chunk62FBZWGWjs.LOG_LEVEL <= 0) console.error(e.stack);
|
|
212
212
|
}
|
|
213
213
|
return e.data;
|
|
214
214
|
}, "defaultFilter");
|
|
@@ -217,7 +217,7 @@ var defaultFilter = /* @__PURE__ */ _chunkKFFS2P7Ijs.__name.call(void 0, (e) =>
|
|
|
217
217
|
var debug = _debug2.default.call(void 0, "phecda-server(Context)");
|
|
218
218
|
var Context = (_class = class _Context {
|
|
219
219
|
static {
|
|
220
|
-
|
|
220
|
+
_chunk62FBZWGWjs.__name.call(void 0, this, "Context");
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
|
|
@@ -232,7 +232,7 @@ var Context = (_class = class _Context {
|
|
|
232
232
|
static __initStatic4() {this.addonRecord = {}}
|
|
233
233
|
constructor(data) {
|
|
234
234
|
this.data = data;
|
|
235
|
-
if (
|
|
235
|
+
if (_chunk62FBZWGWjs.IS_HMR)
|
|
236
236
|
data._context = this;
|
|
237
237
|
}
|
|
238
238
|
static getAop(meta, opts) {
|
|
@@ -264,7 +264,7 @@ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
264
264
|
const { paramsType, data: { ctxs, tag, params, func } } = meta;
|
|
265
265
|
try {
|
|
266
266
|
let res;
|
|
267
|
-
const nextHandler = /* @__PURE__ */
|
|
267
|
+
const nextHandler = /* @__PURE__ */ _chunk62FBZWGWjs.__name.call(void 0, (index) => {
|
|
268
268
|
return async () => {
|
|
269
269
|
if (index === guards.length) {
|
|
270
270
|
const instance = moduleMap.get(tag);
|
|
@@ -288,7 +288,7 @@ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
288
288
|
return res;
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
-
|
|
291
|
+
_chunk62FBZWGWjs.__name.call(void 0, next, "next");
|
|
292
292
|
const ret = await guards[index](this.data, next);
|
|
293
293
|
if (ret !== void 0) {
|
|
294
294
|
res = ret;
|
|
@@ -333,12 +333,12 @@ function addPipe(key, pipe) {
|
|
|
333
333
|
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) debug(`overwrite Pipe "${String(key)}"`, "warn");
|
|
334
334
|
Context.pipeRecord[key] = pipe;
|
|
335
335
|
}
|
|
336
|
-
|
|
336
|
+
_chunk62FBZWGWjs.__name.call(void 0, addPipe, "addPipe");
|
|
337
337
|
function addFilter(key, filter) {
|
|
338
338
|
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) debug(`overwrite Filter "${String(key)}"`, "warn");
|
|
339
339
|
Context.filterRecord[key] = filter;
|
|
340
340
|
}
|
|
341
|
-
|
|
341
|
+
_chunk62FBZWGWjs.__name.call(void 0, addFilter, "addFilter");
|
|
342
342
|
function addGuard(key, guard, priority = 0) {
|
|
343
343
|
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) debug(`overwrite Guard "${String(key)}"`, "warn");
|
|
344
344
|
Context.guardRecord[key] = {
|
|
@@ -346,7 +346,7 @@ function addGuard(key, guard, priority = 0) {
|
|
|
346
346
|
priority
|
|
347
347
|
};
|
|
348
348
|
}
|
|
349
|
-
|
|
349
|
+
_chunk62FBZWGWjs.__name.call(void 0, addGuard, "addGuard");
|
|
350
350
|
function addAddon(key, addon, priority = 0) {
|
|
351
351
|
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) debug(`overwrite Addon "${String(key)}"`, "warn");
|
|
352
352
|
Context.addonRecord[key] = {
|
|
@@ -354,20 +354,20 @@ function addAddon(key, addon, priority = 0) {
|
|
|
354
354
|
priority
|
|
355
355
|
};
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
_chunk62FBZWGWjs.__name.call(void 0, addAddon, "addAddon");
|
|
358
358
|
|
|
359
359
|
// src/hmr.ts
|
|
360
360
|
function HMR(cb) {
|
|
361
|
-
if (
|
|
361
|
+
if (_chunk62FBZWGWjs.IS_HMR) _optionalChain([globalThis, 'access', _ => _.__PS_HMR__, 'optionalAccess', _2 => _2.push, 'call', _3 => _3(cb)]);
|
|
362
362
|
}
|
|
363
|
-
|
|
363
|
+
_chunk62FBZWGWjs.__name.call(void 0, HMR, "HMR");
|
|
364
364
|
|
|
365
365
|
// src/http/helper.ts
|
|
366
366
|
function resolveDep(ret, key) {
|
|
367
367
|
if (key) return _optionalChain([ret, 'optionalAccess', _4 => _4[key]]);
|
|
368
368
|
return ret;
|
|
369
369
|
}
|
|
370
|
-
|
|
370
|
+
_chunk62FBZWGWjs.__name.call(void 0, resolveDep, "resolveDep");
|
|
371
371
|
function argToReq(params, args, headers) {
|
|
372
372
|
const req = {
|
|
373
373
|
body: {},
|
|
@@ -381,14 +381,14 @@ function argToReq(params, args, headers) {
|
|
|
381
381
|
});
|
|
382
382
|
return req;
|
|
383
383
|
}
|
|
384
|
-
|
|
384
|
+
_chunk62FBZWGWjs.__name.call(void 0, argToReq, "argToReq");
|
|
385
385
|
|
|
386
386
|
// src/rpc/helper.ts
|
|
387
387
|
var _os = require('os');
|
|
388
388
|
function genClientQueue(key) {
|
|
389
389
|
return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
|
|
390
390
|
}
|
|
391
|
-
|
|
391
|
+
_chunk62FBZWGWjs.__name.call(void 0, genClientQueue, "genClientQueue");
|
|
392
392
|
|
|
393
393
|
// src/decorators/helper.ts
|
|
394
394
|
function shallowClone(obj) {
|
|
@@ -396,11 +396,11 @@ function shallowClone(obj) {
|
|
|
396
396
|
...obj
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
|
-
|
|
399
|
+
_chunk62FBZWGWjs.__name.call(void 0, shallowClone, "shallowClone");
|
|
400
400
|
function mergeObject(...args) {
|
|
401
401
|
return Object.assign({}, ...args);
|
|
402
402
|
}
|
|
403
|
-
|
|
403
|
+
_chunk62FBZWGWjs.__name.call(void 0, mergeObject, "mergeObject");
|
|
404
404
|
|
|
405
405
|
// src/helper.ts
|
|
406
406
|
function createControllerMetaMap(meta, filter) {
|
|
@@ -416,12 +416,12 @@ function createControllerMetaMap(meta, filter) {
|
|
|
416
416
|
});
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
|
-
|
|
419
|
+
_chunk62FBZWGWjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
420
420
|
handleMeta();
|
|
421
421
|
HMR(handleMeta);
|
|
422
422
|
return metaMap;
|
|
423
423
|
}
|
|
424
|
-
|
|
424
|
+
_chunk62FBZWGWjs.__name.call(void 0, createControllerMetaMap, "createControllerMetaMap");
|
|
425
425
|
function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
426
426
|
const addonSet = /* @__PURE__ */ new Set();
|
|
427
427
|
const guardSet = /* @__PURE__ */ new Set();
|
|
@@ -465,29 +465,29 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
465
465
|
...filterSet
|
|
466
466
|
].filter((i) => !Context.filterRecord[i]);
|
|
467
467
|
function exit() {
|
|
468
|
-
if (
|
|
468
|
+
if (_chunk62FBZWGWjs.IS_STRICT) process.exit(5);
|
|
469
469
|
}
|
|
470
|
-
|
|
470
|
+
_chunk62FBZWGWjs.__name.call(void 0, exit, "exit");
|
|
471
471
|
if (missAddons.length) {
|
|
472
|
-
|
|
472
|
+
_chunk62FBZWGWjs.log.call(void 0, `${_picocolors2.default.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
|
|
473
473
|
exit();
|
|
474
474
|
}
|
|
475
475
|
if (missGuards.length) {
|
|
476
|
-
|
|
476
|
+
_chunk62FBZWGWjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
477
477
|
exit();
|
|
478
478
|
}
|
|
479
479
|
if (missPipes.length) {
|
|
480
|
-
|
|
480
|
+
_chunk62FBZWGWjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
481
481
|
exit();
|
|
482
482
|
}
|
|
483
483
|
if (missFilters.length) {
|
|
484
|
-
|
|
484
|
+
_chunk62FBZWGWjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
485
485
|
exit();
|
|
486
486
|
}
|
|
487
|
-
warningSet.forEach((warn) =>
|
|
487
|
+
warningSet.forEach((warn) => _chunk62FBZWGWjs.log.call(void 0, warn, "warn"));
|
|
488
488
|
if (warningSet.size) exit();
|
|
489
489
|
}
|
|
490
|
-
|
|
490
|
+
_chunk62FBZWGWjs.__name.call(void 0, handleMeta, "handleMeta");
|
|
491
491
|
handleMeta();
|
|
492
492
|
HMR(handleMeta);
|
|
493
493
|
return {
|
|
@@ -497,7 +497,7 @@ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
|
497
497
|
filterSet
|
|
498
498
|
};
|
|
499
499
|
}
|
|
500
|
-
|
|
500
|
+
_chunk62FBZWGWjs.__name.call(void 0, detectAopDep, "detectAopDep");
|
|
501
501
|
|
|
502
502
|
|
|
503
503
|
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/common.ts
|
|
5
|
+
var ERROR_SYMBOL = "__PS_ERROR__";
|
|
6
|
+
var IS_HMR = process.env.NODE_ENV === "development";
|
|
7
|
+
var IS_ONLY_GENERATE = !!process.env.PS_GENERATE;
|
|
8
|
+
var IS_STRICT = !!process.env.PS_STRICT;
|
|
9
|
+
var LOG_LEVEL = Number(process.env.PS_LOG_LEVEL || 0);
|
|
10
|
+
var IS_READY = Symbol("IS_READY");
|
|
11
|
+
var PS_EXIT_CODE = /* @__PURE__ */ function(PS_EXIT_CODE2) {
|
|
12
|
+
PS_EXIT_CODE2[PS_EXIT_CODE2["RELAUNCH"] = 2] = "RELAUNCH";
|
|
13
|
+
PS_EXIT_CODE2[PS_EXIT_CODE2["CODE"] = 4] = "CODE";
|
|
14
|
+
return PS_EXIT_CODE2;
|
|
15
|
+
}({});
|
|
16
|
+
|
|
17
|
+
// src/utils.ts
|
|
18
|
+
import pc from "picocolors";
|
|
19
|
+
import { Mixin } from "ts-mixer";
|
|
20
|
+
var InternalLogger = class InternalLogger2 {
|
|
21
|
+
static {
|
|
22
|
+
__name(this, "InternalLogger");
|
|
23
|
+
}
|
|
24
|
+
time;
|
|
25
|
+
color = {
|
|
26
|
+
debug: "bgMagenta",
|
|
27
|
+
error: "red",
|
|
28
|
+
info: "gray",
|
|
29
|
+
warn: "yellow",
|
|
30
|
+
log: "green"
|
|
31
|
+
};
|
|
32
|
+
dateFormatter = new Intl.DateTimeFormat(void 0, {
|
|
33
|
+
year: "numeric",
|
|
34
|
+
hour: "numeric",
|
|
35
|
+
minute: "numeric",
|
|
36
|
+
second: "numeric",
|
|
37
|
+
day: "2-digit",
|
|
38
|
+
month: "2-digit"
|
|
39
|
+
});
|
|
40
|
+
diffTimestamp() {
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
if (!this.time) return "";
|
|
43
|
+
const diff = now - this.time;
|
|
44
|
+
this.time = now;
|
|
45
|
+
return diff ? pc.yellow(` +${diff}`) : "";
|
|
46
|
+
}
|
|
47
|
+
colorize(message, logLevel) {
|
|
48
|
+
return pc[this.color[logLevel]](message);
|
|
49
|
+
}
|
|
50
|
+
isAllowLog(level) {
|
|
51
|
+
const logLevel = {
|
|
52
|
+
debug: -1,
|
|
53
|
+
info: 0,
|
|
54
|
+
log: 1,
|
|
55
|
+
warn: 2,
|
|
56
|
+
error: 3
|
|
57
|
+
}[level];
|
|
58
|
+
if (logLevel < LOG_LEVEL) return false;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
log(msg, level, ctx) {
|
|
62
|
+
if (!this.isAllowLog(level)) return;
|
|
63
|
+
msg = this.colorize(msg, level);
|
|
64
|
+
const pidMsg = this.colorize(`[phecda-server] ${process.pid}`, level);
|
|
65
|
+
const ctxMsg = ctx ? this.colorize(pc.bold(`[${ctx}] `), level) : "";
|
|
66
|
+
const timeDiff = this.diffTimestamp();
|
|
67
|
+
const levelMsg = this.colorize(level.toUpperCase().padStart(7, " "), level);
|
|
68
|
+
process.stdout.write(`${pidMsg} ${this.dateFormatter.format(Date.now())} ${levelMsg} ${ctxMsg}${msg}${timeDiff}
|
|
69
|
+
`);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var _logger = new InternalLogger();
|
|
73
|
+
function setLogger(logger) {
|
|
74
|
+
_logger = logger;
|
|
75
|
+
}
|
|
76
|
+
__name(setLogger, "setLogger");
|
|
77
|
+
function getLogger() {
|
|
78
|
+
return _logger;
|
|
79
|
+
}
|
|
80
|
+
__name(getLogger, "getLogger");
|
|
81
|
+
function log(msg, level = "log", ctx) {
|
|
82
|
+
_logger.log(msg, level, ctx);
|
|
83
|
+
}
|
|
84
|
+
__name(log, "log");
|
|
85
|
+
function runMiddleware(ctx, middleware) {
|
|
86
|
+
return new Promise((resolve) => {
|
|
87
|
+
middleware(ctx.getRequest(), ctx.getResponse(), resolve);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
__name(runMiddleware, "runMiddleware");
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
__name,
|
|
94
|
+
ERROR_SYMBOL,
|
|
95
|
+
IS_HMR,
|
|
96
|
+
IS_ONLY_GENERATE,
|
|
97
|
+
IS_STRICT,
|
|
98
|
+
LOG_LEVEL,
|
|
99
|
+
IS_READY,
|
|
100
|
+
PS_EXIT_CODE,
|
|
101
|
+
setLogger,
|
|
102
|
+
getLogger,
|
|
103
|
+
log,
|
|
104
|
+
runMiddleware,
|
|
105
|
+
Mixin
|
|
106
|
+
};
|