phecda-server 3.2.0-alpha.5 → 4.0.0-alpha.11

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.
Files changed (39) hide show
  1. package/dist/core-91ada79c.d.ts +21 -0
  2. package/dist/index.d.ts +97 -101
  3. package/dist/index.js +389 -449
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +375 -440
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/rpc/rabbitmq/index.d.ts +23 -0
  8. package/dist/rpc/rabbitmq/index.js +363 -0
  9. package/dist/rpc/rabbitmq/index.js.map +1 -0
  10. package/dist/rpc/rabbitmq/index.mjs +337 -0
  11. package/dist/rpc/rabbitmq/index.mjs.map +1 -0
  12. package/dist/rpc/redis/index.d.ts +24 -0
  13. package/dist/rpc/redis/index.js +366 -0
  14. package/dist/rpc/redis/index.js.map +1 -0
  15. package/dist/rpc/redis/index.mjs +334 -0
  16. package/dist/rpc/redis/index.mjs.map +1 -0
  17. package/dist/server/express/index.d.ts +22 -0
  18. package/dist/server/express/index.js +422 -0
  19. package/dist/server/express/index.js.map +1 -0
  20. package/dist/server/express/index.mjs +391 -0
  21. package/dist/server/express/index.mjs.map +1 -0
  22. package/dist/server/fastify/index.d.ts +21 -0
  23. package/dist/server/fastify/index.js +402 -0
  24. package/dist/server/fastify/index.js.map +1 -0
  25. package/dist/server/fastify/index.mjs +377 -0
  26. package/dist/server/fastify/index.mjs.map +1 -0
  27. package/dist/server/h3/index.d.ts +21 -0
  28. package/dist/server/h3/index.js +435 -0
  29. package/dist/server/h3/index.js.map +1 -0
  30. package/dist/server/h3/index.mjs +410 -0
  31. package/dist/server/h3/index.mjs.map +1 -0
  32. package/dist/test.d.ts +3 -3
  33. package/dist/test.js +397 -251
  34. package/dist/test.js.map +1 -1
  35. package/dist/test.mjs +397 -251
  36. package/dist/test.mjs.map +1 -1
  37. package/dist/{types-b69250fd.d.ts → types-70714e01.d.ts} +28 -41
  38. package/package.json +45 -2
  39. package/register/index.mjs +2 -0
@@ -0,0 +1,21 @@
1
+ import { P, a as Emitter, C as Construct } from './types-70714e01.js';
2
+
3
+ declare class Meta {
4
+ data: P.Meta;
5
+ handlers: P.Handler[];
6
+ paramsType: any[];
7
+ constructor(data: P.Meta, handlers: P.Handler[], paramsType: any[]);
8
+ }
9
+
10
+ declare const emitter: Emitter;
11
+ declare function Factory(Modules: (new (...args: any) => any)[], opts?: {
12
+ http?: string;
13
+ rpc?: string;
14
+ }): Promise<{
15
+ moduleMap: Map<string, any>;
16
+ meta: Meta[];
17
+ constructorMap: Map<any, any>;
18
+ update: (Module: Construct) => Promise<void>;
19
+ }>;
20
+
21
+ export { Factory as F, Meta as M, emitter as e };
package/dist/index.d.ts CHANGED
@@ -1,160 +1,112 @@
1
- import { RequestHandler, Express, Router } from 'express';
2
- import { H as HttpException, M as Meta, P, S as ServerCtx, a as ServerMergeCtx, b as ServerFilter, E as Emitter, C as Construct } from './types-b69250fd.js';
3
- export { d as Base, B as BaseError, c as MergeType, R as RequestType } from './types-b69250fd.js';
1
+ import { E as Exception, P } from './types-70714e01.js';
2
+ export { B as BaseError, C as Construct, a as Emitter, M as MergeType, R as RequestType, S as ServerErr, T as ToInstance } from './types-70714e01.js';
3
+ export { F as Factory, M as Meta, e as emitter } from './core-91ada79c.js';
4
4
  export * from 'phecda-core';
5
5
 
6
- declare class UndefinedException extends HttpException {
7
- constructor(message: string);
6
+ declare class Histroy {
7
+ guard: string[];
8
+ interceptor: string[];
9
+ record(name: string, type: 'guard' | 'interceptor'): boolean;
8
10
  }
9
11
 
10
- declare class ValidateException extends HttpException {
12
+ declare class UndefinedException extends Exception {
11
13
  constructor(message: string);
12
14
  }
13
15
 
14
- declare class ForbiddenException extends HttpException {
16
+ declare class ValidateException extends Exception {
15
17
  constructor(message: string);
16
18
  }
17
19
 
18
- declare class BadRequestException extends HttpException {
20
+ declare class ForbiddenException extends Exception {
19
21
  constructor(message: string);
20
22
  }
21
23
 
22
- declare class NotFoundException extends HttpException {
24
+ declare class BadRequestException extends Exception {
23
25
  constructor(message: string);
24
26
  }
25
27
 
26
- declare class ConflictException extends HttpException {
28
+ declare class NotFoundException extends Exception {
27
29
  constructor(message: string);
28
30
  }
29
31
 
30
- declare class BadGatewayException extends HttpException {
32
+ declare class ConflictException extends Exception {
31
33
  constructor(message: string);
32
34
  }
33
35
 
34
- declare class InvalidInputException extends HttpException {
36
+ declare class BadGatewayException extends Exception {
35
37
  constructor(message: string);
36
38
  }
37
39
 
38
- declare class UnsupportedMediaTypeException extends HttpException {
40
+ declare class InvalidInputException extends Exception {
39
41
  constructor(message: string);
40
42
  }
41
43
 
42
- declare class PayloadLargeException extends HttpException {
44
+ declare class UnsupportedMediaTypeException extends Exception {
43
45
  constructor(message: string);
44
46
  }
45
47
 
46
- declare class TimeoutException extends HttpException {
48
+ declare class PayloadLargeException extends Exception {
47
49
  constructor(message: string);
48
50
  }
49
51
 
50
- declare class UnauthorizedException extends HttpException {
52
+ declare class TimeoutException extends Exception {
51
53
  constructor(message: string);
52
54
  }
53
55
 
54
- declare class ServiceUnavailableException extends HttpException {
56
+ declare class UnauthorizedException extends Exception {
55
57
  constructor(message: string);
56
58
  }
57
59
 
58
- declare class FrameworkException extends HttpException {
60
+ declare class ServiceUnavailableException extends Exception {
59
61
  constructor(message: string);
60
62
  }
61
63
 
62
- declare class Histroy {
63
- guard: string[];
64
- interceptor: string[];
65
- record(name: string, type: 'guard' | 'interceptor'): boolean;
64
+ declare class FrameworkException extends Exception {
65
+ constructor(message: string);
66
66
  }
67
67
 
68
- declare abstract class Context<Data = any> {
69
- key: string;
68
+ declare const guardsRecord: Record<string, P.Guard<any>>;
69
+ declare class Context<Data = any> {
70
+ tag: string;
70
71
  data: Data;
71
72
  method: string;
72
73
  params: string[];
73
- static metaRecord: Record<string, Meta>;
74
- static metaDataRecord: Record<string, ReturnType<typeof parseMeta>>;
75
- static guardsRecord: Record<string, any>;
76
- static interceptorsRecord: Record<string, any>;
77
- post: ((...params: any) => any)[];
78
74
  history: Histroy;
79
- constructor(key: string, data: Data);
80
- static registerGuard(key: string, handler: any): void;
81
- static registerInterceptor(key: string, handler: any): void;
82
- useGuard(guards: string[], isMerge?: boolean): Promise<void>;
83
- useInterceptor(interceptors: string[], isMerge?: boolean): Promise<void>;
84
- usePost(data: any): Promise<any>;
85
- }
86
- declare function addGuard(key: string, handler: P.Guard): void;
87
- declare function addInterceptor(key: string, handler: P.Interceptor): void;
88
- declare function parseMeta(meta: Meta): {
89
- guards: string[];
90
- reflect: any[];
91
- interceptors: string[];
92
- middlewares: string[];
93
- handlers: P.Handler[];
94
- params: {
95
- type: string;
96
- index: number;
97
- key: string;
98
- option?: any;
99
- }[];
100
- };
101
-
102
- declare class ServerContext extends Context<ServerCtx | ServerMergeCtx> {
103
- static pipe: P.Pipe;
104
- static filter: ServerFilter;
75
+ static filter: P.Filter;
76
+ static pipeRecord: Record<string, P.Pipe>;
77
+ static guardsRecord: Record<string, P.Guard>;
78
+ static interceptorsRecord: Record<string, P.Interceptor>;
105
79
  static middlewareRecord: Record<string, (...params: any) => any>;
106
- static useMiddleware(middlewares: string[]): ((...params: any) => any)[];
80
+ postInterceptors: Function[];
81
+ constructor(tag: string, data: Data);
107
82
  usePipe(args: {
108
83
  arg: any;
109
- option?: any;
84
+ pipe?: string;
85
+ pipeOpts?: any;
110
86
  type: string;
111
87
  key: string;
112
88
  index: number;
113
89
  reflect: any;
114
- }[], tag: string): Promise<any[]>;
115
- static useFilter(arg: any, data: ServerCtx | ServerMergeCtx): any;
90
+ }[]): Promise<any[]>;
116
91
  useFilter(arg: any): any;
117
- }
118
- declare function addMiddleware(key: string, handler: RequestHandler): void;
119
- declare function useServerPipe(pipe: P.Pipe): void;
120
- declare function useServerFilter(filter: ServerFilter): void;
121
-
122
- declare const SERIES_SYMBOL = "__PS_SERIES__";
123
- declare const MERGE_SYMBOL = "__PS_MERGE__";
124
- declare const UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
125
- declare const MODULE_SYMBOL = "__PS_MODULE__";
126
- declare const META_SYMBOL = "__PS_META__";
127
- declare const APP_SYMBOL = "__PS__";
128
-
129
- declare const emitter: Emitter;
130
- declare function Factory(Modules: (new (...args: any) => any)[], opts?: {
131
- dev?: boolean;
132
- file?: string;
133
- }): Promise<{
134
- moduleMap: Map<string, any>;
135
- meta: Meta[];
136
- constructorMap: Map<any, any>;
137
- update: (Module: Construct) => Promise<void>;
138
- }>;
139
- declare class Dev {
140
- [UNMOUNT_SYMBOL]: (() => void)[];
141
- onUnmount(cb: () => void): void;
142
- }
143
-
144
- interface Options {
145
- dev?: boolean;
146
- route?: string;
147
- globalGuards?: string[];
148
- globalInterceptors?: string[];
149
- middlewares?: string[];
150
- }
151
- declare function bindApp(app: Express | Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options?: Options): void;
92
+ useGuard(guards: string[]): Promise<void>;
93
+ usePostInterceptor(ret: any): Promise<any>;
94
+ useInterceptor(interceptors: string[]): Promise<true | undefined>;
95
+ static useMiddleware(middlewares: string[]): any[];
96
+ }
97
+ declare function addMiddleware(key: string, handler: (...params: any) => any): void;
98
+ declare function addPipe(key: string, pipe: P.Pipe): void;
99
+ declare function setFilter(filter: P.Filter): void;
100
+ declare function addGuard(key: string, handler: P.Guard): void;
101
+ declare function addInterceptor(key: string, handler: P.Interceptor): void;
152
102
 
153
- declare function BaseParam(type: string, key: string, option?: any): any;
154
- declare function Body(key?: string, pipeOpts?: any): any;
155
- declare function Head(key: string, pipeOpts?: any): any;
156
- declare function Query(key?: string, pipeOpts?: any): any;
157
- declare function Param(key: string, pipeOpts?: any): any;
103
+ declare function BaseParam(type: string, key: string): any;
104
+ declare function Pipe(key?: string, opts?: any): (target: any, k: PropertyKey, index: number) => void;
105
+ declare function Body(key?: string): any;
106
+ declare function Head(key: string): any;
107
+ declare function Query(key?: string): any;
108
+ declare function Param(key: string): any;
109
+ declare function Arg(): any;
158
110
 
159
111
  declare function Route(route: string, type?: string): any;
160
112
  declare function Get(route: string): any;
@@ -163,6 +115,9 @@ declare function Put(route: string): any;
163
115
  declare function Patch(route: string): any;
164
116
  declare function Delete(route: string): any;
165
117
  declare function Controller(route: string): any;
118
+ declare function Rpc(...types: ('mq' | 'redis' | string)[]): (target: any, key?: PropertyKey) => void;
119
+ declare function Event(isEvent?: boolean): (target: any, key?: PropertyKey) => void;
120
+
166
121
  declare function Guard(...guards: string[]): any;
167
122
  declare function Middle(...middlewares: string[]): any;
168
123
  declare function Interceptor(...interceptors: string[]): any;
@@ -172,7 +127,48 @@ declare function Define(key: string, value: any): (target: any, k?: PropertyKey)
172
127
 
173
128
  declare const defaultPipe: P.Pipe;
174
129
 
175
- declare function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx;
176
130
  declare function resolveDep(ret: any, key: string): any;
177
131
 
178
- export { APP_SYMBOL, BadGatewayException, BadRequestException, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Dev, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Head, Header, HttpException, Interceptor, InvalidInputException, MERGE_SYMBOL, META_SYMBOL, MODULE_SYMBOL, Meta, Middle, NotFoundException, Options, P, Param, Patch, PayloadLargeException, Post, Put, Query, Route, SERIES_SYMBOL, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, defaultPipe, emitter, isMerge, parseMeta, resolveDep, useServerFilter, useServerPipe };
132
+ declare const MERGE_SYMBOL = "__PS_MERGE__";
133
+ declare const UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
134
+ declare const MODULE_SYMBOL = "__PS_MODULE__";
135
+ declare const META_SYMBOL = "__PS_META__";
136
+ declare const APP_SYMBOL = "__PS__";
137
+
138
+ declare class Dev {
139
+ [UNMOUNT_SYMBOL]: (() => void)[];
140
+ onUnmount(cb: () => void): void;
141
+ }
142
+
143
+ declare abstract class PFilter {
144
+ constructor();
145
+ abstract use<C, S, E extends Exception>(error: Error | E, tag?: string, ctx?: C): S;
146
+ }
147
+
148
+ declare abstract class PGuard {
149
+ abstract use<C>(tag: string, ctx: C): Promise<boolean> | boolean;
150
+ constructor(tag: string);
151
+ }
152
+
153
+ declare abstract class PInterceptor {
154
+ abstract use<C>(tag: string, ctx: C): ((arg: any) => any) | void;
155
+ constructor(tag: string);
156
+ }
157
+
158
+ declare abstract class PPipe {
159
+ constructor(key: string);
160
+ abstract use<C>(args: {
161
+ arg: any;
162
+ option?: any;
163
+ key: string;
164
+ type: string;
165
+ index: number;
166
+ reflect: any;
167
+ }, tag: string, ctx: C): Promise<any>;
168
+ }
169
+
170
+ declare function generateRPCCode(meta: P.Meta[]): string;
171
+
172
+ declare function generateHTTPCode(meta: P.Meta[]): string;
173
+
174
+ export { APP_SYMBOL, Arg, BadGatewayException, BadRequestException, BaseParam, Body, ConflictException, Context, Controller, Define, Delete, Dev, Event, Exception, ForbiddenException, FrameworkException, Get, Guard, Head, Header, Interceptor, InvalidInputException, MERGE_SYMBOL, META_SYMBOL, MODULE_SYMBOL, Middle, NotFoundException, P, PFilter, PGuard, PInterceptor, PPipe, Param, Patch, PayloadLargeException, Pipe, Post, Put, Query, Route, Rpc, ServiceUnavailableException, TimeoutException, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, addPipe, defaultPipe, generateHTTPCode, generateRPCCode, guardsRecord, resolveDep, setFilter };