phecda-server 1.0.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/LICENSE +21 -0
- package/dist/client/index.d.ts +27 -0
- package/dist/client/index.js +88 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +61 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +566 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +515 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-6e2842b3.d.ts +47 -0
- package/package.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __publicField = (obj, key, value) => {
|
|
22
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var src_exports = {};
|
|
28
|
+
__export(src_exports, {
|
|
29
|
+
BadRequestException: () => BadRequestException,
|
|
30
|
+
BaseParam: () => BaseParam,
|
|
31
|
+
Body: () => Body,
|
|
32
|
+
Controller: () => Controller,
|
|
33
|
+
Delete: () => Delete,
|
|
34
|
+
Factory: () => Factory,
|
|
35
|
+
ForbiddenException: () => ForbiddenException,
|
|
36
|
+
Get: () => Get,
|
|
37
|
+
Header: () => Header,
|
|
38
|
+
HttpException: () => HttpException,
|
|
39
|
+
Inject: () => Inject,
|
|
40
|
+
Param: () => Param,
|
|
41
|
+
Pcompiler: () => Pcompiler,
|
|
42
|
+
Pmeta: () => Pmeta,
|
|
43
|
+
Post: () => Post,
|
|
44
|
+
Pserver: () => Pserver,
|
|
45
|
+
Put: () => Put,
|
|
46
|
+
Query: () => Query,
|
|
47
|
+
Route: () => Route,
|
|
48
|
+
Server: () => Server,
|
|
49
|
+
UndefinedException: () => UndefinedException,
|
|
50
|
+
ValidateException: () => ValidateException,
|
|
51
|
+
addGuard: () => addGuard,
|
|
52
|
+
addInterceptor: () => addInterceptor,
|
|
53
|
+
bindApp: () => bindApp,
|
|
54
|
+
defaultPipe: () => defaultPipe,
|
|
55
|
+
usePipe: () => usePipe
|
|
56
|
+
});
|
|
57
|
+
module.exports = __toCommonJS(src_exports);
|
|
58
|
+
|
|
59
|
+
// src/exception/base.ts
|
|
60
|
+
var HttpException = class extends Error {
|
|
61
|
+
message;
|
|
62
|
+
status;
|
|
63
|
+
description;
|
|
64
|
+
constructor(message, status, description = "Http exception") {
|
|
65
|
+
super(message);
|
|
66
|
+
this.message = message;
|
|
67
|
+
this.status = status;
|
|
68
|
+
this.description = description;
|
|
69
|
+
}
|
|
70
|
+
get data() {
|
|
71
|
+
return {
|
|
72
|
+
message: this.message,
|
|
73
|
+
description: this.description,
|
|
74
|
+
status: this.status,
|
|
75
|
+
error: true
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
__name(HttpException, "HttpException");
|
|
80
|
+
|
|
81
|
+
// src/exception/undefine.ts
|
|
82
|
+
var UndefinedException = class extends HttpException {
|
|
83
|
+
constructor(message) {
|
|
84
|
+
super(message, 500, "Undefined error");
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
__name(UndefinedException, "UndefinedException");
|
|
88
|
+
|
|
89
|
+
// src/exception/validate.ts
|
|
90
|
+
var ValidateException = class extends HttpException {
|
|
91
|
+
constructor(message) {
|
|
92
|
+
super(message, 400, "Validate exception");
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
__name(ValidateException, "ValidateException");
|
|
96
|
+
|
|
97
|
+
// src/exception/forbidden.ts
|
|
98
|
+
var ForbiddenException = class extends HttpException {
|
|
99
|
+
constructor(message) {
|
|
100
|
+
super(message, 403, "Forbidden resource");
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
__name(ForbiddenException, "ForbiddenException");
|
|
104
|
+
|
|
105
|
+
// src/exception/bad-request.ts
|
|
106
|
+
var BadRequestException = class extends HttpException {
|
|
107
|
+
constructor(message) {
|
|
108
|
+
super(message, 400, "Bad Request");
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
__name(BadRequestException, "BadRequestException");
|
|
112
|
+
|
|
113
|
+
// src/pipe.ts
|
|
114
|
+
var import_phecda_core = require("phecda-core");
|
|
115
|
+
var defaultPipe = {
|
|
116
|
+
async transform(args, reflect) {
|
|
117
|
+
for (const i in args) {
|
|
118
|
+
const { validate, arg } = args[i];
|
|
119
|
+
if (validate === false)
|
|
120
|
+
continue;
|
|
121
|
+
if (validate && !(arg?.constructor === reflect[i])) {
|
|
122
|
+
throw new ValidateException(`${arg} is not ${reflect[i].name}`);
|
|
123
|
+
} else {
|
|
124
|
+
if ((0, import_phecda_core.isPhecda)(reflect[i])) {
|
|
125
|
+
const ret = await (0, import_phecda_core.plainToClass)(reflect[i], arg, {
|
|
126
|
+
transform: false
|
|
127
|
+
});
|
|
128
|
+
if (ret.err.length > 0)
|
|
129
|
+
throw new ValidateException(ret.err[0]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return args.map((item) => item.arg);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/server.ts
|
|
138
|
+
var _Pserver = class {
|
|
139
|
+
key;
|
|
140
|
+
meta;
|
|
141
|
+
method;
|
|
142
|
+
params;
|
|
143
|
+
constructor(key, meta) {
|
|
144
|
+
this.key = key;
|
|
145
|
+
this.meta = meta;
|
|
146
|
+
_Pserver.serverRecord[key] = this;
|
|
147
|
+
}
|
|
148
|
+
static registerGuard(key, handler) {
|
|
149
|
+
_Pserver.guardsRecord[key] = handler;
|
|
150
|
+
}
|
|
151
|
+
static registerInterceptor(key, handler) {
|
|
152
|
+
_Pserver.interceptorsRecord[key] = handler;
|
|
153
|
+
}
|
|
154
|
+
async useGuard(req, guards) {
|
|
155
|
+
for (const guard of guards) {
|
|
156
|
+
if (!await _Pserver.guardsRecord[guard]?.(req))
|
|
157
|
+
throw new ForbiddenException(`Guard exception--${guard}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async useInterceptor(req, interceptors) {
|
|
161
|
+
const ret = [];
|
|
162
|
+
for (const interceptor of interceptors) {
|
|
163
|
+
const post = await _Pserver.interceptorsRecord[interceptor]?.(req);
|
|
164
|
+
if (post)
|
|
165
|
+
ret.push(post);
|
|
166
|
+
}
|
|
167
|
+
return ret;
|
|
168
|
+
}
|
|
169
|
+
async usePost(ret, cbs) {
|
|
170
|
+
for (const cb of cbs)
|
|
171
|
+
ret = await cb(ret) | ret;
|
|
172
|
+
return ret;
|
|
173
|
+
}
|
|
174
|
+
async usePipe(args, reflect) {
|
|
175
|
+
return _Pserver.pipe.transform(args, reflect);
|
|
176
|
+
}
|
|
177
|
+
methodToHandler(method) {
|
|
178
|
+
const { data: { params, guards, interceptors }, reflect } = this.meta;
|
|
179
|
+
return async (req) => {
|
|
180
|
+
try {
|
|
181
|
+
await this.useGuard(req, guards);
|
|
182
|
+
const posts = await this.useInterceptor(req, interceptors);
|
|
183
|
+
const args = params.map((param) => {
|
|
184
|
+
const { type, key, validate } = param;
|
|
185
|
+
return {
|
|
186
|
+
arg: req[type]?.[key],
|
|
187
|
+
validate
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
const ret = await method(...await this.usePipe(args, reflect));
|
|
191
|
+
return this.usePost(ret, posts);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
console.log(e);
|
|
194
|
+
if (!(e instanceof HttpException))
|
|
195
|
+
return new UndefinedException(e.message || e);
|
|
196
|
+
return e;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var Pserver = _Pserver;
|
|
202
|
+
__name(Pserver, "Pserver");
|
|
203
|
+
__publicField(Pserver, "pipe", defaultPipe);
|
|
204
|
+
__publicField(Pserver, "guardsRecord", {});
|
|
205
|
+
__publicField(Pserver, "middlewareRecord", {});
|
|
206
|
+
__publicField(Pserver, "interceptorsRecord", {});
|
|
207
|
+
__publicField(Pserver, "serverRecord", {});
|
|
208
|
+
function addGuard(key, handler) {
|
|
209
|
+
Pserver.registerGuard(key, handler);
|
|
210
|
+
}
|
|
211
|
+
__name(addGuard, "addGuard");
|
|
212
|
+
function addInterceptor(key, handler) {
|
|
213
|
+
Pserver.registerInterceptor(key, handler);
|
|
214
|
+
}
|
|
215
|
+
__name(addInterceptor, "addInterceptor");
|
|
216
|
+
function usePipe(pipe) {
|
|
217
|
+
Pserver.pipe = pipe;
|
|
218
|
+
}
|
|
219
|
+
__name(usePipe, "usePipe");
|
|
220
|
+
|
|
221
|
+
// src/compiler.ts
|
|
222
|
+
var Pcompiler = class {
|
|
223
|
+
content = "";
|
|
224
|
+
classMap = {};
|
|
225
|
+
constructor() {
|
|
226
|
+
}
|
|
227
|
+
getContent() {
|
|
228
|
+
let content = "";
|
|
229
|
+
for (const name in this.classMap) {
|
|
230
|
+
content += `
|
|
231
|
+
export class ${name}{
|
|
232
|
+
${Object.values(this.classMap[name]).reduce((p, c) => p + c)}
|
|
233
|
+
}`;
|
|
234
|
+
}
|
|
235
|
+
return content;
|
|
236
|
+
}
|
|
237
|
+
addMethod(className, methodName, route = "", requestType = "", params = []) {
|
|
238
|
+
const url = route.replace(/\/\:([^\/]*)/g, "");
|
|
239
|
+
if (!this.classMap[className])
|
|
240
|
+
this.classMap[className] = {};
|
|
241
|
+
this.classMap[className][methodName] = `
|
|
242
|
+
${methodName}(${genParams(params)}){
|
|
243
|
+
const ret={name:"${className}-${methodName}",body:{},query:{},params:{},realParam:'',method:"${requestType}",url:"${url}"}
|
|
244
|
+
${params.reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}
|
|
245
|
+
${c.type === "params" ? `ret.realParam+='/'+arg${i}
|
|
246
|
+
` : ""}`, "")}
|
|
247
|
+
return ret
|
|
248
|
+
}
|
|
249
|
+
`;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
__name(Pcompiler, "Pcompiler");
|
|
253
|
+
function genParams(decorators) {
|
|
254
|
+
let index = 0;
|
|
255
|
+
return decorators.reduce((p) => {
|
|
256
|
+
return `${`${p}arg${index++}`},`;
|
|
257
|
+
}, "");
|
|
258
|
+
}
|
|
259
|
+
__name(genParams, "genParams");
|
|
260
|
+
|
|
261
|
+
// src/utils.ts
|
|
262
|
+
var isUndefined = /* @__PURE__ */ __name((obj) => typeof obj === "undefined", "isUndefined");
|
|
263
|
+
var isNil = /* @__PURE__ */ __name((obj) => isUndefined(obj) || obj === null, "isNil");
|
|
264
|
+
var isObject = /* @__PURE__ */ __name((fn) => !isNil(fn) && typeof fn === "object", "isObject");
|
|
265
|
+
|
|
266
|
+
// src/express.ts
|
|
267
|
+
function bindApp(app, { meta, moduleMap }, key = "/__PHECDA_SERVER__") {
|
|
268
|
+
const methodMap = {};
|
|
269
|
+
for (const i of meta) {
|
|
270
|
+
const { name, method, route, header } = i.data;
|
|
271
|
+
const server = new Pserver(`${name}`, i);
|
|
272
|
+
const instance = moduleMap.get(name);
|
|
273
|
+
const handler = server.methodToHandler(instance[method].bind(instance));
|
|
274
|
+
methodMap[`${name}-${method}`] = handler;
|
|
275
|
+
if (route) {
|
|
276
|
+
app[route.type](route.route, async (req, res) => {
|
|
277
|
+
instance.request = req;
|
|
278
|
+
instance.meta = req.body;
|
|
279
|
+
const ret = await handler(req);
|
|
280
|
+
for (const name2 in header)
|
|
281
|
+
res.set(name2, header[name2]);
|
|
282
|
+
if (ret instanceof HttpException) {
|
|
283
|
+
res.status(ret.status).json(ret.data);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (isObject(ret))
|
|
287
|
+
res.json(ret);
|
|
288
|
+
else
|
|
289
|
+
res.send(String(ret));
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
app.post(key, async (req, res) => {
|
|
294
|
+
const { body } = req;
|
|
295
|
+
const ret = [];
|
|
296
|
+
for (const i in body) {
|
|
297
|
+
const res2 = await methodMap[i](body[i]);
|
|
298
|
+
ret.push(ret instanceof HttpException ? res2.data : res2);
|
|
299
|
+
}
|
|
300
|
+
res.json(ret);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
__name(bindApp, "bindApp");
|
|
304
|
+
|
|
305
|
+
// src/core.ts
|
|
306
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
307
|
+
var import_phecda_core2 = require("phecda-core");
|
|
308
|
+
|
|
309
|
+
// src/meta.ts
|
|
310
|
+
var Pmeta = class {
|
|
311
|
+
data;
|
|
312
|
+
reflect;
|
|
313
|
+
constructor(data, reflect) {
|
|
314
|
+
this.data = data;
|
|
315
|
+
this.reflect = reflect;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
__name(Pmeta, "Pmeta");
|
|
319
|
+
|
|
320
|
+
// src/core.ts
|
|
321
|
+
function Factory(Modules) {
|
|
322
|
+
const moduleMap = /* @__PURE__ */ new Map();
|
|
323
|
+
const meta = [];
|
|
324
|
+
Modules.forEach((Module) => buildNestModule(Module, moduleMap, meta));
|
|
325
|
+
return {
|
|
326
|
+
moduleMap,
|
|
327
|
+
meta
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
__name(Factory, "Factory");
|
|
331
|
+
function buildNestModule(Module, map, meta) {
|
|
332
|
+
const paramtypes = getParamtypes(Module);
|
|
333
|
+
let instance;
|
|
334
|
+
const name = Module.name;
|
|
335
|
+
if (map.has(name)) {
|
|
336
|
+
instance = map.get(name);
|
|
337
|
+
if (!instance)
|
|
338
|
+
throw new Error(`exist Circular Module dep--${Module}`);
|
|
339
|
+
return instance;
|
|
340
|
+
}
|
|
341
|
+
map.set(name, void 0);
|
|
342
|
+
if (paramtypes) {
|
|
343
|
+
instance = new Module(...paramtypes.map((item) => buildNestModule(item, map, meta)));
|
|
344
|
+
} else {
|
|
345
|
+
instance = new Module();
|
|
346
|
+
}
|
|
347
|
+
meta.push(...getMetaFromInstance(instance, name));
|
|
348
|
+
map.set(name, instance);
|
|
349
|
+
return instance;
|
|
350
|
+
}
|
|
351
|
+
__name(buildNestModule, "buildNestModule");
|
|
352
|
+
function getMetaFromInstance(instance, name) {
|
|
353
|
+
const vars = (0, import_phecda_core2.getModelState)(instance).filter((item) => item !== "__CLASS");
|
|
354
|
+
const baseState = (0, import_phecda_core2.getState)(instance, "__CLASS") || {};
|
|
355
|
+
initState(baseState);
|
|
356
|
+
return vars.map((i) => {
|
|
357
|
+
const state = (0, import_phecda_core2.getState)(instance, i);
|
|
358
|
+
if (baseState.route && state.route)
|
|
359
|
+
state.route.route = baseState.route.route + state.route.route;
|
|
360
|
+
state.name = name;
|
|
361
|
+
state.method = i;
|
|
362
|
+
const params = [];
|
|
363
|
+
for (const i2 of state.params || []) {
|
|
364
|
+
params.unshift(i2);
|
|
365
|
+
if (i2.index === 0)
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
state.params = params;
|
|
369
|
+
initState(state);
|
|
370
|
+
state.header = Object.assign({}, baseState.header, state.header);
|
|
371
|
+
state.middlewares = [
|
|
372
|
+
.../* @__PURE__ */ new Set([
|
|
373
|
+
...baseState.middlewares,
|
|
374
|
+
...state.middlewares
|
|
375
|
+
])
|
|
376
|
+
];
|
|
377
|
+
state.guards = [
|
|
378
|
+
.../* @__PURE__ */ new Set([
|
|
379
|
+
...baseState.guards,
|
|
380
|
+
...state.guards
|
|
381
|
+
])
|
|
382
|
+
];
|
|
383
|
+
state.interceptors = [
|
|
384
|
+
.../* @__PURE__ */ new Set([
|
|
385
|
+
...baseState.interceptors,
|
|
386
|
+
...state.interceptors
|
|
387
|
+
])
|
|
388
|
+
];
|
|
389
|
+
return new Pmeta(state, getParamtypes(instance, i) || []);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
__name(getMetaFromInstance, "getMetaFromInstance");
|
|
393
|
+
function getParamtypes(Module, key) {
|
|
394
|
+
return Reflect.getMetadata("design:paramtypes", Module, key);
|
|
395
|
+
}
|
|
396
|
+
__name(getParamtypes, "getParamtypes");
|
|
397
|
+
function initState(state) {
|
|
398
|
+
if (!state.header)
|
|
399
|
+
state.header = {};
|
|
400
|
+
if (!state.middlewares)
|
|
401
|
+
state.middlewares = [];
|
|
402
|
+
if (!state.guards)
|
|
403
|
+
state.guards = [];
|
|
404
|
+
if (!state.interceptors)
|
|
405
|
+
state.interceptors = [];
|
|
406
|
+
}
|
|
407
|
+
__name(initState, "initState");
|
|
408
|
+
|
|
409
|
+
// src/decorators/index.ts
|
|
410
|
+
var import_phecda_core5 = require("phecda-core");
|
|
411
|
+
|
|
412
|
+
// src/decorators/param.ts
|
|
413
|
+
var import_phecda_core3 = require("phecda-core");
|
|
414
|
+
function BaseParam(type, key, validate) {
|
|
415
|
+
return (target, k, index) => {
|
|
416
|
+
(0, import_phecda_core3.setModalVar)(target, k);
|
|
417
|
+
(0, import_phecda_core3.mergeState)(target, k, {
|
|
418
|
+
params: [
|
|
419
|
+
{
|
|
420
|
+
type,
|
|
421
|
+
key,
|
|
422
|
+
index,
|
|
423
|
+
validate
|
|
424
|
+
}
|
|
425
|
+
]
|
|
426
|
+
});
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
__name(BaseParam, "BaseParam");
|
|
430
|
+
function Body(key, validate) {
|
|
431
|
+
return BaseParam("body", key, validate);
|
|
432
|
+
}
|
|
433
|
+
__name(Body, "Body");
|
|
434
|
+
function Query(key, validate) {
|
|
435
|
+
return BaseParam("query", key, validate);
|
|
436
|
+
}
|
|
437
|
+
__name(Query, "Query");
|
|
438
|
+
function Param(key, validate) {
|
|
439
|
+
return BaseParam("params", key, validate);
|
|
440
|
+
}
|
|
441
|
+
__name(Param, "Param");
|
|
442
|
+
|
|
443
|
+
// src/decorators/route.ts
|
|
444
|
+
var import_phecda_core4 = require("phecda-core");
|
|
445
|
+
function Route(route, type) {
|
|
446
|
+
return (target, key) => {
|
|
447
|
+
if (key) {
|
|
448
|
+
(0, import_phecda_core4.setModalVar)(target, key);
|
|
449
|
+
(0, import_phecda_core4.mergeState)(target, key, {
|
|
450
|
+
route: {
|
|
451
|
+
route,
|
|
452
|
+
type
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
} else {
|
|
456
|
+
(0, import_phecda_core4.setModalVar)(target.prototype, "__CLASS");
|
|
457
|
+
(0, import_phecda_core4.mergeState)(target.prototype, "__CLASS", {
|
|
458
|
+
route: {
|
|
459
|
+
route,
|
|
460
|
+
type
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
__name(Route, "Route");
|
|
467
|
+
function Get(route) {
|
|
468
|
+
return Route(route, "get");
|
|
469
|
+
}
|
|
470
|
+
__name(Get, "Get");
|
|
471
|
+
function Post(route) {
|
|
472
|
+
return Route(route, "post");
|
|
473
|
+
}
|
|
474
|
+
__name(Post, "Post");
|
|
475
|
+
function Put(route) {
|
|
476
|
+
return Route(route, "put");
|
|
477
|
+
}
|
|
478
|
+
__name(Put, "Put");
|
|
479
|
+
function Delete(route) {
|
|
480
|
+
return Route(route, "delete");
|
|
481
|
+
}
|
|
482
|
+
__name(Delete, "Delete");
|
|
483
|
+
function Controller(route) {
|
|
484
|
+
return Route(route);
|
|
485
|
+
}
|
|
486
|
+
__name(Controller, "Controller");
|
|
487
|
+
|
|
488
|
+
// src/decorators/index.ts
|
|
489
|
+
function Inject() {
|
|
490
|
+
}
|
|
491
|
+
__name(Inject, "Inject");
|
|
492
|
+
function Header(name, value) {
|
|
493
|
+
return (target, k) => {
|
|
494
|
+
(0, import_phecda_core5.setModalVar)(target, k);
|
|
495
|
+
(0, import_phecda_core5.mergeState)(target, k, {
|
|
496
|
+
header: {
|
|
497
|
+
name,
|
|
498
|
+
value
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
__name(Header, "Header");
|
|
504
|
+
|
|
505
|
+
// src/vite/index.ts
|
|
506
|
+
var import_path = require("path");
|
|
507
|
+
var import_vite = require("vite");
|
|
508
|
+
function Server(localPath) {
|
|
509
|
+
let root;
|
|
510
|
+
let metaPath;
|
|
511
|
+
return {
|
|
512
|
+
name: "phecda-server-vite:client",
|
|
513
|
+
enforce: "pre",
|
|
514
|
+
configResolved(config) {
|
|
515
|
+
root = config.root || process.cwd();
|
|
516
|
+
metaPath = (0, import_vite.normalizePath)((0, import_path.resolve)(root, localPath));
|
|
517
|
+
},
|
|
518
|
+
resolveId(id) {
|
|
519
|
+
if (id.endsWith(".controller"))
|
|
520
|
+
return metaPath;
|
|
521
|
+
},
|
|
522
|
+
transform(code, id) {
|
|
523
|
+
if (id === metaPath) {
|
|
524
|
+
const meta = JSON.parse(code);
|
|
525
|
+
const compiler = new Pcompiler();
|
|
526
|
+
for (const i of meta)
|
|
527
|
+
compiler.addMethod(i.name, i.method, i.route?.route, i.route?.type, i.params);
|
|
528
|
+
return {
|
|
529
|
+
code: compiler.getContent()
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
__name(Server, "Server");
|
|
536
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
537
|
+
0 && (module.exports = {
|
|
538
|
+
BadRequestException,
|
|
539
|
+
BaseParam,
|
|
540
|
+
Body,
|
|
541
|
+
Controller,
|
|
542
|
+
Delete,
|
|
543
|
+
Factory,
|
|
544
|
+
ForbiddenException,
|
|
545
|
+
Get,
|
|
546
|
+
Header,
|
|
547
|
+
HttpException,
|
|
548
|
+
Inject,
|
|
549
|
+
Param,
|
|
550
|
+
Pcompiler,
|
|
551
|
+
Pmeta,
|
|
552
|
+
Post,
|
|
553
|
+
Pserver,
|
|
554
|
+
Put,
|
|
555
|
+
Query,
|
|
556
|
+
Route,
|
|
557
|
+
Server,
|
|
558
|
+
UndefinedException,
|
|
559
|
+
ValidateException,
|
|
560
|
+
addGuard,
|
|
561
|
+
addInterceptor,
|
|
562
|
+
bindApp,
|
|
563
|
+
defaultPipe,
|
|
564
|
+
usePipe
|
|
565
|
+
});
|
|
566
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/exception/base.ts","../src/exception/undefine.ts","../src/exception/validate.ts","../src/exception/forbidden.ts","../src/exception/bad-request.ts","../src/pipe.ts","../src/server.ts","../src/compiler.ts","../src/utils.ts","../src/express.ts","../src/core.ts","../src/meta.ts","../src/decorators/index.ts","../src/decorators/param.ts","../src/decorators/route.ts","../src/vite/index.ts"],"sourcesContent":["export * from './server'\nexport * from './types'\nexport * from './compiler'\nexport * from './express'\nexport * from './core'\nexport * from './decorators'\nexport * from './vite'\nexport * from './exception'\nexport * from './pipe'\nexport * from './meta'\n","export class HttpException 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: true }\n }\n}\n","import { HttpException } from './base'\n\nexport class UndefinedException extends HttpException {\n constructor(message: string) {\n super(message, 500, 'Undefined error')\n }\n}\n","import { HttpException } from './base'\n\nexport class ValidateException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Validate exception')\n }\n}\n","import { HttpException } from './base'\n\nexport class ForbiddenException extends HttpException {\n constructor(message: string) {\n super(message, 403, 'Forbidden resource')\n }\n}\n","import { HttpException } from './base'\n\nexport class BadRequestException extends HttpException {\n constructor(message: string) {\n super(message, 400, 'Bad Request')\n }\n}\n","import { isPhecda, plainToClass } from 'phecda-core'\nimport { ValidateException } from './exception/validate'\n\nexport interface Ppipe {\n transform(args: { arg: any; validate?: boolean }[], reflect: any[]): Promise<any[]>\n}\n\nexport const defaultPipe = {\n async transform(args: { arg: any; validate: boolean }[], reflect: any[]) {\n for (const i in args) {\n const { validate, arg } = args[i]\n if (validate === false)\n continue\n if (validate && !(arg?.constructor === reflect[i])) {\n throw new ValidateException(`${arg} is not ${reflect[i].name}`)\n }\n else {\n if (isPhecda(reflect[i])) {\n const ret = await plainToClass(reflect[i], arg, { transform: false })\n if (ret.err.length > 0)\n throw new ValidateException(ret.err[0])\n }\n }\n }\n return args.map(item => item.arg)\n },\n} as Ppipe\n","import { ForbiddenException } from './exception'\nimport { HttpException } from './exception/base'\nimport { UndefinedException } from './exception/undefine'\nimport type { Pmeta } from './meta'\nimport type { Ppipe } from './pipe'\nimport { defaultPipe } from './pipe'\n\nexport class Pserver {\n method: string\n params: string[]\n static pipe: Ppipe = defaultPipe\n static guardsRecord: Record<string, (...params: any) => boolean> = {}\n static middlewareRecord: Record<string, (...params: any) => boolean> = {}\n static interceptorsRecord: Record<string, (...params: any) => any | ((...params: any) => any)> = {}\n static serverRecord: Record<string, Pserver> = {}\n\n constructor(public key: string, public meta: Pmeta) {\n Pserver.serverRecord[key] = this\n }\n\n static registerGuard(key: string, handler: any) {\n Pserver.guardsRecord[key] = handler\n }\n\n static registerInterceptor(key: string, handler: any) {\n Pserver.interceptorsRecord[key] = handler\n }\n\n async useGuard(req: any, guards: string[]) {\n for (const guard of guards) {\n if (!await Pserver.guardsRecord[guard]?.(req))\n throw new ForbiddenException(`Guard exception--${guard}`)\n }\n }\n\n async useInterceptor(req: any, interceptors: string[]) {\n const ret = []\n for (const interceptor of interceptors) {\n const post = await Pserver.interceptorsRecord[interceptor]?.(req)\n if (post)\n ret.push(post)\n }\n return ret\n }\n\n async usePost(ret: any, cbs: ((...params: any[]) => any)[]) {\n for (const cb of cbs)\n ret = (await cb(ret)) | ret\n\n return ret\n }\n\n async usePipe(args: { arg: any; validate?: boolean }[], reflect: any[]) {\n return Pserver.pipe.transform(args, reflect)\n }\n\n methodToHandler(method: (...params: any[]) => any) {\n const { data: { params, guards, interceptors }, reflect } = this.meta\n\n return async (req: any) => {\n try {\n await this.useGuard(req, guards)\n const posts = await this.useInterceptor(req, interceptors!)\n const args = params.map((param) => {\n const { type, key, validate } = param\n return { arg: req[type]?.[key], validate }\n })\n\n const ret = await method(...await this.usePipe(args, reflect))\n return this.usePost(ret, posts)\n }\n catch (e: any) {\n console.log(e)\n if (!(e instanceof HttpException))\n return new UndefinedException(e.message || e)\n return e\n }\n }\n }\n}\n\nexport function addGuard(key: string, handler: (...params: any) => boolean) {\n Pserver.registerGuard(key, handler)\n}\n\nexport function addInterceptor(key: string, handler: (...params: any) => any | ((...params: any) => any)) {\n Pserver.registerInterceptor(key, handler)\n}\n\nexport function usePipe(pipe: Ppipe) {\n Pserver.pipe = pipe\n}\n","import type { RequestType } from './types'\n\nexport class Pcompiler {\n content = ''\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(className: string, methodName: string, route = '', requestType: RequestType | '' = '', params: { type: string; key: string; index: number }[] = []) {\n const url = route.replace(/\\/\\:([^\\/]*)/g, '')\n if (!this.classMap[className])\n this.classMap[className] = {}\n this.classMap[className][methodName] = `\n ${methodName}(${genParams(params)}){\nconst ret={name:\"${className}-${methodName}\",body:{},query:{},params:{},realParam:'',method:\"${requestType}\",url:\"${url}\"}\n${params.reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}\\n${c.type === 'params' ? `ret.realParam+='/'+arg${i}\\n` : ''}`, '')}\nreturn ret\n }\n `\n }\n}\n\n// function genExpression(type: string, key: string, index: number) {\n// switch (type) {\n// case 'params':\n// return `ret.params+='/'+arg${index}`\n// case 'query':\n// return `ret.query+=ret.query?\"&${key}=\"+arg${index}:\"?${key}=\"+arg${index}`\n// case 'body':\n// return `ret.body[${key}]=arg${index}`\n// }\n// }\n\nfunction genParams(decorators: any[]) {\n let index = 0\n return decorators.reduce((p) => {\n return `${`${p}arg${index++}`},`\n }, '')\n}\n","export const isUndefined = (obj: any): obj is undefined =>\n typeof obj === 'undefined'\nexport const isNil = (obj: any): obj is null | undefined =>\n isUndefined(obj) || obj === null\n\nexport const isObject = (fn: any): fn is object =>\n !isNil(fn) && typeof fn === 'object'\n\n/**\n * @experiment\n */\nexport class Wrap<F, T> {\n constructor(public v1: F,\n public V2: T) {\n\n }\n\n get value() {\n return this.V2\n }\n}\n","import type { Express } from 'express'\nimport { Pserver } from './server'\nimport { HttpException } from './exception/base'\nimport { isObject } from './utils'\nimport type { Pmeta } from './meta'\nexport function bindApp(app: Express, { meta, moduleMap }: { meta: Pmeta[]; moduleMap: any }, key = '/__PHECDA_SERVER__') {\n const methodMap = {} as Record<string, (...args: any[]) => any>\n for (const i of meta) {\n const { name, method, route, header } = i.data\n const server = new Pserver(`${name}`, i)\n const instance = moduleMap.get(name)!\n const handler = server.methodToHandler(instance[method].bind(instance))\n methodMap[`${name}-${method}`] = handler\n if (route) {\n app[route.type](route.route, async (req, res) => {\n instance.request = req\n instance.meta = req.body\n\n const ret = await handler(req)\n for (const name in header)\n res.set(name, header[name])\n\n if (ret instanceof HttpException) {\n res.status(ret.status).json(ret.data)\n\n return\n }\n if (isObject(ret))\n res.json(ret)\n else\n res.send(String(ret))\n })\n }\n }\n app.post(key, async (req, res) => {\n const { body } = req\n const ret = [] as any[]\n for (const i in body) {\n const res = await methodMap[i](body[i])\n ret.push(ret instanceof HttpException ? res.data : res)\n }\n\n res.json(ret)\n })\n}\n","import 'reflect-metadata'\nimport type { Phecda } from 'phecda-core'\nimport { getModelState, getState } from 'phecda-core'\n\nimport type { Construct, ServerMeta } from './types'\nimport { Pmeta } from './meta'\n\nexport function Factory<T>(Modules: Construct<T>[]) {\n const moduleMap = new Map<string, InstanceType<Construct>>()\n const meta: Pmeta[] = []\n Modules.forEach(Module => buildNestModule(Module, moduleMap, meta) as InstanceType<Construct<T>>)\n return { moduleMap, meta }\n}\n\nfunction buildNestModule(Module: Construct, map: Map<string, InstanceType<Construct>>, meta: Pmeta[]) {\n const paramtypes = getParamtypes(Module) as Construct[]\n let instance: InstanceType<Construct>\n const name = Module.name\n if (map.has(name)) {\n instance = map.get(name)\n if (!instance)\n throw new Error(`exist Circular Module dep--${Module}`)\n return instance\n }\n map.set(name, undefined)\n if (paramtypes) {\n instance = new Module(...paramtypes.map(item =>\n buildNestModule(item, map, meta),\n ))\n }\n else {\n instance = new Module()\n }\n meta.push(...getMetaFromInstance(instance, name))\n map.set(name, instance)\n\n return instance\n}\n\nfunction getMetaFromInstance(instance: Phecda, name: string) {\n const vars = getModelState(instance).filter(item => item !== '__CLASS')\n const baseState = (getState(instance, '__CLASS') || {}) as ServerMeta\n initState(baseState)\n return vars.map((i) => {\n const state = getState(instance, i) as ServerMeta\n if (baseState.route && state.route)\n state.route.route = baseState.route.route + state.route.route\n state.name = name\n state.method = i\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 state.params = params\n initState(state)\n state.header = Object.assign({}, baseState.header, state.header)\n state.middlewares = [...new Set([...baseState.middlewares, ...state.middlewares])]\n state.guards = [...new Set([...baseState.guards, ...state.guards])]\n state.interceptors = [...new Set([...baseState.interceptors, ...state.interceptors])]\n\n return new Pmeta(state as unknown as ServerMeta, getParamtypes(instance, i) || [])\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.header)\n state.header = {}\n if (!state.middlewares)\n state.middlewares = []\n if (!state.guards)\n state.guards = []\n if (!state.interceptors)\n state.interceptors = []\n}\n","import type { ServerMeta } from './types'\n\nexport class Pmeta {\n constructor(public data: ServerMeta, public reflect: any[]) {\n\n }\n}\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function Inject() { }\n\nexport function Header(name: string, value: string) {\n return (target: any, k: PropertyKey) => {\n setModalVar(target, k)\n mergeState(target, k, {\n header: { name, value },\n })\n }\n}\n\nexport * from './param'\nexport * from './route'\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function BaseParam(type: string, key: string, validate?: boolean): any {\n return (target: any, k: PropertyKey, index: number) => {\n setModalVar(target, k)\n mergeState(target, k, {\n params: [{ type, key, index, validate }],\n })\n }\n}\n\nexport function Body(key: string, validate?: boolean) {\n return BaseParam('body', key, validate)\n}\nexport function Query(key: string, validate?: boolean) {\n return BaseParam('query', key, validate)\n}\nexport function Param(key: string, validate?: boolean) {\n return BaseParam('params', key, validate)\n}\n","import { mergeState, setModalVar } from 'phecda-core'\n\nexport function Route(route: string, type?: string): any {\n return (target: any, key?: PropertyKey) => {\n if (key) {\n setModalVar(target, key)\n mergeState(target, key, {\n route: {\n route,\n type,\n },\n })\n }\n else {\n setModalVar(target.prototype, '__CLASS')\n mergeState(target.prototype, '__CLASS', {\n route: {\n route,\n type,\n },\n })\n }\n }\n}\n\nexport function Get(route: string) {\n return Route(route, 'get')\n}\n\nexport function Post(route: string) {\n return Route(route, 'post')\n}\nexport function Put(route: string) {\n return Route(route, 'put')\n}\n\nexport function Delete(route: string) {\n return Route(route, 'delete')\n}\n\nexport function Controller(route: string) {\n return Route(route)\n}\n","import { resolve } from 'path'\nimport type { PluginOption } from 'vite'\nimport { normalizePath } from 'vite'\nimport { Pcompiler } from '../compiler'\nimport type { ServerMeta } from '../types'\nexport function Server(localPath: string): PluginOption {\n let root: string\n let metaPath: string\n return {\n name: 'phecda-server-vite:client',\n enforce: 'pre',\n configResolved(config) {\n root = config.root || process.cwd()\n metaPath = normalizePath(resolve(root, localPath))\n },\n resolveId(id) {\n if (id.endsWith('.controller'))\n return metaPath\n },\n transform(code, id) {\n if (id === metaPath) {\n const meta = JSON.parse(code) as ServerMeta[]\n const compiler = new Pcompiler()\n\n for (const i of meta)\n compiler.addMethod(i.name, i.method, i.route?.route, i.route?.type, i.params)\n return {\n code: compiler.getContent(),\n }\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACAO,IAAMA,gBAAN,cAA4BC,MAAAA;EACdC;EAAwBC;EAAuBC;EAAlEC,YAAmBH,SAAwBC,QAAuBC,cAAc,kBAAkB;AAChG,UAAMF,OAAAA;mBADWA;kBAAwBC;uBAAuBC;EAElE;EAEA,IAAIE,OAAO;AACT,WAAO;MAAEJ,SAAS,KAAKA;MAASE,aAAa,KAAKA;MAAaD,QAAQ,KAAKA;MAAQI,OAAO;IAAK;EAClG;AACF;AARaP;;;ACEN,IAAMQ,qBAAN,cAAiCC,cAAAA;EACtCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,iBAAA;EACtB;AACF;AAJaH;;;ACAN,IAAMI,oBAAN,cAAgCC,cAAAA;EACrCC,YAAYC,SAAiB;AAC3B,UAAMA,SAAS,KAAK,oBAAA;EACtB;AACF;AAJaH;;;ACAN,IAAMI,qBAAN,cAAiCC,cAAAA;EACtCC,YAA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X,OAAe;AACxC,SAAOD,MAAMC,KAAAA;AACf;AAFgBW;;;AFtCT,SAASC,SAAS;AAAE;AAAXA;AAET,SAASC,OAAOC,MAAcC,OAAe;AAClD,SAAO,CAACC,QAAaC,MAAmB;AACtCC,yCAAYF,QAAQC,CAAAA;AACpBE,wCAAWH,QAAQC,GAAG;MACpBG,QAAQ;QAAEN;QAAMC;MAAM;IACxB,CAAA;EACF;AACF;AAPgBF;;;AGJhB,kBAAwB;AAExB,kBAA8B;AAGvB,SAASQ,OAAOC,WAAiC;AACtD,MAAIC;AACJ,MAAIC;AACJ,SAAO;IACLC,MAAM;IACNC,SAAS;IACTC,eAAeC,QAAQ;AACrBL,aAAOK,OAAOL,QAAQM,QAAQC,IAAG;AACjCN,qBAAWO,+BAAcC,qBAAQT,MAAMD,SAAAA,CAAAA;IACzC;IACAW,UAAUC,IAAI;AACZ,UAAIA,GAAGC,SAAS,aAAA;AACd,eAAOX;IACX;IACAY,UAAUC,MAAMH,IAAI;AAClB,UAAIA,OAAOV,UAAU;AACnB,cAAMc,OAAOC,KAAKC,MAAMH,IAAAA;AACxB,cAAMI,WAAW,IAAIC,UAAAA;AAErB,mBAAWC,KAAKL;AACdG,mBAASG,UAAUD,EAAElB,MAAMkB,EAAEE,QAAQF,EAAEG,OAAOA,OAAOH,EAAEG,OAAOC,MAAMJ,EAAEK,MAAM;AAC9E,eAAO;UACLX,MAAMI,SAASQ,WAAU;QAC3B;MACF;IACF;EACF;AACF;AA3BgB5B;","names":["HttpException","Error","message","status","description","constructor","data","error","UndefinedException","HttpException","constructor","message","ValidateException","HttpException","constructor","message","ForbiddenException","HttpException","constructor","message","BadRequestException","HttpException","constructor","message","defaultPipe","transform","args","reflect","i","validate","arg","constructor","ValidateException","name","isPhecda","ret","plainToClass","err","length","map","item","Pserver","key","meta","method","params","constructor","serverRecord","registerGuard","handler","guardsRecord","registerInterceptor","interceptorsRecord","useGuard","req","guards","guard","ForbiddenException","useInterceptor","interceptors","ret","interceptor","post","push","usePost","cbs","cb","usePipe","args","reflect","pipe","transform","methodToHandler","data","posts","map","param","type","validate","arg","e","console","log","HttpException","UndefinedException","message","defaultPipe","middlewareRecord","addGuard","addInterceptor","Pcompiler","content","classMap","constructor","getContent","name","Object","values","reduce","p","c","addMethod","className","methodName","route","requestType","params","url","replace","genParams","i","type","key","decorators","index","isUndefined","obj","isNil","isObject","fn","bindApp","app","meta","moduleMap","key","methodMap","i","name","method","route","header","data","server","Pserver","instance","get","handler","methodToHandler","bind","type","req","res","request","body","ret","set","HttpException","status","json","isObject","send","String","post","push","import_phecda_core","Pmeta","data","reflect","constructor","Factory","Modules","moduleMap","Map","meta","forEach","Module","buildNestModule","map","paramtypes","getParamtypes","instance","name","has","get","Error","set","undefined","item","push","getMetaFromInstance","vars","getModelState","filter","baseState","getState","initState","i","state","route","method","params","unshift","index","header","Object","assign","middlewares","Set","guards","interceptors","Pmeta","key","Reflect","getMetadata","import_phecda_core","import_phecda_core","BaseParam","type","key","validate","target","k","index","setModalVar","mergeState","params","Body","Query","Param","import_phecda_core","Route","route","type","target","key","setModalVar","mergeState","prototype","Get","Post","Put","Delete","Controller","Inject","Header","name","value","target","k","setModalVar","mergeState","header","Server","localPath","root","metaPath","name","enforce","configResolved","config","process","cwd","normalizePath","resolve","resolveId","id","endsWith","transform","code","meta","JSON","parse","compiler","Pcompiler","i","addMethod","method","route","type","params","getContent"]}
|