phecda-server 4.0.7 → 4.1.0
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-JZGLQ4FQ.js → chunk-32E425F6.js} +55 -55
- package/dist/chunk-32E425F6.js.map +1 -0
- package/dist/{chunk-DQUH5BP6.mjs → chunk-5KOB2WHH.mjs} +1 -1
- package/dist/{chunk-DQUH5BP6.mjs.map → chunk-5KOB2WHH.mjs.map} +1 -1
- package/dist/{chunk-WWYSLFOI.js → chunk-5L4K7XEB.js} +33 -31
- package/dist/chunk-5L4K7XEB.js.map +1 -0
- package/dist/{chunk-FCLWCFQS.js → chunk-63KBHOSB.js} +3 -3
- package/dist/{chunk-ZZ2QKZ46.js → chunk-BDIQWWHN.js} +1 -1
- package/dist/{chunk-ZZ2QKZ46.js.map → chunk-BDIQWWHN.js.map} +1 -1
- package/dist/{chunk-43ZXHSVH.mjs → chunk-Q3V3ERU3.mjs} +2 -2
- package/dist/{chunk-F5PQVQTY.mjs → chunk-WQBXOVND.mjs} +16 -14
- package/dist/chunk-WQBXOVND.mjs.map +1 -0
- package/dist/{chunk-ATMZNJSE.mjs → chunk-Z6LSJTOF.mjs} +11 -11
- package/dist/chunk-Z6LSJTOF.mjs.map +1 -0
- package/dist/{core-72951cf9.d.ts → core-d080d872.d.ts} +21 -13
- package/dist/index.d.ts +24 -25
- package/dist/index.js +57 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/rpc/rabbitmq/index.d.ts +2 -5
- package/dist/rpc/rabbitmq/index.js +22 -20
- package/dist/rpc/rabbitmq/index.js.map +1 -1
- package/dist/rpc/rabbitmq/index.mjs +17 -15
- package/dist/rpc/rabbitmq/index.mjs.map +1 -1
- package/dist/rpc/redis/index.d.ts +2 -5
- package/dist/rpc/redis/index.js +23 -21
- package/dist/rpc/redis/index.js.map +1 -1
- package/dist/rpc/redis/index.mjs +18 -16
- package/dist/rpc/redis/index.mjs.map +1 -1
- package/dist/server/express/index.d.ts +2 -5
- package/dist/server/express/index.js +28 -26
- package/dist/server/express/index.js.map +1 -1
- package/dist/server/express/index.mjs +9 -7
- package/dist/server/express/index.mjs.map +1 -1
- package/dist/server/fastify/index.d.ts +2 -5
- package/dist/server/fastify/index.js +26 -24
- package/dist/server/fastify/index.js.map +1 -1
- package/dist/server/fastify/index.mjs +9 -7
- package/dist/server/fastify/index.mjs.map +1 -1
- package/dist/server/h3/index.d.ts +2 -5
- package/dist/server/h3/index.js +28 -26
- package/dist/server/h3/index.js.map +1 -1
- package/dist/server/h3/index.mjs +9 -7
- package/dist/server/h3/index.mjs.map +1 -1
- package/dist/server/koa/index.d.ts +2 -5
- package/dist/server/koa/index.js +28 -26
- package/dist/server/koa/index.js.map +1 -1
- package/dist/server/koa/index.mjs +9 -7
- package/dist/server/koa/index.mjs.map +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +5 -5
- package/dist/test.mjs +2 -2
- package/package.json +1 -1
- package/dist/chunk-ATMZNJSE.mjs.map +0 -1
- package/dist/chunk-F5PQVQTY.mjs.map +0 -1
- package/dist/chunk-JZGLQ4FQ.js.map +0 -1
- package/dist/chunk-WWYSLFOI.js.map +0 -1
- /package/dist/{chunk-FCLWCFQS.js.map → chunk-63KBHOSB.js.map} +0 -0
- /package/dist/{chunk-43ZXHSVH.mjs.map → chunk-Q3V3ERU3.mjs.map} +0 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkBDIQWWHNjs = require('./chunk-BDIQWWHN.js');
|
|
9
9
|
|
|
10
10
|
// src/exception/base.ts
|
|
11
11
|
var Exception = class extends Error {
|
|
@@ -23,11 +23,11 @@ var Exception = class extends Error {
|
|
|
23
23
|
message: this.message,
|
|
24
24
|
description: this.description,
|
|
25
25
|
status: this.status,
|
|
26
|
-
[
|
|
26
|
+
[_chunkBDIQWWHNjs.ERROR_SYMBOL]: true
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
_chunkBDIQWWHNjs.__name.call(void 0, Exception, "Exception");
|
|
31
31
|
|
|
32
32
|
// src/exception/validate.ts
|
|
33
33
|
var ValidateException = class extends Exception {
|
|
@@ -35,11 +35,11 @@ var ValidateException = class extends Exception {
|
|
|
35
35
|
super(message, 400, "Validate exception");
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
_chunkBDIQWWHNjs.__name.call(void 0, ValidateException, "ValidateException");
|
|
39
39
|
|
|
40
40
|
// src/pipe.ts
|
|
41
41
|
var _phecdacore = require('phecda-core');
|
|
42
|
-
var defaultPipe = /* @__PURE__ */
|
|
42
|
+
var defaultPipe = /* @__PURE__ */ _chunkBDIQWWHNjs.__name.call(void 0, async ({ arg, reflect, index }) => {
|
|
43
43
|
if (_phecdacore.isPhecda.call(void 0, reflect)) {
|
|
44
44
|
const instance = _phecdacore.plainToClass.call(void 0, reflect, arg);
|
|
45
45
|
const err = await _phecdacore.transformClass.call(void 0, instance);
|
|
@@ -65,7 +65,7 @@ var UndefinedException = class extends Exception {
|
|
|
65
65
|
super(message, 500, "Undefined error");
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
-
|
|
68
|
+
_chunkBDIQWWHNjs.__name.call(void 0, UndefinedException, "UndefinedException");
|
|
69
69
|
|
|
70
70
|
// src/exception/forbidden.ts
|
|
71
71
|
var ForbiddenException = class extends Exception {
|
|
@@ -73,7 +73,7 @@ var ForbiddenException = class extends Exception {
|
|
|
73
73
|
super(message, 403, "Forbidden resource");
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
_chunkBDIQWWHNjs.__name.call(void 0, ForbiddenException, "ForbiddenException");
|
|
77
77
|
|
|
78
78
|
// src/exception/bad-request.ts
|
|
79
79
|
var BadRequestException = class extends Exception {
|
|
@@ -81,7 +81,7 @@ var BadRequestException = class extends Exception {
|
|
|
81
81
|
super(message, 400, "Bad Request");
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
|
-
|
|
84
|
+
_chunkBDIQWWHNjs.__name.call(void 0, BadRequestException, "BadRequestException");
|
|
85
85
|
|
|
86
86
|
// src/exception/not-found.ts
|
|
87
87
|
var NotFoundException = class extends Exception {
|
|
@@ -89,7 +89,7 @@ var NotFoundException = class extends Exception {
|
|
|
89
89
|
super(message, 404, "Not Found");
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
|
|
92
|
+
_chunkBDIQWWHNjs.__name.call(void 0, NotFoundException, "NotFoundException");
|
|
93
93
|
|
|
94
94
|
// src/exception/conflict.ts
|
|
95
95
|
var ConflictException = class extends Exception {
|
|
@@ -97,7 +97,7 @@ var ConflictException = class extends Exception {
|
|
|
97
97
|
super(message, 409, "Conflict");
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
|
|
100
|
+
_chunkBDIQWWHNjs.__name.call(void 0, ConflictException, "ConflictException");
|
|
101
101
|
|
|
102
102
|
// src/exception/bad-gateway.ts
|
|
103
103
|
var BadGatewayException = class extends Exception {
|
|
@@ -105,7 +105,7 @@ var BadGatewayException = class extends Exception {
|
|
|
105
105
|
super(message, 502, "Bad Gatrway");
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
|
-
|
|
108
|
+
_chunkBDIQWWHNjs.__name.call(void 0, BadGatewayException, "BadGatewayException");
|
|
109
109
|
|
|
110
110
|
// src/exception/invalid-input.ts
|
|
111
111
|
var InvalidInputException = class extends Exception {
|
|
@@ -113,7 +113,7 @@ var InvalidInputException = class extends Exception {
|
|
|
113
113
|
super(message, 502, "Invalid Input");
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
-
|
|
116
|
+
_chunkBDIQWWHNjs.__name.call(void 0, InvalidInputException, "InvalidInputException");
|
|
117
117
|
|
|
118
118
|
// src/exception/media-type.ts
|
|
119
119
|
var UnsupportedMediaTypeException = class extends Exception {
|
|
@@ -121,7 +121,7 @@ var UnsupportedMediaTypeException = class extends Exception {
|
|
|
121
121
|
super(message, 415, "Unsupported Media Type");
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
|
-
|
|
124
|
+
_chunkBDIQWWHNjs.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
|
|
125
125
|
|
|
126
126
|
// src/exception/payload-large.ts
|
|
127
127
|
var PayloadLargeException = class extends Exception {
|
|
@@ -129,7 +129,7 @@ var PayloadLargeException = class extends Exception {
|
|
|
129
129
|
super(message, 413, "Payload Too Large");
|
|
130
130
|
}
|
|
131
131
|
};
|
|
132
|
-
|
|
132
|
+
_chunkBDIQWWHNjs.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
|
|
133
133
|
|
|
134
134
|
// src/exception/timeout.ts
|
|
135
135
|
var TimeoutException = class extends Exception {
|
|
@@ -137,7 +137,7 @@ var TimeoutException = class extends Exception {
|
|
|
137
137
|
super(message, 408, "Request Timeout");
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
|
-
|
|
140
|
+
_chunkBDIQWWHNjs.__name.call(void 0, TimeoutException, "TimeoutException");
|
|
141
141
|
|
|
142
142
|
// src/exception/unauthorized.ts
|
|
143
143
|
var UnauthorizedException = class extends Exception {
|
|
@@ -145,7 +145,7 @@ var UnauthorizedException = class extends Exception {
|
|
|
145
145
|
super(message, 401, "Unauthorized");
|
|
146
146
|
}
|
|
147
147
|
};
|
|
148
|
-
|
|
148
|
+
_chunkBDIQWWHNjs.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
|
|
149
149
|
|
|
150
150
|
// src/exception/unavailable-service.ts
|
|
151
151
|
var ServiceUnavailableException = class extends Exception {
|
|
@@ -153,7 +153,7 @@ var ServiceUnavailableException = class extends Exception {
|
|
|
153
153
|
super(message, 503, "Service Unavailable");
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
|
-
|
|
156
|
+
_chunkBDIQWWHNjs.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
|
|
157
157
|
|
|
158
158
|
// src/exception/framework.ts
|
|
159
159
|
var FrameworkException = class extends Exception {
|
|
@@ -161,19 +161,19 @@ var FrameworkException = class extends Exception {
|
|
|
161
161
|
super(`[phecda-server] ${message}`, 500, "Framework Error");
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
|
-
|
|
164
|
+
_chunkBDIQWWHNjs.__name.call(void 0, FrameworkException, "FrameworkException");
|
|
165
165
|
|
|
166
166
|
// src/context.ts
|
|
167
167
|
var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
|
|
168
168
|
|
|
169
169
|
// src/filter.ts
|
|
170
|
-
var defaultFilter = /* @__PURE__ */
|
|
170
|
+
var defaultFilter = /* @__PURE__ */ _chunkBDIQWWHNjs.__name.call(void 0, (e) => {
|
|
171
171
|
if (!(e instanceof Exception)) {
|
|
172
|
-
|
|
172
|
+
_chunkBDIQWWHNjs.log.call(void 0, e.message, "error");
|
|
173
173
|
console.error(e.stack);
|
|
174
174
|
e = new UndefinedException(e.message || e);
|
|
175
175
|
} else {
|
|
176
|
-
|
|
176
|
+
_chunkBDIQWWHNjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
|
|
177
177
|
console.error(e.stack);
|
|
178
178
|
}
|
|
179
179
|
return e.data;
|
|
@@ -191,7 +191,7 @@ var Histroy = (_class = class {constructor() { _class.prototype.__init.call(this
|
|
|
191
191
|
return false;
|
|
192
192
|
}
|
|
193
193
|
}, _class);
|
|
194
|
-
|
|
194
|
+
_chunkBDIQWWHNjs.__name.call(void 0, Histroy, "Histroy");
|
|
195
195
|
|
|
196
196
|
// src/context.ts
|
|
197
197
|
var guardRecord = {};
|
|
@@ -201,43 +201,41 @@ var _Context = class {
|
|
|
201
201
|
|
|
202
202
|
|
|
203
203
|
|
|
204
|
-
|
|
205
|
-
constructor(tag, data) {
|
|
206
|
-
this.tag = tag;
|
|
204
|
+
constructor(data) {
|
|
207
205
|
this.data = data;
|
|
208
206
|
this.history = new Histroy();
|
|
209
|
-
if (
|
|
207
|
+
if (_chunkBDIQWWHNjs.IS_DEV)
|
|
210
208
|
data._context = this;
|
|
211
209
|
}
|
|
212
210
|
usePipe(args) {
|
|
213
211
|
return Promise.all(args.map((item) => {
|
|
214
212
|
if (item.pipe && !_Context.pipeRecord[item.pipe]) {
|
|
215
|
-
if (
|
|
213
|
+
if (_chunkBDIQWWHNjs.IS_STRICT)
|
|
216
214
|
throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
|
|
217
215
|
else
|
|
218
|
-
return _Context.pipeRecord.default(item, this.
|
|
216
|
+
return _Context.pipeRecord.default(item, this.data);
|
|
219
217
|
}
|
|
220
|
-
return _Context.pipeRecord[item.pipe || "default"](item, this.
|
|
218
|
+
return _Context.pipeRecord[item.pipe || "default"](item, this.data);
|
|
221
219
|
}));
|
|
222
220
|
}
|
|
223
221
|
useFilter(arg, filter = "default") {
|
|
224
222
|
if (!_Context.filterRecord[filter]) {
|
|
225
|
-
if (
|
|
223
|
+
if (_chunkBDIQWWHNjs.IS_STRICT)
|
|
226
224
|
throw new FrameworkException(`can't find filter named '${filter}'`);
|
|
227
225
|
else
|
|
228
|
-
return _Context.filterRecord.default(arg, this.
|
|
226
|
+
return _Context.filterRecord.default(arg, this.data);
|
|
229
227
|
}
|
|
230
|
-
return _Context.filterRecord[filter](arg, this.
|
|
228
|
+
return _Context.filterRecord[filter](arg, this.data);
|
|
231
229
|
}
|
|
232
230
|
async useGuard(guards) {
|
|
233
231
|
for (const guard of guards) {
|
|
234
232
|
if (this.history.record(guard, "guard")) {
|
|
235
233
|
if (!(guard in _Context.guardRecord)) {
|
|
236
|
-
if (
|
|
234
|
+
if (_chunkBDIQWWHNjs.IS_STRICT)
|
|
237
235
|
throw new FrameworkException(`can't find guard named '${guard}'`);
|
|
238
236
|
continue;
|
|
239
237
|
}
|
|
240
|
-
if (!await _Context.guardRecord[guard](this.
|
|
238
|
+
if (!await _Context.guardRecord[guard](this.data))
|
|
241
239
|
throw new ForbiddenException(`Guard exception--${guard}`);
|
|
242
240
|
}
|
|
243
241
|
}
|
|
@@ -252,11 +250,11 @@ var _Context = class {
|
|
|
252
250
|
for (const interceptor of interceptors) {
|
|
253
251
|
if (this.history.record(interceptor, "interceptor")) {
|
|
254
252
|
if (!(interceptor in _Context.interceptorRecord)) {
|
|
255
|
-
if (
|
|
253
|
+
if (_chunkBDIQWWHNjs.IS_STRICT)
|
|
256
254
|
throw new FrameworkException(`can't find interceptor named '${interceptor}'`);
|
|
257
255
|
continue;
|
|
258
256
|
}
|
|
259
|
-
const postInterceptor = await _Context.interceptorRecord[interceptor](this.
|
|
257
|
+
const postInterceptor = await _Context.interceptorRecord[interceptor](this.data);
|
|
260
258
|
if (postInterceptor !== void 0) {
|
|
261
259
|
if (typeof postInterceptor === "function")
|
|
262
260
|
ret.push(postInterceptor);
|
|
@@ -271,7 +269,7 @@ var _Context = class {
|
|
|
271
269
|
const ret = [];
|
|
272
270
|
for (const m of plugins) {
|
|
273
271
|
if (!(m in _Context.pluginRecord)) {
|
|
274
|
-
if (
|
|
272
|
+
if (_chunkBDIQWWHNjs.IS_STRICT)
|
|
275
273
|
throw new FrameworkException(`can't find middleware named '${m}'`);
|
|
276
274
|
continue;
|
|
277
275
|
}
|
|
@@ -281,37 +279,39 @@ var _Context = class {
|
|
|
281
279
|
}
|
|
282
280
|
};
|
|
283
281
|
var Context = _Context;
|
|
284
|
-
|
|
285
|
-
|
|
282
|
+
_chunkBDIQWWHNjs.__name.call(void 0, Context, "Context");
|
|
283
|
+
_chunkBDIQWWHNjs.__publicField.call(void 0, Context, "filterRecord", {
|
|
286
284
|
default: defaultFilter
|
|
287
285
|
});
|
|
288
|
-
|
|
286
|
+
_chunkBDIQWWHNjs.__publicField.call(void 0, Context, "pipeRecord", {
|
|
289
287
|
default: defaultPipe
|
|
290
288
|
});
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
289
|
+
_chunkBDIQWWHNjs.__publicField.call(void 0, Context, "guardRecord", {});
|
|
290
|
+
_chunkBDIQWWHNjs.__publicField.call(void 0, Context, "interceptorRecord", {});
|
|
291
|
+
_chunkBDIQWWHNjs.__publicField.call(void 0, Context, "pluginRecord", {});
|
|
294
292
|
function addPlugin(key, handler) {
|
|
295
293
|
Context.pluginRecord[key] = handler;
|
|
296
294
|
}
|
|
297
|
-
|
|
295
|
+
_chunkBDIQWWHNjs.__name.call(void 0, addPlugin, "addPlugin");
|
|
298
296
|
function addPipe(key, pipe) {
|
|
299
297
|
Context.pipeRecord[key] = pipe;
|
|
300
298
|
}
|
|
301
|
-
|
|
299
|
+
_chunkBDIQWWHNjs.__name.call(void 0, addPipe, "addPipe");
|
|
302
300
|
function addFilter(key, handler) {
|
|
303
301
|
Context.filterRecord[key] = handler;
|
|
304
302
|
}
|
|
305
|
-
|
|
303
|
+
_chunkBDIQWWHNjs.__name.call(void 0, addFilter, "addFilter");
|
|
306
304
|
function addGuard(key, handler) {
|
|
307
305
|
Context.guardRecord[key] = handler;
|
|
308
306
|
}
|
|
309
|
-
|
|
307
|
+
_chunkBDIQWWHNjs.__name.call(void 0, addGuard, "addGuard");
|
|
310
308
|
function addInterceptor(key, handler) {
|
|
311
309
|
Context.interceptorRecord[key] = handler;
|
|
312
310
|
}
|
|
313
|
-
|
|
311
|
+
_chunkBDIQWWHNjs.__name.call(void 0, addInterceptor, "addInterceptor");
|
|
314
312
|
function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
|
|
313
|
+
if (!_chunkBDIQWWHNjs.IS_DEV)
|
|
314
|
+
return;
|
|
315
315
|
const pluginSet = new Set(plugins);
|
|
316
316
|
const guardSet = new Set(guards);
|
|
317
317
|
const interceptorSet = new Set(interceptors);
|
|
@@ -344,17 +344,17 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
|
|
|
344
344
|
...filterSet
|
|
345
345
|
].filter((i) => !Context.filterRecord[i]);
|
|
346
346
|
if (missPlugins.length)
|
|
347
|
-
|
|
347
|
+
_chunkBDIQWWHNjs.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
|
|
348
348
|
if (missGuards.length)
|
|
349
|
-
|
|
349
|
+
_chunkBDIQWWHNjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
350
350
|
if (missInterceptors.length)
|
|
351
|
-
|
|
351
|
+
_chunkBDIQWWHNjs.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
|
|
352
352
|
if (missPipes.length)
|
|
353
|
-
|
|
353
|
+
_chunkBDIQWWHNjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
354
354
|
if (missFilters.length)
|
|
355
|
-
|
|
355
|
+
_chunkBDIQWWHNjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
_chunkBDIQWWHNjs.__name.call(void 0, isAopDepInject, "isAopDepInject");
|
|
358
358
|
|
|
359
359
|
|
|
360
360
|
|
|
@@ -382,4 +382,4 @@ _chunkZZ2QKZ46js.__name.call(void 0, isAopDepInject, "isAopDepInject");
|
|
|
382
382
|
|
|
383
383
|
|
|
384
384
|
exports.Exception = Exception; exports.ValidateException = ValidateException; exports.defaultPipe = defaultPipe; exports.UndefinedException = UndefinedException; exports.ForbiddenException = ForbiddenException; exports.BadRequestException = BadRequestException; exports.NotFoundException = NotFoundException; exports.ConflictException = ConflictException; exports.BadGatewayException = BadGatewayException; exports.InvalidInputException = InvalidInputException; exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException; exports.PayloadLargeException = PayloadLargeException; exports.TimeoutException = TimeoutException; exports.UnauthorizedException = UnauthorizedException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.FrameworkException = FrameworkException; exports.guardRecord = guardRecord; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor; exports.isAopDepInject = isAopDepInject;
|
|
385
|
-
//# sourceMappingURL=chunk-
|
|
385
|
+
//# sourceMappingURL=chunk-32E425F6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/exception/base.ts","../src/exception/validate.ts","../src/pipe.ts","../src/exception/undefine.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/exception/not-found.ts","../src/exception/conflict.ts","../src/exception/bad-gateway.ts","../src/exception/invalid-input.ts","../src/exception/media-type.ts","../src/exception/payload-large.ts","../src/exception/timeout.ts","../src/exception/unauthorized.ts","../src/exception/unavailable-service.ts","../src/exception/framework.ts","../src/context.ts","../src/filter.ts","../src/history.ts"],"names":["Exception","Error","message","status","description","constructor","data","ERROR_SYMBOL","ValidateException","isPhecda","plainToClass","transformClass","defaultPipe","arg","reflect","index","instance","err","length","Number","Boolean","includes","Object","is","NaN","UndefinedException","ForbiddenException","BadRequestException","NotFoundException","ConflictException","BadGatewayException","InvalidInputException","UnsupportedMediaTypeException","PayloadLargeException","TimeoutException","UnauthorizedException","ServiceUnavailableException","FrameworkException","pc","defaultFilter","e","log","console","error","stack","name","Histroy","guard","interceptor","record","type","push","guardRecord","Context","method","params","history","postInterceptors","IS_DEV","_context","usePipe","args","Promise","all","map","item","pipe","pipeRecord","IS_STRICT","default","useFilter","filter","filterRecord","useGuard","guards","usePostInterceptor","ret","cb","useInterceptor","interceptors","interceptorRecord","postInterceptor","undefined","usePlugin","plugins","m","pluginRecord","addPlugin","key","handler","addPipe","addFilter","addGuard","addInterceptor","isAopDepInject","meta","pluginSet","Set","guardSet","interceptorSet","pipeSet","filterSet","forEach","add","i","missPlugins","missGuards","missInterceptors","missPipes","missFilters","white","join","magenta","cyan","blue","red"],"mappings":";;;;;;;;;;AAEO,IAAM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G6E,IAAI,WAAWN,YAAYE,KAAK,GAAA,IAAO,mBAAmB,MAAA;AACxE;AA9CgBjB","sourcesContent":["import { ERROR_SYMBOL } from '../common'\n\nexport class Exception extends Error {\n constructor(public message: string, public status: number, public description = 'Http exception') {\n super(message)\n }\n\n get data() {\n return { message: this.message, description: this.description, status: this.status, [ERROR_SYMBOL]: true }\n }\n}\n","import { Exception } from './base'\n\nexport class ValidateException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { isPhecda, plainToClass, transformClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nimport type { P } from './types'\n\nexport const defaultPipe: P.Pipe = async ({ arg, reflect, index }: any) => {\n if (isPhecda(reflect)) {\n const instance = plainToClass(reflect, arg)\n const err = await transformClass(instance)\n if (err.length > 0)\n throw new ValidateException(err[0])\n\n arg = instance\n }\n else {\n if ([Number, Boolean].includes(reflect)) {\n arg = reflect(arg)\n\n if (reflect === Number && Object.is(arg, NaN))\n throw new ValidateException(`parameter ${Number(index) + 1} should be a number`)\n }\n }\n return arg\n}\n","import { Exception } from './base'\n\nexport class UndefinedException extends Exception {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { Exception } from './base'\n\nexport class ForbiddenException extends Exception {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { Exception } from './base'\n\nexport class BadRequestException extends Exception {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { Exception } from './base'\n\nexport class NotFoundException extends Exception {\n constructor(message: string) {\n super(message, 404, 'Not Found')\n }\n}\n","import { Exception } from './base'\n\nexport class ConflictException extends Exception {\n constructor(message: string) {\n super(message, 409, 'Conflict')\n }\n}\n","import { Exception } from './base'\n\nexport class BadGatewayException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Bad Gatrway')\n }\n}\n","import { Exception } from './base'\n\nexport class InvalidInputException extends Exception {\n constructor(message: string) {\n super(message, 502, 'Invalid Input')\n }\n}\n","import { Exception } from './base'\n\nexport class UnsupportedMediaTypeException extends Exception {\n constructor(message: string) {\n super(message, 415, 'Unsupported Media Type')\n }\n}\n","import { Exception } from './base'\n\nexport class PayloadLargeException extends Exception {\n constructor(message: string) {\n super(message, 413, 'Payload Too Large')\n }\n}\n","import { Exception } from './base'\n\nexport class TimeoutException extends Exception {\n constructor(message: string) {\n super(message, 408, 'Request Timeout',\n )\n }\n}\n","import { Exception } from './base'\n\nexport class UnauthorizedException extends Exception {\n constructor(message: string) {\n super(message, 401, 'Unauthorized')\n }\n}\n","import { Exception } from './base'\n\nexport class ServiceUnavailableException extends Exception {\n constructor(message: string) {\n super(message, 503, 'Service Unavailable')\n }\n}\n","import { Exception } from './base'\n\nexport class FrameworkException extends Exception {\n constructor(message: string) {\n super(`[phecda-server] ${message}`, 500, 'Framework Error')\n }\n}\n","import pc from 'picocolors'\nimport { defaultPipe } from './pipe'\nimport { ForbiddenException, FrameworkException } from './exception'\nimport { defaultFilter } from './filter'\nimport { Histroy } from './history'\nimport type { P } from './types'\nimport { IS_DEV, IS_STRICT } from './common'\nimport type { Meta } from './meta'\nimport { log } from './utils'\nexport const guardRecord = {} as Record<string, P.Guard>\n\nexport class Context<Data extends P.BaseContext> {\n method: string\n params: string[]\n history = new Histroy()\n\n static filterRecord: Record<string, P.Filter> = {\n default: defaultFilter,\n }\n\n static pipeRecord: Record<string, P.Pipe> = {\n default: defaultPipe,\n }\n\n static guardRecord: Record<string, P.Guard> = {}\n static interceptorRecord: Record<string, P.Interceptor> = {}\n\n static pluginRecord: Record<string, any> = {}\n postInterceptors: Function[]\n\n constructor(public data: Data) {\n if (IS_DEV)\n // @ts-expect-error work for debug\n data._context = this\n }\n\n usePipe(args: { arg: any; pipe?: string; pipeOpts?: any; type: string; key: string; index: number; reflect: any }[]) {\n return Promise.all(args.map((item) => {\n if (item.pipe && !Context.pipeRecord[item.pipe]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find pipe named '${item.pipe}'`)\n\n else\n return Context.pipeRecord.default(item, this.data)\n }\n\n return Context.pipeRecord[item.pipe || 'default'](item, this.data)\n }))\n }\n\n useFilter(arg: any, filter = 'default') {\n if (!Context.filterRecord[filter]) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find filter named '${filter}'`)\n else\n return Context.filterRecord.default(arg, this.data)\n }\n\n return Context.filterRecord[filter](arg, this.data)\n }\n\n async useGuard(guards: string[]) {\n for (const guard of guards) {\n if (this.history.record(guard, 'guard')) {\n if (!(guard in Context.guardRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find guard named '${guard}'`)\n continue\n }\n if (!await Context.guardRecord[guard](this.data))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n }\n\n async usePostInterceptor(ret: any) {\n for (const cb of this.postInterceptors)\n ret = await cb(ret) || ret\n\n return ret\n }\n\n async useInterceptor(interceptors: string[]) {\n const ret = []\n for (const interceptor of interceptors) {\n if (this.history.record(interceptor, 'interceptor')) {\n if (!(interceptor in Context.interceptorRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find interceptor named '${interceptor}'`)\n\n continue\n }\n const postInterceptor = await Context.interceptorRecord[interceptor](this.data)\n if (postInterceptor !== undefined) {\n if (typeof postInterceptor === 'function')\n ret.push(postInterceptor)\n\n else\n return postInterceptor\n }\n }\n }\n this.postInterceptors = ret\n }\n\n static usePlugin(plugins: string[]) {\n const ret = []\n for (const m of plugins) {\n if (!(m in Context.pluginRecord)) {\n if (IS_STRICT)\n throw new FrameworkException(`can't find middleware named '${m}'`)\n\n continue\n }\n ret.push(Context.pluginRecord[m])\n }\n return ret as any[]\n }\n}\nexport function addPlugin<T>(key: string, handler: T) {\n Context.pluginRecord[key] = handler\n}\n\nexport function addPipe<C extends P.BaseContext>(key: string, pipe: P.Pipe<C>) {\n Context.pipeRecord[key] = pipe\n}\n\nexport function addFilter<C extends P.BaseContext>(key: string, handler: P.Filter<C>) {\n Context.filterRecord[key] = handler\n}\n\nexport function addGuard<C extends P.BaseContext>(key: string, handler: P.Guard<C>) {\n Context.guardRecord[key] = handler\n}\n\nexport function addInterceptor<C extends P.BaseContext>(key: string, handler: P.Interceptor<C>) {\n Context.interceptorRecord[key] = handler\n}\n\n// detect whether plugin/filter/pipe/guard/intercept is injected\nexport function isAopDepInject(meta: Meta[], { guards, interceptors, plugins }: {\n guards?: string[]\n interceptors?: string[]\n plugins?: string[]\n} = {}) {\n\n if (!IS_DEV) return\n const pluginSet = new Set<string>(plugins)\n\n const guardSet = new Set<string>(guards)\n const interceptorSet = new Set<string>(interceptors)\n const pipeSet = new Set<string>()\n\n const filterSet = new Set<string>()\n meta.forEach(({ data }) => {\n if (data.filter)\n filterSet.add(data.filter)\n\n data.interceptors.forEach(i => interceptorSet.add(i))\n data.guards.forEach(i => guardSet.add(i))\n data.plugins.forEach(i => pluginSet.add(i))\n data.params.forEach((i) => {\n if (i.pipe)\n pipeSet.add(i.pipe)\n })\n })\n\n const missPlugins = [...pluginSet].filter(i => !Context.pluginRecord[i])\n const missGuards = [...guardSet].filter(i => !Context.guardRecord[i])\n const missInterceptors = [...interceptorSet].filter(i => !Context.interceptorRecord[i])\n const missPipes = [...pipeSet].filter(i => !Context.pipeRecord[i])\n const missFilters = [...filterSet].filter(i => !Context.filterRecord[i])\n\n if (missPlugins.length)\n log(`${pc.white(`Plugin [${missPlugins.join(',')}]`)} doesn't exist`, 'warn')\n if (missGuards.length)\n log(`${pc.magenta(`Guard [${missGuards.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missInterceptors.length)\n log(`${pc.cyan(`Interceptor [${missInterceptors.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missPipes.length)\n log(`${pc.blue(`Pipe [${missPipes.join(',')}]`)} doesn't exist`, 'warn')\n\n if (missFilters.length)\n log(`${pc.red(`Filter [${missFilters.join(',')}]`)} doesn't exist`, 'warn')\n}\n","import { Exception, UndefinedException } from './exception'\nimport type { P } from './types'\nimport { log } from './utils'\n\nexport const defaultFilter: P.Filter = (e) => {\n if (!(e instanceof Exception)) {\n log(e.message, 'error')\n console.error(e.stack)\n e = new UndefinedException(e.message || e)\n }\n else {\n log(`[${e.constructor.name}] ${e.message}`, 'error')\n console.error(e.stack)\n }\n\n return e.data\n}\n","export class Histroy {\n guard: string[] = []\n interceptor: string[] = []\n record(name: string, type: 'guard' | 'interceptor') {\n if (!this[type].includes(name)) {\n this[type].push(name)\n return true\n }\n return false\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/common.ts","../src/utils.ts"],"sourcesContent":["export const MERGE_SYMBOL = '__PS_MERGE__'\nexport const UNMOUNT_SYMBOL = '__PS_UNMOUNT__'\nexport const MODULE_SYMBOL = '__PS_MODULE__'\nexport const META_SYMBOL = '__PS_META__'\nexport const APP_SYMBOL = '__PS__'\nexport const IS_DEV = process.env.NODE_ENV === 'development'\nexport const IS_STRICT = !!process.env.PS_STRICT\nexport const ERROR_SYMBOL = '__PS_ERROR__'\n","import pc from 'picocolors'\nimport { DataMap } from 'phecda-core'\n\nlet time: number\n\nexport function log(msg: string, level: 'error' | 'info' | 'warn' = 'info') {\n const color = ({ error: 'red', info: 'green', warn: 'yellow' } as const)[level]\n const date = new Date()\n const current = Date.now()\n const interval = (time && current - time) ? `+${current - time}` : ''\n time = current\n // eslint-disable-next-line no-console\n console.log(`${pc.magenta('[phecda-server]')} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`)\n}\n\nexport function getConfig<C = any>(key: string, defaultConf?: C): C {\n if (!DataMap[key]) {\n if (defaultConf)\n return defaultConf\n throw new Error(`config \"${key}\" is not existed`)\n }\n\n return DataMap[key]\n}\n\nexport function setConfig<C = any>(key: string, conf: C, force = true) {\n if (DataMap[key] && !force)\n return\n\n DataMap[key] = conf\n}\n"],"mappings":";;;;;;;;;AAAO,IAAMA,eAAe;AACrB,IAAMC,iBAAiB;AACvB,IAAMC,gBAAgB;AACtB,IAAMC,cAAc;AACpB,IAAMC,aAAa;AACnB,IAAMC,SAASC,QAAQC,IAAIC,aAAa;AACxC,IAAMC,YAAY,CAAC,CAACH,QAAQC,IAAIG;AAChC,IAAMC,eAAe;;;ACP5B,OAAOC,QAAQ;AACf,SAASC,eAAe;AAExB,IAAIC;AAEG,SAASC,IAAIC,KAAaC,QAAmC,QAAQ;AAC1E,QAAMC,QAAS;IAAEC,OAAO;IAAOC,MAAM;IAASC,MAAM;EAAS,EAAYJ;AACzE,QAAMK,OAAO,IAAIC,KAAAA;AACjB,QAAMC,UAAUD,KAAKE,IAAG;AACxB,QAAMC,WAAYZ,QAAQU,UAAUV,OAAQ,IAAIU,UAAUV,SAAS;AACnEA,SAAOU;AAEPG,UAAQZ,IAAI,GAAGa,GAAGC,QAAQ,iBAAA,KAAsBD,GAAGE,KAAK,GAAGR,KAAKS,SAAQ,KAAMT,KAAKU,WAAU,KAAMV,KAAKW,WAAU,GAAI,KAAKL,GAAGV,OAAOF,GAAAA,KAAQY,GAAGE,KAAKJ,QAAAA,GAAW;AAClK;AARgBX;AAUT,SAASmB,UAAmBC,KAAaC,aAAoB;AAClE,MAAI,CAACC,QAAQF,MAAM;AACjB,QAAIC;AACF,aAAOA;AACT,UAAM,IAAIE,MAAM,WAAWH,qBAAqB;EAClD;AAEA,SAAOE,QAAQF;AACjB;AARgBD;AAUT,SAASK,UAAmBJ,KAAaK,MAASC,QAAQ,MAAM;AACrE,MAAIJ,QAAQF,QAAQ,CAACM;AACnB;AAEFJ,UAAQF,OAAOK;AACjB;AALgBD;","names":["MERGE_SYMBOL","UNMOUNT_SYMBOL","MODULE_SYMBOL","META_SYMBOL","APP_SYMBOL","IS_DEV","process","env","NODE_ENV","IS_STRICT","PS_STRICT","ERROR_SYMBOL","pc","DataMap","time","log","msg","level","color","error","info","warn","date","Date","current","now","interval","console","pc","magenta","gray","getHours","getMinutes","getSeconds","getConfig","key","defaultConf","DataMap","Error","setConfig","conf","force"]}
|
|
1
|
+
{"version":3,"sources":["../src/common.ts","../src/utils.ts"],"sourcesContent":["export const MERGE_SYMBOL = '__PS_MERGE__'\nexport const UNMOUNT_SYMBOL = '__PS_UNMOUNT__'\nexport const MODULE_SYMBOL = '__PS_MODULE__'\nexport const META_SYMBOL = '__PS_META__'\nexport const APP_SYMBOL = '__PS__'\nexport const IS_DEV = process.env.NODE_ENV === 'development'\nexport const IS_STRICT = !!process.env.PS_STRICT\nexport const ERROR_SYMBOL = '__PS_ERROR__'\n","import pc from 'picocolors'\nimport { DataMap } from 'phecda-core'\n\nlet time: number\n\nexport function log(msg: string, level: 'error' | 'info' | 'warn' = 'info') {\n const color = ({ error: 'red', info: 'green', warn: 'yellow' } as const)[level]\n const date = new Date()\n const current = Date.now()\n const interval = (time && current - time) ? `+${current - time}` : ''\n time = current\n // eslint-disable-next-line no-console\n console.log(`${pc.magenta('[phecda-server]')} ${pc.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${pc[color](msg)} ${pc.gray(interval)}`)\n}\n\nexport function getConfig<C = any>(key: string, defaultConf?: C): C {\n if (!DataMap[key]) {\n if (defaultConf)\n return defaultConf\n throw new Error(`config \"${key}\" is not existed`)\n }\n\n return DataMap[key]\n}\n\nexport function setConfig<C = any>(key: string, conf: C, force = true) {\n if (DataMap[key] && !force)\n return\n\n DataMap[key] = conf\n}\n\n\n\n\n\n"],"mappings":";;;;;;;;;AAAO,IAAMA,eAAe;AACrB,IAAMC,iBAAiB;AACvB,IAAMC,gBAAgB;AACtB,IAAMC,cAAc;AACpB,IAAMC,aAAa;AACnB,IAAMC,SAASC,QAAQC,IAAIC,aAAa;AACxC,IAAMC,YAAY,CAAC,CAACH,QAAQC,IAAIG;AAChC,IAAMC,eAAe;;;ACP5B,OAAOC,QAAQ;AACf,SAASC,eAAe;AAExB,IAAIC;AAEG,SAASC,IAAIC,KAAaC,QAAmC,QAAQ;AAC1E,QAAMC,QAAS;IAAEC,OAAO;IAAOC,MAAM;IAASC,MAAM;EAAS,EAAYJ;AACzE,QAAMK,OAAO,IAAIC,KAAAA;AACjB,QAAMC,UAAUD,KAAKE,IAAG;AACxB,QAAMC,WAAYZ,QAAQU,UAAUV,OAAQ,IAAIU,UAAUV,SAAS;AACnEA,SAAOU;AAEPG,UAAQZ,IAAI,GAAGa,GAAGC,QAAQ,iBAAA,KAAsBD,GAAGE,KAAK,GAAGR,KAAKS,SAAQ,KAAMT,KAAKU,WAAU,KAAMV,KAAKW,WAAU,GAAI,KAAKL,GAAGV,OAAOF,GAAAA,KAAQY,GAAGE,KAAKJ,QAAAA,GAAW;AAClK;AARgBX;AAUT,SAASmB,UAAmBC,KAAaC,aAAoB;AAClE,MAAI,CAACC,QAAQF,MAAM;AACjB,QAAIC;AACF,aAAOA;AACT,UAAM,IAAIE,MAAM,WAAWH,qBAAqB;EAClD;AAEA,SAAOE,QAAQF;AACjB;AARgBD;AAUT,SAASK,UAAmBJ,KAAaK,MAASC,QAAQ,MAAM;AACrE,MAAIJ,QAAQF,QAAQ,CAACM;AACnB;AAEFJ,UAAQF,OAAOK;AACjB;AALgBD;","names":["MERGE_SYMBOL","UNMOUNT_SYMBOL","MODULE_SYMBOL","META_SYMBOL","APP_SYMBOL","IS_DEV","process","env","NODE_ENV","IS_STRICT","PS_STRICT","ERROR_SYMBOL","pc","DataMap","time","log","msg","level","color","error","info","warn","date","Date","current","now","interval","console","pc","magenta","gray","getHours","getMinutes","getSeconds","getConfig","key","defaultConf","DataMap","Error","setConfig","conf","force"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkBDIQWWHNjs = require('./chunk-BDIQWWHN.js');
|
|
7
7
|
|
|
8
8
|
// src/meta.ts
|
|
9
9
|
var Meta = class {
|
|
@@ -16,10 +16,10 @@ var Meta = class {
|
|
|
16
16
|
this.paramsType = paramsType;
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
_chunkBDIQWWHNjs.__name.call(void 0, Meta, "Meta");
|
|
20
20
|
|
|
21
21
|
// src/compiler/rpc.ts
|
|
22
|
-
var Compiler = /* @__PURE__ */
|
|
22
|
+
var Compiler = /* @__PURE__ */ _chunkBDIQWWHNjs.__name.call(void 0, (_class =class Compiler2 {
|
|
23
23
|
__init() {this.classMap = {}}
|
|
24
24
|
constructor() {;_class.prototype.__init.call(this);
|
|
25
25
|
}
|
|
@@ -55,10 +55,10 @@ function generateRPCCode(meta) {
|
|
|
55
55
|
compiler.addMethod(i);
|
|
56
56
|
return compiler.getContent();
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
_chunkBDIQWWHNjs.__name.call(void 0, generateRPCCode, "generateRPCCode");
|
|
59
59
|
|
|
60
60
|
// src/compiler/http.ts
|
|
61
|
-
var Compiler3 = /* @__PURE__ */
|
|
61
|
+
var Compiler3 = /* @__PURE__ */ _chunkBDIQWWHNjs.__name.call(void 0, (_class2 =class Compiler4 {
|
|
62
62
|
__init2() {this.classMap = {}}
|
|
63
63
|
constructor() {;_class2.prototype.__init2.call(this);
|
|
64
64
|
}
|
|
@@ -97,7 +97,7 @@ function generateHTTPCode(meta) {
|
|
|
97
97
|
compiler.addMethod(i);
|
|
98
98
|
return compiler.getContent();
|
|
99
99
|
}
|
|
100
|
-
|
|
100
|
+
_chunkBDIQWWHNjs.__name.call(void 0, generateHTTPCode, "generateHTTPCode");
|
|
101
101
|
|
|
102
102
|
// src/core.ts
|
|
103
103
|
require('reflect-metadata');
|
|
@@ -108,7 +108,7 @@ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
|
108
108
|
function Injectable() {
|
|
109
109
|
return (target) => _phecdacore.Empty.call(void 0, target);
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
_chunkBDIQWWHNjs.__name.call(void 0, Injectable, "Injectable");
|
|
112
112
|
var debug = _debug2.default.call(void 0, "phecda-server");
|
|
113
113
|
var emitter = new (0, _events2.default)();
|
|
114
114
|
async function Factory(Modules, opts = {}) {
|
|
@@ -118,25 +118,27 @@ async function Factory(Modules, opts = {}) {
|
|
|
118
118
|
const constructorSet = /* @__PURE__ */ new WeakSet();
|
|
119
119
|
const moduleGraph = /* @__PURE__ */ new Map();
|
|
120
120
|
const { http, rpc } = opts;
|
|
121
|
-
_phecdacore.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
instance[
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
if (!_phecdacore.getProperty.call(void 0, "watcher")) {
|
|
122
|
+
_phecdacore.injectProperty.call(void 0, "watcher", ({ eventName, instance, key, options }) => {
|
|
123
|
+
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
124
|
+
if (!instance[_chunkBDIQWWHNjs.UNMOUNT_SYMBOL])
|
|
125
|
+
instance[_chunkBDIQWWHNjs.UNMOUNT_SYMBOL] = [];
|
|
126
|
+
instance[_chunkBDIQWWHNjs.UNMOUNT_SYMBOL].push(() => {
|
|
127
|
+
emitter.off(eventName, fn);
|
|
128
|
+
});
|
|
129
|
+
if (_optionalChain([options, 'optionalAccess', _2 => _2.once]))
|
|
130
|
+
emitter.once(eventName, fn);
|
|
131
|
+
else
|
|
132
|
+
emitter.on(eventName, fn);
|
|
127
133
|
});
|
|
128
|
-
|
|
129
|
-
emitter.once(eventName, fn);
|
|
130
|
-
else
|
|
131
|
-
emitter.on(eventName, fn);
|
|
132
|
-
});
|
|
134
|
+
}
|
|
133
135
|
async function del(tag) {
|
|
134
136
|
if (!moduleMap.has(tag))
|
|
135
137
|
return;
|
|
136
138
|
const instance = moduleMap.get(tag);
|
|
137
139
|
debug(`unmount module "${tag}"`);
|
|
138
|
-
if (_optionalChain([instance, 'optionalAccess', _3 => _3[
|
|
139
|
-
for (const cb of instance[
|
|
140
|
+
if (_optionalChain([instance, 'optionalAccess', _3 => _3[_chunkBDIQWWHNjs.UNMOUNT_SYMBOL]])) {
|
|
141
|
+
for (const cb of instance[_chunkBDIQWWHNjs.UNMOUNT_SYMBOL])
|
|
140
142
|
await cb();
|
|
141
143
|
}
|
|
142
144
|
debug(`del module "${tag}"`);
|
|
@@ -148,7 +150,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
148
150
|
}
|
|
149
151
|
return instance;
|
|
150
152
|
}
|
|
151
|
-
|
|
153
|
+
_chunkBDIQWWHNjs.__name.call(void 0, del, "del");
|
|
152
154
|
async function add(Module) {
|
|
153
155
|
const tag = _optionalChain([Module, 'access', _4 => _4.prototype, 'optionalAccess', _5 => _5.__TAG__]) || Module.name;
|
|
154
156
|
const oldInstance = await del(tag);
|
|
@@ -166,7 +168,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
166
168
|
});
|
|
167
169
|
}
|
|
168
170
|
}
|
|
169
|
-
|
|
171
|
+
_chunkBDIQWWHNjs.__name.call(void 0, add, "add");
|
|
170
172
|
async function buildNestModule(Module) {
|
|
171
173
|
const paramtypes = getParamTypes(Module);
|
|
172
174
|
let instance;
|
|
@@ -177,7 +179,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
177
179
|
throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`);
|
|
178
180
|
if (constructorMap.get(tag) !== Module && !constructorSet.has(Module)) {
|
|
179
181
|
constructorSet.add(Module);
|
|
180
|
-
|
|
182
|
+
_chunkBDIQWWHNjs.log.call(void 0, `Synonym module: Module taged "${tag}" has been loaded before, so phecda-server won't load Module "${Module.name}"`, "warn");
|
|
181
183
|
}
|
|
182
184
|
return {
|
|
183
185
|
instance,
|
|
@@ -211,7 +213,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
211
213
|
tag
|
|
212
214
|
};
|
|
213
215
|
}
|
|
214
|
-
|
|
216
|
+
_chunkBDIQWWHNjs.__name.call(void 0, buildNestModule, "buildNestModule");
|
|
215
217
|
for (const Module of Modules)
|
|
216
218
|
await buildNestModule(Module);
|
|
217
219
|
function writeCode() {
|
|
@@ -224,9 +226,9 @@ async function Factory(Modules, opts = {}) {
|
|
|
224
226
|
_fs2.default.promises.writeFile(rpc, generateRPCCode(meta.map((item) => item.data)));
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
|
-
|
|
229
|
+
_chunkBDIQWWHNjs.__name.call(void 0, writeCode, "writeCode");
|
|
228
230
|
writeCode();
|
|
229
|
-
if (
|
|
231
|
+
if (_chunkBDIQWWHNjs.IS_DEV) {
|
|
230
232
|
if (!globalThis.__PS_HMR__)
|
|
231
233
|
globalThis.__PS_HMR__ = [];
|
|
232
234
|
_optionalChain([globalThis, 'access', _8 => _8.__PS_HMR__, 'optionalAccess', _9 => _9.push, 'call', _10 => _10(async (files) => {
|
|
@@ -249,7 +251,7 @@ async function Factory(Modules, opts = {}) {
|
|
|
249
251
|
del
|
|
250
252
|
};
|
|
251
253
|
}
|
|
252
|
-
|
|
254
|
+
_chunkBDIQWWHNjs.__name.call(void 0, Factory, "Factory");
|
|
253
255
|
function getMetaFromInstance(instance, tag, name) {
|
|
254
256
|
const vars = _phecdacore.getExposeKey.call(void 0, instance).filter((item) => item !== "__CLASS");
|
|
255
257
|
const baseState = _phecdacore.getState.call(void 0, instance, "__CLASS") || {};
|
|
@@ -312,11 +314,11 @@ function getMetaFromInstance(instance, tag, name) {
|
|
|
312
314
|
return new Meta(meta, _phecdacore.getHandler.call(void 0, instance, i), getParamTypes(instance, i) || []);
|
|
313
315
|
});
|
|
314
316
|
}
|
|
315
|
-
|
|
317
|
+
_chunkBDIQWWHNjs.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
|
|
316
318
|
function getParamTypes(Module, key) {
|
|
317
319
|
return Reflect.getMetadata("design:paramtypes", Module, key);
|
|
318
320
|
}
|
|
319
|
-
|
|
321
|
+
_chunkBDIQWWHNjs.__name.call(void 0, getParamTypes, "getParamTypes");
|
|
320
322
|
function initState(state) {
|
|
321
323
|
if (!state.define)
|
|
322
324
|
state.define = {};
|
|
@@ -329,7 +331,7 @@ function initState(state) {
|
|
|
329
331
|
if (!state.interceptors)
|
|
330
332
|
state.interceptors = [];
|
|
331
333
|
}
|
|
332
|
-
|
|
334
|
+
_chunkBDIQWWHNjs.__name.call(void 0, initState, "initState");
|
|
333
335
|
|
|
334
336
|
|
|
335
337
|
|
|
@@ -339,4 +341,4 @@ _chunkZZ2QKZ46js.__name.call(void 0, initState, "initState");
|
|
|
339
341
|
|
|
340
342
|
|
|
341
343
|
exports.Meta = Meta; exports.generateRPCCode = generateRPCCode; exports.generateHTTPCode = generateHTTPCode; exports.Injectable = Injectable; exports.emitter = emitter; exports.Factory = Factory;
|
|
342
|
-
//# sourceMappingURL=chunk-
|
|
344
|
+
//# sourceMappingURL=chunk-5L4K7XEB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/meta.ts","../src/compiler/rpc.ts","../src/compiler/http.ts","../src/core.ts"],"names":["Meta","data","handlers","paramsType","constructor","Compiler","classMap","getContent","content","name","Object","values","reduce","p","c","addMethod","args","rpc","method","tag","type","isEvent","generateRPCCode","meta","compiler","i","http","params","url","route","replace","_","js","key","generateHTTPCode","fs","EventEmitter","Empty","getExposeKey","getHandler","getProperty","getState","injectProperty","isPhecda","registerAsync","Debug","Injectable","target","debug","emitter","Factory","Modules","opts","moduleMap","Map","constructorMap","constructorSet","WeakSet","moduleGraph","eventName","instance","options","fn","bind","v","UNMOUNT_SYMBOL","push","off","once","on","del","has","get","cb","delete","length","splice","add","Module","prototype","__TAG__","oldInstance","newModule","buildNestModule","forEach","module","paramtypes","getParamTypes","Error","log","set","undefined","paramtypesInstances","sub","subTag","Set","getMetaFromInstance","writeCode","promises","writeFile","map","item","IS_DEV","globalThis","__PS_HMR__","files","file","vars","filter","baseState","initState","state","unshift","index","define","header","plugins","guards","interceptors","Reflect","getMetadata"],"mappings":";;;;;;;;AAEO,IAAMA,OAAN,MAAMA;EACQC;EAAyBC;EAA8BC;EAA1EC,YAAmBH,MAAyBC,UAA8BC,YAAmB;gBAA1EF;oBAAyB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BP,MAAMO;OAAa;;AAElF,WAAO,IAAItH,KAAKuB,MAA+BgB,WAAWqB,UAAUnC,CAAAA,GAAI8D,cAAc3B,UAAUnC,CAAAA,KAAgB,CAAA,CAAE;EACpH,CAAA;AACF;AA5CSuE;AA8CT,SAAST,cAAcT,QAAa7C,KAAuB;AACzD,SAAOsF,QAAQC,YAAY,qBAAqB1C,QAAQ7C,GAAAA;AAC1D;AAFSsD;AAIT,SAASuB,UAAUC,OAAY;AAC7B,MAAI,CAACA,MAAMG;AACTH,UAAMG,SAAS,CAAC;AAClB,MAAI,CAACH,MAAMI;AACTJ,UAAMI,SAAS,CAAC;AAClB,MAAI,CAACJ,MAAMK;AACTL,UAAMK,UAAU,CAAA;AAClB,MAAI,CAACL,MAAMM;AACTN,UAAMM,SAAS,CAAA;AACjB,MAAI,CAACN,MAAMO;AACTP,UAAMO,eAAe,CAAA;AACzB;AAXSR","sourcesContent":["import type { P } from './types'\n\nexport class Meta {\n constructor(public data: P.MetaData, public handlers: P.Handler[], public paramsType: any[]) {\n\n }\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n addMethod(args: P.MetaData) {\n const {\n rpc, name, method, tag,\n } = args\n if (!rpc || !rpc.type)\n return\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(){\n return {tag:'${tag}-${method}',isEvent:${!!rpc.isEvent},rpc:[${rpc.type.reduce((p, c) => {\n return `${p}\"${c}\",`\n }, '')}]}\n\n }\n `\n }\n}\n\nexport function generateRPCCode(meta: P.MetaData[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import type { P } from '../types'\n\nclass Compiler {\n classMap: Record<string, { [key: string]: string }> = {}\n constructor() { }\n\n getContent() {\n let content = ''\n\n for (const name in this.classMap) {\n content += `\n export class ${name}{\n ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}\n }`\n }\n return content\n }\n\n // createRequest() {\n // let content = 'import {useC} from \\'phecda-server\\'\\n'\n // for (const name in this.classMap)\n // content += `export const {${Object.keys(this.classMap[name]).join(',')}}=useC(${name})\\n`\n // return content\n // }\n\n addMethod(args: P.MetaData) {\n const {\n http, name, method, params, tag,\n } = args\n if (!http)\n return\n const url = http.route.replace(/\\/\\:([^\\/]*)/g, (_, js) => `/{{${js}}}`)\n if (!this.classMap[name])\n this.classMap[name] = {}\n this.classMap[name][method] = `\n ${method}(...args){\nconst ret={tag:\"${tag}-${method}\",body:{},headers:{},query:{},params:{},method:\"${http.type}\",url:\"${url}\",args}\n\n${params.reduce((p, c, i) => `${p}ret.${c.type}${c.key ? `['${c.key}']` : ''}=args[${i}]\\n${c.type === 'params' ? `ret.url=ret.url.replace('{{${c.key}}}',args[${i}])` : ''}\\n`, '')}\nreturn ret\n }\n `\n }\n}\n\nexport function generateHTTPCode(meta: P.MetaData[]) {\n const compiler = new Compiler()\n\n for (const i of meta)\n compiler.addMethod(i)\n return compiler.getContent()\n}\n","import 'reflect-metadata'\nimport fs from 'fs'\nimport EventEmitter from 'node:events'\nimport type { Phecda } from 'phecda-core'\nimport { Empty, getExposeKey, getHandler, getProperty, getState, injectProperty, isPhecda, registerAsync } from 'phecda-core'\nimport Debug from 'debug'\nimport type { Construct, Emitter, P } from './types'\nimport { Meta } from './meta'\nimport { log } from './utils'\nimport { IS_DEV, UNMOUNT_SYMBOL } from './common'\nimport { generateHTTPCode, generateRPCCode } from './compiler'\nexport function Injectable() {\n return (target: any) => Empty(target)\n}\nconst debug = Debug('phecda-server')\n// TODO: support both emitter types and origin emitter type in future\nexport const emitter: Emitter = new EventEmitter() as any\n\nexport async function Factory(Modules: (new (...args: any) => any)[], opts: {\n\n // HTTP generate code path\n http?: string\n // rpc generate code path\n rpc?: string\n} = {}) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Meta[] = []\n const constructorMap = new Map()\n\n // only work for warn\n const constructorSet = new WeakSet()\n const moduleGraph = new Map<string, Set<string>>()\n const { http, rpc } = opts\n\n if (!getProperty('watcher')) {\n injectProperty('watcher', ({ eventName, instance, key, options }: { eventName: string; instance: any; key: string; options?: { once: boolean } }) => {\n const fn = typeof instance[key] === 'function' ? instance[key].bind(instance) : (v: any) => instance[key] = v\n\n // work for hmr\n if (!instance[UNMOUNT_SYMBOL])\n instance[UNMOUNT_SYMBOL] = []\n\n instance[UNMOUNT_SYMBOL].push(() => {\n (emitter as any).off(eventName, fn)\n })\n\n if (options?.once)\n (emitter as any).once(eventName, fn)\n\n else\n (emitter as any).on(eventName, fn)\n })\n }\n\n // only remove module in moduleMap(won't remove indiect module)\n async function del(tag: string) {\n if (!moduleMap.has(tag))\n return\n\n const instance = moduleMap.get(tag)\n\n debug(`unmount module \"${tag}\"`)\n\n if (instance?.[UNMOUNT_SYMBOL]) {\n for (const cb of instance[UNMOUNT_SYMBOL])\n await cb()\n }\n\n debug(`del module \"${tag}\"`)\n\n moduleMap.delete(tag)\n constructorMap.delete(tag)\n for (let i = meta.length - 1; i >= 0; i--) {\n if (meta[i].data.tag === tag)\n meta.splice(i, 1)\n }\n\n return instance\n }\n\n async function add(Module: Construct) {\n const tag = Module.prototype?.__TAG__ || Module.name\n const oldInstance = await del(tag)\n\n const { instance: newModule } = await buildNestModule(Module)\n\n if (oldInstance && moduleGraph.has(tag)) {\n debug(`replace module \"${tag}\"`);\n\n [...moduleGraph.get(tag)!].forEach((tag) => {\n const module = moduleMap.get(tag)\n for (const key in module) {\n if (module[key] === oldInstance)\n module[key] = newModule\n }\n })\n }\n }\n async function buildNestModule(Module: Construct) {\n const paramtypes = getParamTypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const tag = Module.prototype?.__TAG__ || Module.name\n if (moduleMap.has(tag)) {\n instance = moduleMap.get(tag)\n if (!instance)\n throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`)\n\n if (constructorMap.get(tag) !== Module && !constructorSet.has(Module)) {\n constructorSet.add(Module)// a module will only warn once\n log(`Synonym module: Module taged \"${tag}\" has been loaded before, so phecda-server won't load Module \"${Module.name}\"`, 'warn')\n }\n return { instance, tag }\n }\n moduleMap.set(tag, undefined)\n if (paramtypes) {\n const paramtypesInstances = [] as any[]\n for (const i in paramtypes) {\n const { instance: sub, tag: subTag } = await buildNestModule(paramtypes[i])\n paramtypesInstances[i] = sub\n if (!moduleGraph.has(subTag))\n moduleGraph.set(subTag, new Set())\n moduleGraph.get(subTag)!.add(tag)\n }\n debug(`instantiate module \"${tag}\"`)\n\n instance = new Module(...paramtypesInstances)\n }\n else {\n debug(`instantiate module \"${tag}\"`)\n\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, tag, Module.name))\n\n debug(`init module \"${tag}\"`)\n\n await registerAsync(instance)\n\n debug(`add module \"${tag}\"`)\n\n moduleMap.set(tag, instance)\n constructorMap.set(tag, Module)\n return { instance, tag }\n }\n\n for (const Module of Modules)\n await buildNestModule(Module)\n\n function writeCode() {\n if (http) {\n debug(`write http code to ${http}`)\n fs.promises.writeFile(http, generateHTTPCode(meta.map(item => item.data)))\n }\n if (rpc) {\n debug(`write rpc code to ${rpc}`)\n\n fs.promises.writeFile(rpc, generateRPCCode(meta.map(item => item.data)))\n }\n }\n\n writeCode()\n if (IS_DEV) {\n if (!globalThis.__PS_HMR__)\n globalThis.__PS_HMR__ = []\n\n globalThis.__PS_HMR__?.push(async (files: string[]) => {\n debug('reload files ')\n\n for (const file of files) {\n const module = await import(file)\n for (const i in module) {\n if (isPhecda(module[i]))\n await add(module[i])\n }\n }\n writeCode()\n })\n }\n\n return {\n moduleMap,\n meta,\n constructorMap,\n add,\n del,\n }\n}\n\nfunction getMetaFromInstance(instance: Phecda, tag: string, name: string) {\n const vars = getExposeKey(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as P.MetaData\n initState(baseState)\n\n return vars.map((i) => {\n const meta = {} as P.MetaData\n const state = (getState(instance, i) || {}) as P.MetaData\n initState(state)\n if (state.http) {\n meta.http = {\n route: (baseState.http?.route || '') + (state.http.route),\n type: state.http.type,\n }\n }\n if (baseState.rpc)\n meta.rpc = baseState.rpc\n if (state.rpc) {\n meta.rpc = {\n ...meta.rpc,\n ...state.rpc,\n }\n }\n\n meta.name = name\n meta.tag = tag\n meta.method = i as string\n const params = [] as any[]\n for (const i of state.params || []) {\n params.unshift(i)\n if (i.index === 0)\n break\n }\n\n meta.params = params\n meta.filter = state.filter || baseState.filter\n meta.define = { ...baseState.define, ...state.define }\n meta.header = { ...baseState.header, ...state.header }\n meta.plugins = [...new Set([...baseState.plugins, ...state.plugins])]\n meta.guards = [...new Set([...baseState.guards, ...state.guards])]\n meta.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Meta(meta as unknown as P.MetaData, getHandler(instance, i), getParamTypes(instance, i as string) || [])\n })\n}\n\nfunction getParamTypes(Module: any, key?: string | symbol) {\n return Reflect.getMetadata('design:paramtypes', Module, key!)\n}\n\nfunction initState(state: any) {\n if (!state.define)\n state.define = {}\n if (!state.header)\n state.header = {}\n if (!state.plugins)\n state.plugins = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n"]}
|