phecda-server 4.0.0-alpha.7 → 4.0.0-alpha.9

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.
@@ -0,0 +1,21 @@
1
+ import { P, a as Emitter, C as Construct } from './types-754ec28e.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,10 +1,14 @@
1
- import { RequestHandler, Router } from 'express';
2
- import { E as Exception, P, S as ServerCtx, a as ServerErr } from './types-ff44d472.js';
3
- export { B as BaseError, C as Construct, b as Emitter, M as MergeType, d as Meta, R as RequestType, c as ServerBase, T as ToInstance } from './types-ff44d472.js';
4
- import { B as BaseContext, F as Factory } from './core-72b1280e.js';
5
- export { e as emitter } from './core-72b1280e.js';
1
+ import { E as Exception, P } from './types-754ec28e.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-754ec28e.js';
3
+ export { F as Factory, M as Meta, e as emitter } from './core-4ded7d17.js';
6
4
  export * from 'phecda-core';
7
5
 
6
+ declare class Histroy {
7
+ guard: string[];
8
+ interceptor: string[];
9
+ record(name: string, type: 'guard' | 'interceptor'): boolean;
10
+ }
11
+
8
12
  declare class UndefinedException extends Exception {
9
13
  constructor(message: string);
10
14
  }
@@ -61,39 +65,39 @@ declare class FrameworkException extends Exception {
61
65
  constructor(message: string);
62
66
  }
63
67
 
64
- declare const guardsRecord: Record<string, P.Guard<ServerCtx>>;
65
- declare const interceptorsRecord: Record<string, P.Interceptor<ServerCtx>>;
66
- declare const middlewareRecord: Record<string, (...params: any) => any>;
67
- declare const singletonConf: {
68
- pipe: P.Pipe<any>;
69
- filter: P.Filter<any, any, any>;
70
- };
71
- declare class Context extends BaseContext<ServerCtx> {
72
- singletonConf: {
73
- pipe: P.Pipe<any>;
74
- filter: P.Filter<any, any, any>;
75
- };
68
+ declare const guardsRecord: Record<string, P.Guard<any>>;
69
+ declare class Context<Data = any> {
70
+ tag: string;
71
+ data: Data;
72
+ method: string;
73
+ params: string[];
74
+ history: Histroy;
75
+ static filter: P.Filter;
76
+ static pipe: P.Pipe;
77
+ static guardsRecord: Record<string, P.Guard>;
78
+ static interceptorsRecord: Record<string, P.Interceptor>;
76
79
  static middlewareRecord: Record<string, (...params: any) => any>;
77
- guardsRecord: Record<string, P.Guard<ServerCtx>>;
78
- interceptorsRecord: Record<string, P.Interceptor<ServerCtx>>;
79
80
  postInterceptors: Function[];
81
+ constructor(tag: string, data: Data);
82
+ usePipe(args: {
83
+ arg: any;
84
+ option?: any;
85
+ type: string;
86
+ key: string;
87
+ index: number;
88
+ reflect: any;
89
+ }[]): Promise<any[]>;
90
+ useFilter(arg: any): any;
91
+ useGuard(guards: string[]): Promise<void>;
92
+ usePostInterceptor(ret: any): Promise<any>;
93
+ useInterceptor(interceptors: string[]): Promise<true | undefined>;
80
94
  static useMiddleware(middlewares: string[]): ((...params: any) => any)[];
81
95
  }
82
- declare function addMiddleware(key: string, handler: RequestHandler): void;
83
- declare function setPipe(pipe: P.Pipe<ServerCtx>): void;
84
- declare function setFilter(filter: P.Filter<ServerCtx, ServerErr>): void;
85
- declare function addGuard(key: string, handler: P.Guard<ServerCtx>): void;
86
- declare function addInterceptor(key: string, handler: P.Interceptor<ServerCtx>): void;
87
-
88
- interface Options {
89
- route?: string;
90
- globalGuards?: string[];
91
- globalInterceptors?: string[];
92
- middlewares?: string[];
93
- parallel?: boolean;
94
- series?: boolean;
95
- }
96
- declare function bindApp(app: Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options?: Options): void;
96
+ declare function addMiddleware(key: string, handler: (...params: any) => any): void;
97
+ declare function setPipe(pipe: P.Pipe): void;
98
+ declare function setFilter(filter: P.Filter): void;
99
+ declare function addGuard(key: string, handler: P.Guard): void;
100
+ declare function addInterceptor(key: string, handler: P.Interceptor): void;
97
101
 
98
102
  declare function BaseParam(type: string, key: string, option?: any): any;
99
103
  declare function Body(key?: string, pipeOpts?: any): any;
@@ -109,7 +113,8 @@ declare function Put(route: string): any;
109
113
  declare function Patch(route: string): any;
110
114
  declare function Delete(route: string): any;
111
115
  declare function Controller(route: string): any;
112
- declare function Rpc(...rpc: ('mq' | 'redis' | string)[]): (target: any, key: PropertyKey) => void;
116
+ declare function Rpc(...types: ('mq' | 'redis' | string)[]): (target: any, key?: PropertyKey) => void;
117
+ declare function Event(isEvent?: boolean): (target: any, key?: PropertyKey) => void;
113
118
 
114
119
  declare function Guard(...guards: string[]): any;
115
120
  declare function Middle(...middlewares: string[]): any;
@@ -134,35 +139,35 @@ declare class Dev {
134
139
  onUnmount(cb: () => void): void;
135
140
  }
136
141
 
137
- declare abstract class ServerGuard {
138
- abstract use(tag: string, ctx: ServerCtx): Promise<boolean> | boolean;
142
+ declare abstract class PFilter {
143
+ constructor();
144
+ abstract use<C, S, E extends Exception>(error: Error | E, tag?: string, ctx?: C): S;
145
+ }
146
+
147
+ declare abstract class PGuard {
148
+ abstract use<C>(tag: string, ctx: C): Promise<boolean> | boolean;
139
149
  constructor(tag: string);
140
150
  }
141
151
 
142
- declare abstract class ServerInterceptor {
143
- abstract use(tag: string, ctx: ServerCtx): ((arg: any) => any) | void;
152
+ declare abstract class PInterceptor {
153
+ abstract use<C>(tag: string, ctx: C): ((arg: any) => any) | void;
144
154
  constructor(tag: string);
145
155
  }
146
156
 
147
- declare abstract class ServerPipe {
157
+ declare abstract class PPipe {
148
158
  constructor();
149
- abstract use(args: {
159
+ abstract use<C>(args: {
150
160
  arg: any;
151
161
  option?: any;
152
162
  key: string;
153
163
  type: string;
154
164
  index: number;
155
165
  reflect: any;
156
- }[], tag: string, ctx: ServerCtx): Promise<any[]>;
157
- }
158
-
159
- declare abstract class ServerFilter {
160
- constructor();
161
- abstract use<E extends Exception>(error: Error | E, tag?: string, ctx?: ServerCtx): ServerErr | Promise<ServerErr>;
166
+ }[], tag: string, ctx: C): Promise<any[]>;
162
167
  }
163
168
 
164
169
  declare function generateRPCCode(meta: P.Meta[]): string;
165
170
 
166
171
  declare function generateHTTPCode(meta: P.Meta[]): string;
167
172
 
168
- export { APP_SYMBOL, Arg, BadGatewayException, BadRequestException, BaseContext, BaseParam, Body, ConflictException, Context, Controller, Define, Delete, Dev, Exception, Factory, ForbiddenException, FrameworkException, Get, Guard, Head, Header, Interceptor, InvalidInputException, MERGE_SYMBOL, META_SYMBOL, MODULE_SYMBOL, Middle, NotFoundException, Options, P, Param, Patch, PayloadLargeException, Post, Put, Query, Route, Rpc, SERIES_SYMBOL, ServerCtx, ServerErr, ServerFilter, ServerGuard, ServerInterceptor, ServerPipe, ServiceUnavailableException, TimeoutException, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, defaultPipe, generateHTTPCode, generateRPCCode, guardsRecord, interceptorsRecord, middlewareRecord, resolveDep, setFilter, setPipe, singletonConf };
173
+ 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, Post, Put, Query, Route, Rpc, SERIES_SYMBOL, ServiceUnavailableException, TimeoutException, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, defaultPipe, generateHTTPCode, generateRPCCode, guardsRecord, resolveDep, setFilter, setPipe };