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/dist/index.mjs ADDED
@@ -0,0 +1,515 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => {
5
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ return value;
7
+ };
8
+
9
+ // src/exception/base.ts
10
+ var HttpException = class extends Error {
11
+ message;
12
+ status;
13
+ description;
14
+ constructor(message, status, description = "Http exception") {
15
+ super(message);
16
+ this.message = message;
17
+ this.status = status;
18
+ this.description = description;
19
+ }
20
+ get data() {
21
+ return {
22
+ message: this.message,
23
+ description: this.description,
24
+ status: this.status,
25
+ error: true
26
+ };
27
+ }
28
+ };
29
+ __name(HttpException, "HttpException");
30
+
31
+ // src/exception/undefine.ts
32
+ var UndefinedException = class extends HttpException {
33
+ constructor(message) {
34
+ super(message, 500, "Undefined error");
35
+ }
36
+ };
37
+ __name(UndefinedException, "UndefinedException");
38
+
39
+ // src/exception/validate.ts
40
+ var ValidateException = class extends HttpException {
41
+ constructor(message) {
42
+ super(message, 400, "Validate exception");
43
+ }
44
+ };
45
+ __name(ValidateException, "ValidateException");
46
+
47
+ // src/exception/forbidden.ts
48
+ var ForbiddenException = class extends HttpException {
49
+ constructor(message) {
50
+ super(message, 403, "Forbidden resource");
51
+ }
52
+ };
53
+ __name(ForbiddenException, "ForbiddenException");
54
+
55
+ // src/exception/bad-request.ts
56
+ var BadRequestException = class extends HttpException {
57
+ constructor(message) {
58
+ super(message, 400, "Bad Request");
59
+ }
60
+ };
61
+ __name(BadRequestException, "BadRequestException");
62
+
63
+ // src/pipe.ts
64
+ import { isPhecda, plainToClass } from "phecda-core";
65
+ var defaultPipe = {
66
+ async transform(args, reflect) {
67
+ for (const i in args) {
68
+ const { validate, arg } = args[i];
69
+ if (validate === false)
70
+ continue;
71
+ if (validate && !(arg?.constructor === reflect[i])) {
72
+ throw new ValidateException(`${arg} is not ${reflect[i].name}`);
73
+ } else {
74
+ if (isPhecda(reflect[i])) {
75
+ const ret = await plainToClass(reflect[i], arg, {
76
+ transform: false
77
+ });
78
+ if (ret.err.length > 0)
79
+ throw new ValidateException(ret.err[0]);
80
+ }
81
+ }
82
+ }
83
+ return args.map((item) => item.arg);
84
+ }
85
+ };
86
+
87
+ // src/server.ts
88
+ var _Pserver = class {
89
+ key;
90
+ meta;
91
+ method;
92
+ params;
93
+ constructor(key, meta) {
94
+ this.key = key;
95
+ this.meta = meta;
96
+ _Pserver.serverRecord[key] = this;
97
+ }
98
+ static registerGuard(key, handler) {
99
+ _Pserver.guardsRecord[key] = handler;
100
+ }
101
+ static registerInterceptor(key, handler) {
102
+ _Pserver.interceptorsRecord[key] = handler;
103
+ }
104
+ async useGuard(req, guards) {
105
+ for (const guard of guards) {
106
+ if (!await _Pserver.guardsRecord[guard]?.(req))
107
+ throw new ForbiddenException(`Guard exception--${guard}`);
108
+ }
109
+ }
110
+ async useInterceptor(req, interceptors) {
111
+ const ret = [];
112
+ for (const interceptor of interceptors) {
113
+ const post = await _Pserver.interceptorsRecord[interceptor]?.(req);
114
+ if (post)
115
+ ret.push(post);
116
+ }
117
+ return ret;
118
+ }
119
+ async usePost(ret, cbs) {
120
+ for (const cb of cbs)
121
+ ret = await cb(ret) | ret;
122
+ return ret;
123
+ }
124
+ async usePipe(args, reflect) {
125
+ return _Pserver.pipe.transform(args, reflect);
126
+ }
127
+ methodToHandler(method) {
128
+ const { data: { params, guards, interceptors }, reflect } = this.meta;
129
+ return async (req) => {
130
+ try {
131
+ await this.useGuard(req, guards);
132
+ const posts = await this.useInterceptor(req, interceptors);
133
+ const args = params.map((param) => {
134
+ const { type, key, validate } = param;
135
+ return {
136
+ arg: req[type]?.[key],
137
+ validate
138
+ };
139
+ });
140
+ const ret = await method(...await this.usePipe(args, reflect));
141
+ return this.usePost(ret, posts);
142
+ } catch (e) {
143
+ console.log(e);
144
+ if (!(e instanceof HttpException))
145
+ return new UndefinedException(e.message || e);
146
+ return e;
147
+ }
148
+ };
149
+ }
150
+ };
151
+ var Pserver = _Pserver;
152
+ __name(Pserver, "Pserver");
153
+ __publicField(Pserver, "pipe", defaultPipe);
154
+ __publicField(Pserver, "guardsRecord", {});
155
+ __publicField(Pserver, "middlewareRecord", {});
156
+ __publicField(Pserver, "interceptorsRecord", {});
157
+ __publicField(Pserver, "serverRecord", {});
158
+ function addGuard(key, handler) {
159
+ Pserver.registerGuard(key, handler);
160
+ }
161
+ __name(addGuard, "addGuard");
162
+ function addInterceptor(key, handler) {
163
+ Pserver.registerInterceptor(key, handler);
164
+ }
165
+ __name(addInterceptor, "addInterceptor");
166
+ function usePipe(pipe) {
167
+ Pserver.pipe = pipe;
168
+ }
169
+ __name(usePipe, "usePipe");
170
+
171
+ // src/compiler.ts
172
+ var Pcompiler = class {
173
+ content = "";
174
+ classMap = {};
175
+ constructor() {
176
+ }
177
+ getContent() {
178
+ let content = "";
179
+ for (const name in this.classMap) {
180
+ content += `
181
+ export class ${name}{
182
+ ${Object.values(this.classMap[name]).reduce((p, c) => p + c)}
183
+ }`;
184
+ }
185
+ return content;
186
+ }
187
+ addMethod(className, methodName, route = "", requestType = "", params = []) {
188
+ const url = route.replace(/\/\:([^\/]*)/g, "");
189
+ if (!this.classMap[className])
190
+ this.classMap[className] = {};
191
+ this.classMap[className][methodName] = `
192
+ ${methodName}(${genParams(params)}){
193
+ const ret={name:"${className}-${methodName}",body:{},query:{},params:{},realParam:'',method:"${requestType}",url:"${url}"}
194
+ ${params.reduce((p, c, i) => `${p}ret.${c.type}.${c.key}=arg${i}
195
+ ${c.type === "params" ? `ret.realParam+='/'+arg${i}
196
+ ` : ""}`, "")}
197
+ return ret
198
+ }
199
+ `;
200
+ }
201
+ };
202
+ __name(Pcompiler, "Pcompiler");
203
+ function genParams(decorators) {
204
+ let index = 0;
205
+ return decorators.reduce((p) => {
206
+ return `${`${p}arg${index++}`},`;
207
+ }, "");
208
+ }
209
+ __name(genParams, "genParams");
210
+
211
+ // src/utils.ts
212
+ var isUndefined = /* @__PURE__ */ __name((obj) => typeof obj === "undefined", "isUndefined");
213
+ var isNil = /* @__PURE__ */ __name((obj) => isUndefined(obj) || obj === null, "isNil");
214
+ var isObject = /* @__PURE__ */ __name((fn) => !isNil(fn) && typeof fn === "object", "isObject");
215
+
216
+ // src/express.ts
217
+ function bindApp(app, { meta, moduleMap }, key = "/__PHECDA_SERVER__") {
218
+ const methodMap = {};
219
+ for (const i of meta) {
220
+ const { name, method, route, header } = i.data;
221
+ const server = new Pserver(`${name}`, i);
222
+ const instance = moduleMap.get(name);
223
+ const handler = server.methodToHandler(instance[method].bind(instance));
224
+ methodMap[`${name}-${method}`] = handler;
225
+ if (route) {
226
+ app[route.type](route.route, async (req, res) => {
227
+ instance.request = req;
228
+ instance.meta = req.body;
229
+ const ret = await handler(req);
230
+ for (const name2 in header)
231
+ res.set(name2, header[name2]);
232
+ if (ret instanceof HttpException) {
233
+ res.status(ret.status).json(ret.data);
234
+ return;
235
+ }
236
+ if (isObject(ret))
237
+ res.json(ret);
238
+ else
239
+ res.send(String(ret));
240
+ });
241
+ }
242
+ }
243
+ app.post(key, async (req, res) => {
244
+ const { body } = req;
245
+ const ret = [];
246
+ for (const i in body) {
247
+ const res2 = await methodMap[i](body[i]);
248
+ ret.push(ret instanceof HttpException ? res2.data : res2);
249
+ }
250
+ res.json(ret);
251
+ });
252
+ }
253
+ __name(bindApp, "bindApp");
254
+
255
+ // src/core.ts
256
+ import "reflect-metadata";
257
+ import { getModelState, getState } from "phecda-core";
258
+
259
+ // src/meta.ts
260
+ var Pmeta = class {
261
+ data;
262
+ reflect;
263
+ constructor(data, reflect) {
264
+ this.data = data;
265
+ this.reflect = reflect;
266
+ }
267
+ };
268
+ __name(Pmeta, "Pmeta");
269
+
270
+ // src/core.ts
271
+ function Factory(Modules) {
272
+ const moduleMap = /* @__PURE__ */ new Map();
273
+ const meta = [];
274
+ Modules.forEach((Module) => buildNestModule(Module, moduleMap, meta));
275
+ return {
276
+ moduleMap,
277
+ meta
278
+ };
279
+ }
280
+ __name(Factory, "Factory");
281
+ function buildNestModule(Module, map, meta) {
282
+ const paramtypes = getParamtypes(Module);
283
+ let instance;
284
+ const name = Module.name;
285
+ if (map.has(name)) {
286
+ instance = map.get(name);
287
+ if (!instance)
288
+ throw new Error(`exist Circular Module dep--${Module}`);
289
+ return instance;
290
+ }
291
+ map.set(name, void 0);
292
+ if (paramtypes) {
293
+ instance = new Module(...paramtypes.map((item) => buildNestModule(item, map, meta)));
294
+ } else {
295
+ instance = new Module();
296
+ }
297
+ meta.push(...getMetaFromInstance(instance, name));
298
+ map.set(name, instance);
299
+ return instance;
300
+ }
301
+ __name(buildNestModule, "buildNestModule");
302
+ function getMetaFromInstance(instance, name) {
303
+ const vars = getModelState(instance).filter((item) => item !== "__CLASS");
304
+ const baseState = getState(instance, "__CLASS") || {};
305
+ initState(baseState);
306
+ return vars.map((i) => {
307
+ const state = getState(instance, i);
308
+ if (baseState.route && state.route)
309
+ state.route.route = baseState.route.route + state.route.route;
310
+ state.name = name;
311
+ state.method = i;
312
+ const params = [];
313
+ for (const i2 of state.params || []) {
314
+ params.unshift(i2);
315
+ if (i2.index === 0)
316
+ break;
317
+ }
318
+ state.params = params;
319
+ initState(state);
320
+ state.header = Object.assign({}, baseState.header, state.header);
321
+ state.middlewares = [
322
+ .../* @__PURE__ */ new Set([
323
+ ...baseState.middlewares,
324
+ ...state.middlewares
325
+ ])
326
+ ];
327
+ state.guards = [
328
+ .../* @__PURE__ */ new Set([
329
+ ...baseState.guards,
330
+ ...state.guards
331
+ ])
332
+ ];
333
+ state.interceptors = [
334
+ .../* @__PURE__ */ new Set([
335
+ ...baseState.interceptors,
336
+ ...state.interceptors
337
+ ])
338
+ ];
339
+ return new Pmeta(state, getParamtypes(instance, i) || []);
340
+ });
341
+ }
342
+ __name(getMetaFromInstance, "getMetaFromInstance");
343
+ function getParamtypes(Module, key) {
344
+ return Reflect.getMetadata("design:paramtypes", Module, key);
345
+ }
346
+ __name(getParamtypes, "getParamtypes");
347
+ function initState(state) {
348
+ if (!state.header)
349
+ state.header = {};
350
+ if (!state.middlewares)
351
+ state.middlewares = [];
352
+ if (!state.guards)
353
+ state.guards = [];
354
+ if (!state.interceptors)
355
+ state.interceptors = [];
356
+ }
357
+ __name(initState, "initState");
358
+
359
+ // src/decorators/index.ts
360
+ import { mergeState as mergeState3, setModalVar as setModalVar3 } from "phecda-core";
361
+
362
+ // src/decorators/param.ts
363
+ import { mergeState, setModalVar } from "phecda-core";
364
+ function BaseParam(type, key, validate) {
365
+ return (target, k, index) => {
366
+ setModalVar(target, k);
367
+ mergeState(target, k, {
368
+ params: [
369
+ {
370
+ type,
371
+ key,
372
+ index,
373
+ validate
374
+ }
375
+ ]
376
+ });
377
+ };
378
+ }
379
+ __name(BaseParam, "BaseParam");
380
+ function Body(key, validate) {
381
+ return BaseParam("body", key, validate);
382
+ }
383
+ __name(Body, "Body");
384
+ function Query(key, validate) {
385
+ return BaseParam("query", key, validate);
386
+ }
387
+ __name(Query, "Query");
388
+ function Param(key, validate) {
389
+ return BaseParam("params", key, validate);
390
+ }
391
+ __name(Param, "Param");
392
+
393
+ // src/decorators/route.ts
394
+ import { mergeState as mergeState2, setModalVar as setModalVar2 } from "phecda-core";
395
+ function Route(route, type) {
396
+ return (target, key) => {
397
+ if (key) {
398
+ setModalVar2(target, key);
399
+ mergeState2(target, key, {
400
+ route: {
401
+ route,
402
+ type
403
+ }
404
+ });
405
+ } else {
406
+ setModalVar2(target.prototype, "__CLASS");
407
+ mergeState2(target.prototype, "__CLASS", {
408
+ route: {
409
+ route,
410
+ type
411
+ }
412
+ });
413
+ }
414
+ };
415
+ }
416
+ __name(Route, "Route");
417
+ function Get(route) {
418
+ return Route(route, "get");
419
+ }
420
+ __name(Get, "Get");
421
+ function Post(route) {
422
+ return Route(route, "post");
423
+ }
424
+ __name(Post, "Post");
425
+ function Put(route) {
426
+ return Route(route, "put");
427
+ }
428
+ __name(Put, "Put");
429
+ function Delete(route) {
430
+ return Route(route, "delete");
431
+ }
432
+ __name(Delete, "Delete");
433
+ function Controller(route) {
434
+ return Route(route);
435
+ }
436
+ __name(Controller, "Controller");
437
+
438
+ // src/decorators/index.ts
439
+ function Inject() {
440
+ }
441
+ __name(Inject, "Inject");
442
+ function Header(name, value) {
443
+ return (target, k) => {
444
+ setModalVar3(target, k);
445
+ mergeState3(target, k, {
446
+ header: {
447
+ name,
448
+ value
449
+ }
450
+ });
451
+ };
452
+ }
453
+ __name(Header, "Header");
454
+
455
+ // src/vite/index.ts
456
+ import { resolve } from "path";
457
+ import { normalizePath } from "vite";
458
+ function Server(localPath) {
459
+ let root;
460
+ let metaPath;
461
+ return {
462
+ name: "phecda-server-vite:client",
463
+ enforce: "pre",
464
+ configResolved(config) {
465
+ root = config.root || process.cwd();
466
+ metaPath = normalizePath(resolve(root, localPath));
467
+ },
468
+ resolveId(id) {
469
+ if (id.endsWith(".controller"))
470
+ return metaPath;
471
+ },
472
+ transform(code, id) {
473
+ if (id === metaPath) {
474
+ const meta = JSON.parse(code);
475
+ const compiler = new Pcompiler();
476
+ for (const i of meta)
477
+ compiler.addMethod(i.name, i.method, i.route?.route, i.route?.type, i.params);
478
+ return {
479
+ code: compiler.getContent()
480
+ };
481
+ }
482
+ }
483
+ };
484
+ }
485
+ __name(Server, "Server");
486
+ export {
487
+ BadRequestException,
488
+ BaseParam,
489
+ Body,
490
+ Controller,
491
+ Delete,
492
+ Factory,
493
+ ForbiddenException,
494
+ Get,
495
+ Header,
496
+ HttpException,
497
+ Inject,
498
+ Param,
499
+ Pcompiler,
500
+ Pmeta,
501
+ Post,
502
+ Pserver,
503
+ Put,
504
+ Query,
505
+ Route,
506
+ Server,
507
+ UndefinedException,
508
+ ValidateException,
509
+ addGuard,
510
+ addInterceptor,
511
+ bindApp,
512
+ defaultPipe,
513
+ usePipe
514
+ };
515
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../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 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":";;;;;;;;;AAAO,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;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AM;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","isPhecda","plainToClass","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","getModelState","getState","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","mergeState","setModalVar","mergeState","setModalVar","BaseParam","type","key","validate","target","k","index","setModalVar","mergeState","params","Body","Query","Param","mergeState","setModalVar","Route","route","type","target","key","setModalVar","mergeState","prototype","Get","Post","Put","Delete","Controller","Inject","Header","name","value","target","k","setModalVar","mergeState","header","resolve","normalizePath","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"]}
@@ -0,0 +1,47 @@
1
+ declare class Wrap<F, T> {
2
+ v1: F;
3
+ V2: T;
4
+ constructor(v1: F, V2: T);
5
+ get value(): T;
6
+ }
7
+
8
+ type Construct<T = any> = new (...args: any[]) => T;
9
+ interface ServerMeta {
10
+ route?: {
11
+ type: RequestType;
12
+ route: string;
13
+ };
14
+ header: Record<string, string>;
15
+ params: {
16
+ type: string;
17
+ index: number;
18
+ key: string;
19
+ validate?: boolean;
20
+ }[];
21
+ guards: string[];
22
+ interceptors: string[];
23
+ middlewares: string[];
24
+ method: string;
25
+ name: string;
26
+ }
27
+ type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
28
+ type MergeType = <R extends Promise<any>[]>(...args: R) => {
29
+ [K in keyof R]: Awaited<R[K]>;
30
+ };
31
+ interface PError {
32
+ message: string;
33
+ error: true;
34
+ description: string;
35
+ status: number;
36
+ }
37
+ type ResOrErr<R> = {
38
+ [K in keyof R]: Awaited<R[K]> | PError;
39
+ };
40
+ type UnWrap<T extends any[]> = {
41
+ [K in keyof T]: T[K] extends Wrap<infer F, infer _> ? F : T[K];
42
+ };
43
+ type Transform<A> = {
44
+ [K in keyof A]: A[K] extends (...args: infer P) => infer R ? (...args: UnWrap<P> extends unknown[] ? UnWrap<P> : unknown[]) => R : never;
45
+ };
46
+
47
+ export { Construct as C, MergeType as M, PError as P, RequestType as R, ServerMeta as S, Transform as T, UnWrap as U, ResOrErr as a };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "phecda-server",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js"
12
+ },
13
+ "./client": {
14
+ "import": "./dist/client/index.mjs",
15
+ "require": "./dist/client/index.js"
16
+ }
17
+ },
18
+ "typesVersions": {
19
+ "*": {
20
+ "client": [
21
+ "dist/client/index.d.ts"
22
+ ]
23
+ }
24
+ },
25
+ "keywords": [],
26
+ "author": "",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "license": "MIT",
31
+ "devDependencies": {
32
+ "@types/express": "^4.17.17",
33
+ "@types/supertest": "^2.0.12",
34
+ "express": "^4.18.2",
35
+ "supertest": "^6.3.3",
36
+ "tsup": "^6.5.0"
37
+ },
38
+ "dependencies": {
39
+ "axios": "^1.3.5",
40
+ "vite": "^4.0.0",
41
+ "reflect-metadata": "^0.1.13",
42
+ "phecda-core": "1.0.6"
43
+ },
44
+ "scripts": {
45
+ "dev": "tsup --watch",
46
+ "build": "tsup"
47
+ }
48
+ }