phecda-server 3.0.3 → 3.2.0-alpha.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/bin/cli.js +29 -8
- package/dist/index.d.ts +36 -20
- package/dist/index.js +223 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +222 -144
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -2
- package/register/compile.mjs +29 -0
- package/register/index.mjs +29 -0
- package/register/loader.mjs +145 -0
package/bin/cli.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
const { exec } = require('child_process')
|
|
2
|
+
const pc = require('picocolors')
|
|
3
|
+
const cmd = process.argv.slice(2)[0]
|
|
4
|
+
let child
|
|
5
|
+
function startChild() {
|
|
6
|
+
child = exec(`node --import phecda-server/register ${cmd}`, {
|
|
7
|
+
env: process.env,
|
|
8
|
+
// cwd: process.cwd(),
|
|
9
|
+
})
|
|
10
|
+
child.stderr.pipe(process.stderr)
|
|
11
|
+
child.stdin.pipe(process.stdin)
|
|
12
|
+
child.stdout.pipe(process.stdout)
|
|
4
13
|
|
|
5
|
-
|
|
6
|
-
|
|
14
|
+
child.on('exit', (code) => {
|
|
15
|
+
if (code === 3) {
|
|
16
|
+
log('relunch...')
|
|
17
|
+
return startChild()
|
|
18
|
+
}
|
|
7
19
|
|
|
8
|
-
|
|
9
|
-
|
|
20
|
+
process.exit(0)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
process.on('SIGINT', () => {
|
|
25
|
+
child.kill('SIGINT')
|
|
26
|
+
})
|
|
10
27
|
|
|
28
|
+
function log(msg, color = 'green') {
|
|
29
|
+
const date = new Date()
|
|
30
|
+
console.log(`${pc.gray(`${date.getHours()} ${date.getMinutes()} ${date.getSeconds()}`)} ${pc.magenta('[phecda-server]')} ${pc[color](msg)}`)
|
|
11
31
|
}
|
|
12
|
-
|
|
32
|
+
|
|
33
|
+
startChild()
|
package/dist/index.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ declare namespace P {
|
|
|
137
137
|
type: string;
|
|
138
138
|
index: number;
|
|
139
139
|
key: string;
|
|
140
|
-
|
|
140
|
+
option?: any;
|
|
141
141
|
}[];
|
|
142
142
|
guards: string[];
|
|
143
143
|
interceptors: string[];
|
|
@@ -149,12 +149,16 @@ declare namespace P {
|
|
|
149
149
|
interface Pipe {
|
|
150
150
|
transform(args: {
|
|
151
151
|
arg: any;
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
option?: any;
|
|
153
|
+
key: string;
|
|
154
|
+
type: string;
|
|
155
|
+
index: number;
|
|
156
|
+
reflect: any;
|
|
157
|
+
}[], tag: string, ctx: ServerCtx | ServerMergeCtx): Promise<any[]>;
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
declare class
|
|
161
|
+
declare class Histroy {
|
|
158
162
|
guard: string[];
|
|
159
163
|
interceptor: string[];
|
|
160
164
|
record(name: string, type: 'guard' | 'interceptor'): boolean;
|
|
@@ -167,11 +171,10 @@ declare abstract class Context<Data = any> {
|
|
|
167
171
|
params: string[];
|
|
168
172
|
static metaRecord: Record<string, Meta>;
|
|
169
173
|
static metaDataRecord: Record<string, ReturnType<typeof parseMeta>>;
|
|
170
|
-
static instanceRecord: Record<string, any>;
|
|
171
174
|
static guardsRecord: Record<string, any>;
|
|
172
175
|
static interceptorsRecord: Record<string, any>;
|
|
173
176
|
post: ((...params: any) => any)[];
|
|
174
|
-
history:
|
|
177
|
+
history: Histroy;
|
|
175
178
|
constructor(key: string, data: Data);
|
|
176
179
|
static registerGuard(key: string, handler: any): void;
|
|
177
180
|
static registerInterceptor(key: string, handler: any): void;
|
|
@@ -181,7 +184,6 @@ declare abstract class Context<Data = any> {
|
|
|
181
184
|
}
|
|
182
185
|
declare function addGuard(key: string, handler: P.Guard): void;
|
|
183
186
|
declare function addInterceptor(key: string, handler: P.Interceptor): void;
|
|
184
|
-
declare function getInstance(tag: string): any;
|
|
185
187
|
declare function parseMeta(meta: Meta): {
|
|
186
188
|
guards: string[];
|
|
187
189
|
reflect: any[];
|
|
@@ -190,20 +192,25 @@ declare function parseMeta(meta: Meta): {
|
|
|
190
192
|
handlers: P.Handler[];
|
|
191
193
|
params: {
|
|
192
194
|
type: string;
|
|
195
|
+
index: number;
|
|
193
196
|
key: string;
|
|
194
|
-
|
|
197
|
+
option?: any;
|
|
195
198
|
}[];
|
|
196
199
|
};
|
|
197
200
|
|
|
198
201
|
declare class ServerContext extends Context<ServerCtx | ServerMergeCtx> {
|
|
199
202
|
static pipe: P.Pipe;
|
|
200
|
-
static filter: ServerFilter
|
|
203
|
+
static filter: ServerFilter;
|
|
201
204
|
static middlewareRecord: Record<string, (...params: any) => any>;
|
|
202
205
|
static useMiddleware(middlewares: string[]): ((...params: any) => any)[];
|
|
203
206
|
usePipe(args: {
|
|
204
207
|
arg: any;
|
|
205
|
-
|
|
206
|
-
|
|
208
|
+
option?: any;
|
|
209
|
+
type: string;
|
|
210
|
+
key: string;
|
|
211
|
+
index: number;
|
|
212
|
+
reflect: any;
|
|
213
|
+
}[], tag: string): Promise<any[]>;
|
|
207
214
|
static useFilter(arg: any, data: ServerCtx | ServerMergeCtx): any;
|
|
208
215
|
useFilter(arg: any): any;
|
|
209
216
|
}
|
|
@@ -211,23 +218,35 @@ declare function addMiddleware(key: string, handler: RequestHandler): void;
|
|
|
211
218
|
declare function useServerPipe(pipe: P.Pipe): void;
|
|
212
219
|
declare function useServerFilter(filter: ServerFilter): void;
|
|
213
220
|
|
|
221
|
+
declare const SERIES_SYMBOL = "__symbol_series__";
|
|
222
|
+
declare const MERGE_SYMBOL = "__symbol_req__";
|
|
223
|
+
declare const UNMOUNT_SYMBOL = "__symbol_unmount__";
|
|
224
|
+
|
|
214
225
|
declare const emitter: Emitter;
|
|
215
|
-
declare
|
|
216
|
-
|
|
226
|
+
declare function Factory(Modules: (new (...args: any) => any)[], opts?: {
|
|
227
|
+
dev?: boolean;
|
|
228
|
+
file?: string;
|
|
229
|
+
}): Promise<{
|
|
217
230
|
moduleMap: Map<string, any>;
|
|
218
231
|
meta: Meta[];
|
|
219
|
-
|
|
232
|
+
constructorMap: Map<any, any>;
|
|
233
|
+
update: (Module: Construct) => Promise<void>;
|
|
220
234
|
}>;
|
|
235
|
+
declare class Dev {
|
|
236
|
+
[UNMOUNT_SYMBOL]: (() => void)[];
|
|
237
|
+
onUnmount(cb: () => void): void;
|
|
238
|
+
}
|
|
221
239
|
|
|
222
240
|
interface Options {
|
|
241
|
+
dev?: boolean;
|
|
223
242
|
route?: string;
|
|
224
243
|
globalGuards?: string[];
|
|
225
244
|
globalInterceptors?: string[];
|
|
226
245
|
middlewares?: string[];
|
|
227
246
|
}
|
|
228
|
-
declare function bindApp(app: Express | Router, {
|
|
247
|
+
declare function bindApp(app: Express | Router, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, options?: Options): void;
|
|
229
248
|
|
|
230
|
-
declare function BaseParam(type: string, key: string,
|
|
249
|
+
declare function BaseParam(type: string, key: string, option?: any): any;
|
|
231
250
|
declare function Body(key?: string, pipeOpts?: any): any;
|
|
232
251
|
declare function Query(key?: string, pipeOpts?: any): any;
|
|
233
252
|
declare function Param(key: string, pipeOpts?: any): any;
|
|
@@ -251,7 +270,4 @@ declare const defaultPipe: P.Pipe;
|
|
|
251
270
|
declare function isMerge(data: ServerCtx | ServerMergeCtx): data is ServerMergeCtx;
|
|
252
271
|
declare function resolveDep(ret: any, key: string): any;
|
|
253
272
|
|
|
254
|
-
|
|
255
|
-
declare const MERGE_SYMBOL = "__symbol_req__";
|
|
256
|
-
|
|
257
|
-
export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Interceptor, InvalidInputException, MERGE_SYMBOL, MergeType, Meta, Middle, NotFoundException, Options, P, Param, Patch, PayloadLargeException, Post, Put, Query, RequestType, Route, SERIES_SYMBOL, ServerContext, ServerCtx, ServerFilter, ServerMergeCtx, ServiceUnavailableException, TimeoutException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addGuard, addInterceptor, addMiddleware, bindApp, constructorMap, defaultPipe, emitter, getInstance, isMerge, parseMeta, resolveDep, useServerFilter, useServerPipe };
|
|
273
|
+
export { BadGatewayException, BadRequestException, Base, BaseError, BaseParam, Body, ConflictException, Construct, Context, Controller, Define, Delete, Dev, Emitter, Factory, ForbiddenException, FrameworkException, Get, Guard, Header, HttpException, Interceptor, InvalidInputException, MERGE_SYMBOL, MergeType, Meta, Middle, NotFoundException, Options, P, Param, Patch, PayloadLargeException, Post, Put, Query, RequestType, 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 };
|