phecda-server 4.0.0-alpha.6 → 4.0.0-alpha.8

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-0b94277f.js';
2
+
3
+ declare class Meta {
4
+ data: P.Meta;
5
+ handlers: P.Handler[];
6
+ reflect: any[];
7
+ constructor(data: P.Meta, handlers: P.Handler[], reflect: 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-2c710fc7.js';
3
- export { c as Base, B as BaseError, C as Construct, b as Emitter, M as MergeType, d as Meta, R as RequestType, T as ToInstance } from './types-2c710fc7.js';
4
- import { B as BaseContext, F as Factory } from './core-c289deb2.js';
5
- export { e as emitter } from './core-c289deb2.js';
1
+ import { E as Exception, P } from './types-0b94277f.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-0b94277f.js';
3
+ export { F as Factory, M as Meta, e as emitter } from './core-edac98be.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,40 +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
- dev?: boolean;
90
- route?: string;
91
- globalGuards?: string[];
92
- globalInterceptors?: string[];
93
- middlewares?: string[];
94
- parallel?: boolean;
95
- series?: boolean;
96
- }
97
- 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;
98
101
 
99
102
  declare function BaseParam(type: string, key: string, option?: any): any;
100
103
  declare function Body(key?: string, pipeOpts?: any): any;
@@ -110,7 +113,7 @@ declare function Put(route: string): any;
110
113
  declare function Patch(route: string): any;
111
114
  declare function Delete(route: string): any;
112
115
  declare function Controller(route: string): any;
113
- declare function Rpc(...rpc: string[]): (target: any, key: PropertyKey) => void;
116
+ declare function Rpc(...rpc: ('mq' | 'redis' | string)[]): (target: any, key: PropertyKey) => void;
114
117
 
115
118
  declare function Guard(...guards: string[]): any;
116
119
  declare function Middle(...middlewares: string[]): any;
@@ -135,35 +138,35 @@ declare class Dev {
135
138
  onUnmount(cb: () => void): void;
136
139
  }
137
140
 
138
- declare abstract class ServerGuard {
139
- abstract use(tag: string, ctx: ServerCtx): Promise<boolean> | boolean;
141
+ declare abstract class PFilter {
142
+ constructor();
143
+ abstract use<C, S, E extends Exception>(error: Error | E, tag?: string, ctx?: C): S;
144
+ }
145
+
146
+ declare abstract class PGuard {
147
+ abstract use<C>(tag: string, ctx: C): Promise<boolean> | boolean;
140
148
  constructor(tag: string);
141
149
  }
142
150
 
143
- declare abstract class ServerInterceptor {
144
- abstract use(tag: string, ctx: ServerCtx): ((arg: any) => any) | void;
151
+ declare abstract class PInterceptor {
152
+ abstract use<C>(tag: string, ctx: C): ((arg: any) => any) | void;
145
153
  constructor(tag: string);
146
154
  }
147
155
 
148
- declare abstract class ServerPipe {
156
+ declare abstract class PPipe {
149
157
  constructor();
150
- abstract use(args: {
158
+ abstract use<C>(args: {
151
159
  arg: any;
152
160
  option?: any;
153
161
  key: string;
154
162
  type: string;
155
163
  index: number;
156
164
  reflect: any;
157
- }[], tag: string, ctx: ServerCtx): Promise<any[]>;
158
- }
159
-
160
- declare abstract class ServerFilter {
161
- constructor();
162
- abstract use<E extends Exception>(error: Error | E, tag?: string, ctx?: ServerCtx): ServerErr | Promise<ServerErr>;
165
+ }[], tag: string, ctx: C): Promise<any[]>;
163
166
  }
164
167
 
165
168
  declare function generateRPCCode(meta: P.Meta[]): string;
166
169
 
167
170
  declare function generateHTTPCode(meta: P.Meta[]): string;
168
171
 
169
- 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 };
172
+ export { APP_SYMBOL, Arg, BadGatewayException, BadRequestException, BaseParam, Body, ConflictException, Context, Controller, Define, Delete, Dev, 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 };