moost 0.5.28 → 0.5.30
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.cjs +360 -116
- package/dist/index.d.ts +363 -13
- package/dist/index.mjs +342 -100
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { useEventLogger } from '@wooksjs/event-core';
|
|
|
2
2
|
export { ContextInjector, EventLogger, THook, getContextInjector, replaceContextInjector, useAsyncEventContext, useEventLogger } from '@wooksjs/event-core';
|
|
3
3
|
import { TProvideRegistry, Infact, TReplaceRegistry, TProvideFn } from '@prostojs/infact';
|
|
4
4
|
export { TProvideRegistry, createProvideRegistry, createReplaceRegistry } from '@prostojs/infact';
|
|
5
|
-
import
|
|
5
|
+
import * as _prostojs_logger from '@prostojs/logger';
|
|
6
|
+
import { TConsoleBase, TProstoLoggerOptions, ProstoLogger } from '@prostojs/logger';
|
|
6
7
|
export { ProstoLogger, TConsoleBase } from '@prostojs/logger';
|
|
7
8
|
import { Hookable } from 'hookable';
|
|
8
9
|
import * as _prostojs_mate from '@prostojs/mate';
|
|
@@ -20,17 +21,93 @@ interface TEmpty {
|
|
|
20
21
|
|
|
21
22
|
declare function Circular<T = unknown>(resolver: () => TClassConstructor<T>): ParameterDecorator;
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Apply Multiple Decorators
|
|
26
|
+
*
|
|
27
|
+
* @param decorators - array of decorators
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
declare function ApplyDecorators(...decorators: (MethodDecorator | ClassDecorator | ParameterDecorator | PropertyDecorator)[]): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
31
|
+
/**
|
|
32
|
+
* ## Label
|
|
33
|
+
* ### @Decorator
|
|
34
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
35
|
+
*
|
|
36
|
+
* Stores Label metadata
|
|
37
|
+
*/
|
|
23
38
|
declare function Label(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
39
|
+
/**
|
|
40
|
+
* ## Description
|
|
41
|
+
* ### @Decorator
|
|
42
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
43
|
+
*
|
|
44
|
+
* Stores Description metadata
|
|
45
|
+
*/
|
|
24
46
|
declare function Description(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
47
|
+
/**
|
|
48
|
+
* ## Value
|
|
49
|
+
* ### @Decorator
|
|
50
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
51
|
+
*
|
|
52
|
+
* Stores Value metadata
|
|
53
|
+
*/
|
|
25
54
|
declare function Value(value: unknown): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
55
|
+
/**
|
|
56
|
+
* ## Id
|
|
57
|
+
* ### @Decorator
|
|
58
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
59
|
+
*
|
|
60
|
+
* Stores Id metadata
|
|
61
|
+
*/
|
|
26
62
|
declare function Id(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
63
|
+
/**
|
|
64
|
+
* ## Optional
|
|
65
|
+
* ### @Decorator
|
|
66
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
67
|
+
*
|
|
68
|
+
* Stores Optional metadata
|
|
69
|
+
*/
|
|
27
70
|
declare function Optional(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
71
|
+
/**
|
|
72
|
+
* ## Required
|
|
73
|
+
* ### @Decorator
|
|
74
|
+
* _Common purpose decorator that may be used by various adapters for various purposes_
|
|
75
|
+
*
|
|
76
|
+
* Stores Required metadata
|
|
77
|
+
*/
|
|
28
78
|
declare function Required(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
29
79
|
|
|
80
|
+
/**
|
|
81
|
+
* ## Controller
|
|
82
|
+
* ### @Decorator
|
|
83
|
+
* Set Class as a Controller
|
|
84
|
+
* @param prefix - define the prefix for all the paths of this controller
|
|
85
|
+
*/
|
|
30
86
|
declare function Controller(prefix?: string): ClassDecorator;
|
|
87
|
+
/**
|
|
88
|
+
* ## ImportController
|
|
89
|
+
* ### @Decorator
|
|
90
|
+
* Attach sub-controller
|
|
91
|
+
* @param controller - target controller (instance) to import
|
|
92
|
+
* @param provide - provide registry for the target controller
|
|
93
|
+
*/
|
|
31
94
|
declare function ImportController(controller: TFunction | TObject, provide?: TProvideRegistry): ClassDecorator;
|
|
95
|
+
/**
|
|
96
|
+
* ## ImportController
|
|
97
|
+
* ### @Decorator
|
|
98
|
+
* Attach sub-controller
|
|
99
|
+
* @param prefix - redefine the prefix for all the paths of this controller
|
|
100
|
+
* @param controller - point to a controller (instance) to import
|
|
101
|
+
* @param provide - provide registry for the target controller
|
|
102
|
+
*/
|
|
32
103
|
declare function ImportController(prefix: string, controller: TFunction | TObject, provide?: TProvideRegistry): ClassDecorator;
|
|
33
104
|
|
|
105
|
+
/**
|
|
106
|
+
* ## Inherit
|
|
107
|
+
* ### @Decorator
|
|
108
|
+
* Inherit metadata from super class
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
34
111
|
declare const Inherit: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
35
112
|
|
|
36
113
|
interface TClassFunction<T extends TAnyFn = TAnyFn> {
|
|
@@ -56,6 +133,14 @@ declare enum TInterceptorPriority {
|
|
|
56
133
|
CATCH_ERROR = 5,
|
|
57
134
|
AFTER_ALL = 6
|
|
58
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* ## Intercept
|
|
138
|
+
* ### @Decorator
|
|
139
|
+
* Set interceptor
|
|
140
|
+
* @param handler interceptor fn (use defineInterceptorFn)
|
|
141
|
+
* @param priority interceptor priority
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
59
144
|
declare function Intercept(handler: TCallableClassFunction<TInterceptorFn>, priority?: TInterceptorPriority, name?: string): ClassDecorator & MethodDecorator;
|
|
60
145
|
|
|
61
146
|
type TDecoratorLevel = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
|
|
@@ -70,8 +155,23 @@ declare function getMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata
|
|
|
70
155
|
interface TCustom {
|
|
71
156
|
pipes?: TPipeData[];
|
|
72
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Define global scope name to be used with `@InjectFromScope` and `@InjectScopeVars` decorators
|
|
160
|
+
*
|
|
161
|
+
* You can read scoped vars with `getInfactScopeVars`
|
|
162
|
+
* @param name scope name
|
|
163
|
+
* @param scopeVars key-value object as scoped vars
|
|
164
|
+
*/
|
|
73
165
|
declare function defineInfactScope<T extends object>(name: string | symbol, scopeVars: T): void;
|
|
166
|
+
/**
|
|
167
|
+
* Read scoped vars defined with `defineInfactScope`
|
|
168
|
+
* @param name scope name
|
|
169
|
+
* @returns key-value object as scoped vars
|
|
170
|
+
*/
|
|
74
171
|
declare function getInfactScopeVars<T extends object>(name: string | symbol): T | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Get Infact instance (used for Dependency Injections)
|
|
174
|
+
*/
|
|
75
175
|
declare function getNewMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
|
|
76
176
|
|
|
77
177
|
interface TPipeMetas<T extends TObject = TEmpty> {
|
|
@@ -146,9 +246,9 @@ interface TInterceptorData {
|
|
|
146
246
|
priority: TInterceptorPriority;
|
|
147
247
|
name: string;
|
|
148
248
|
}
|
|
149
|
-
declare function getMoostMate<Class extends TObject = TEmpty, Prop extends TObject = TEmpty, Param extends TObject = TEmpty>(): Mate<TMoostMetadata
|
|
249
|
+
declare function getMoostMate<Class extends TObject = TEmpty, Prop extends TObject = TEmpty, Param extends TObject = TEmpty>(): Mate<TMoostMetadata & Class & {
|
|
150
250
|
params: Array<Param & TMateParamMeta>;
|
|
151
|
-
}, TMoostMetadata
|
|
251
|
+
}, TMoostMetadata & Prop & {
|
|
152
252
|
params: Array<Param & TMateParamMeta>;
|
|
153
253
|
}>;
|
|
154
254
|
interface TCommonMetaFields {
|
|
@@ -166,24 +266,119 @@ interface TCommonMoostMeta {
|
|
|
166
266
|
type?: TFunction;
|
|
167
267
|
}
|
|
168
268
|
|
|
269
|
+
/**
|
|
270
|
+
* ## Injectable
|
|
271
|
+
* ### @Decorator
|
|
272
|
+
* Mark the Class as Injectable to enable it to be used in dependency injection
|
|
273
|
+
* @param scope - Scope for injection ("FOR_EVENT" | "SINGLETON" | true)
|
|
274
|
+
* FOR_EVENT - will create a new instance for each incoming request
|
|
275
|
+
* SINGLETON | true - will create a new instance only once
|
|
276
|
+
* @param label - field label
|
|
277
|
+
*/
|
|
169
278
|
declare function Injectable(scope?: true | TInjectableScope): ClassDecorator;
|
|
170
279
|
|
|
280
|
+
/**
|
|
281
|
+
* Resolves event logger from event context
|
|
282
|
+
* @param topic
|
|
283
|
+
* @returns Resolver to '@wooksjs/event-core' (EventLogger)
|
|
284
|
+
*/
|
|
171
285
|
declare function InjectEventLogger(topic?: string): ParameterDecorator & PropertyDecorator;
|
|
286
|
+
/**
|
|
287
|
+
* Resolves app-level logger
|
|
288
|
+
* @param topic - logger topic (can be overrided by @LoggerTopic)
|
|
289
|
+
* @returns
|
|
290
|
+
*/
|
|
172
291
|
declare function InjectMoostLogger(topic?: string): ParameterDecorator & PropertyDecorator;
|
|
292
|
+
/**
|
|
293
|
+
* Sets logger topic (used in @InjectMoostLogger)
|
|
294
|
+
* @param topic - logger topic (banner)
|
|
295
|
+
* @returns
|
|
296
|
+
*/
|
|
173
297
|
declare function LoggerTopic(topic: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
174
298
|
|
|
299
|
+
/**
|
|
300
|
+
* ## Pipe
|
|
301
|
+
* ### @Decorator
|
|
302
|
+
* Attach pipe
|
|
303
|
+
* @param handler pipe handler
|
|
304
|
+
* @param priority pipe priority
|
|
305
|
+
* @returns
|
|
306
|
+
*/
|
|
175
307
|
declare function Pipe(handler: TPipeFn, priority?: TPipePriority): ClassDecorator & MethodDecorator & ParameterDecorator;
|
|
176
308
|
|
|
309
|
+
/**
|
|
310
|
+
* ## Provide
|
|
311
|
+
* ### @Decorator
|
|
312
|
+
* Defines provide registry for class (and all the children)
|
|
313
|
+
* @param type - string or class constructor
|
|
314
|
+
* @param fn - factory function for provided value
|
|
315
|
+
*/
|
|
177
316
|
declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
317
|
+
/**
|
|
318
|
+
* ## Replace
|
|
319
|
+
* ### @Decorator
|
|
320
|
+
* Defines class to replace in DI
|
|
321
|
+
* @param type - class to replace
|
|
322
|
+
* @param newType - new class
|
|
323
|
+
*/
|
|
178
324
|
declare function Replace(type: TClassConstructor, newType: TClassConstructor): ClassDecorator;
|
|
325
|
+
/**
|
|
326
|
+
* ## Inject
|
|
327
|
+
* ### @Decorator
|
|
328
|
+
* Defines a key from provide registry to inject value
|
|
329
|
+
* (For optional values use with @Optional())
|
|
330
|
+
* @param type - string or class constructor
|
|
331
|
+
*/
|
|
179
332
|
declare function Inject(type: string | TClassConstructor): ParameterDecorator & PropertyDecorator;
|
|
333
|
+
/**
|
|
334
|
+
* Injects instance from scope
|
|
335
|
+
*
|
|
336
|
+
* (scope must be defined by `defineInfactScope` fn)
|
|
337
|
+
* @param name scope name
|
|
338
|
+
*/
|
|
180
339
|
declare function InjectFromScope(name: string | symbol): ParameterDecorator & PropertyDecorator;
|
|
340
|
+
/**
|
|
341
|
+
* Inject vars from scope for instances
|
|
342
|
+
* instantiated with `@InjectFromScope` decorator
|
|
343
|
+
*/
|
|
181
344
|
declare function InjectScopeVars(name?: string): ParameterDecorator & PropertyDecorator;
|
|
182
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Hook to the Response Status
|
|
348
|
+
* @decorator
|
|
349
|
+
* @param resolver - resolver function
|
|
350
|
+
* @param label - field label
|
|
351
|
+
* @paramType unknown
|
|
352
|
+
*/
|
|
183
353
|
declare function Resolve<T extends TObject = TEmpty>(resolver: (metas: TPipeMetas<T>, level: TDecoratorLevel) => unknown, label?: string): ParameterDecorator & PropertyDecorator;
|
|
354
|
+
/**
|
|
355
|
+
* Get Param Value from url parh
|
|
356
|
+
* @decorator
|
|
357
|
+
* @param name - param name
|
|
358
|
+
* @paramType string
|
|
359
|
+
*/
|
|
184
360
|
declare function Param(name: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
|
|
361
|
+
/**
|
|
362
|
+
* Get Parsed Params from url parh
|
|
363
|
+
* @decorator
|
|
364
|
+
* @paramType object
|
|
365
|
+
*/
|
|
185
366
|
declare function Params(): ParameterDecorator & PropertyDecorator;
|
|
367
|
+
/**
|
|
368
|
+
* Provide Const Value
|
|
369
|
+
* @decorator
|
|
370
|
+
* @param value - provided value
|
|
371
|
+
* @param label - label of the field
|
|
372
|
+
* @paramType unknown
|
|
373
|
+
*/
|
|
186
374
|
declare function Const<T>(value: T, label?: string): ParameterDecorator & PropertyDecorator;
|
|
375
|
+
/**
|
|
376
|
+
* Provide Const Value from Factory fn
|
|
377
|
+
* @decorator
|
|
378
|
+
* @param factory - value Factory fn
|
|
379
|
+
* @param label - label of the field
|
|
380
|
+
* @paramType unknown
|
|
381
|
+
*/
|
|
187
382
|
declare function ConstFactory<T>(factory: () => T | Promise<T>, label?: string): ParameterDecorator & PropertyDecorator;
|
|
188
383
|
|
|
189
384
|
declare class InterceptorHandler {
|
|
@@ -271,9 +466,62 @@ interface THandlerOverview {
|
|
|
271
466
|
type TContextInjectorHook = 'Event:start' | 'Interceptors:init' | 'Arguments:resolve' | 'Interceptors:before' | 'Handler' | 'Interceptors:after';
|
|
272
467
|
|
|
273
468
|
interface TMoostOptions {
|
|
469
|
+
/**
|
|
470
|
+
* Prefix that is used for each event path
|
|
471
|
+
*/
|
|
274
472
|
globalPrefix?: string;
|
|
275
473
|
logger?: TConsoleBase;
|
|
276
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* ## Moost
|
|
477
|
+
* Main moostjs class that serves as a shell for Moost Adapters
|
|
478
|
+
*
|
|
479
|
+
* ### Usage with HTTP Adapter
|
|
480
|
+
* ```ts
|
|
481
|
+
* │ // HTTP server example
|
|
482
|
+
* │ import { MoostHttp, Get } from '@moostjs/event-http'
|
|
483
|
+
* │ import { Moost, Param } from 'moost'
|
|
484
|
+
* │
|
|
485
|
+
* │ class MyServer extends Moost {
|
|
486
|
+
* │ @Get('test/:name')
|
|
487
|
+
* │ test(@Param('name') name: string) {
|
|
488
|
+
* │ return { message: `Hello ${name}!` }
|
|
489
|
+
* │ }
|
|
490
|
+
* │ }
|
|
491
|
+
* │
|
|
492
|
+
* │ const app = new MyServer()
|
|
493
|
+
* │ const http = new MoostHttp()
|
|
494
|
+
* │ app.adapter(http).listen(3000, () => {
|
|
495
|
+
* │ app.getLogger('MyApp').log('Up on port 3000')
|
|
496
|
+
* │ })
|
|
497
|
+
* │ app.init()
|
|
498
|
+
* ```
|
|
499
|
+
* ### Usage with CLI Adapter
|
|
500
|
+
* ```ts
|
|
501
|
+
* │ // CLI example
|
|
502
|
+
* │ import { MoostCli, Cli, CliOption, cliHelpInterceptor } from '@moostjs/event-cli'
|
|
503
|
+
* │ import { Moost, Param } from 'moost'
|
|
504
|
+
* │
|
|
505
|
+
* │ class MyApp extends Moost {
|
|
506
|
+
* │ @Cli('command/:arg')
|
|
507
|
+
* │ command(
|
|
508
|
+
* │ @Param('arg')
|
|
509
|
+
* │ arg: string,
|
|
510
|
+
* │ @CliOption('test', 't')
|
|
511
|
+
* │ test: boolean,
|
|
512
|
+
* │ ) {
|
|
513
|
+
* │ return `command run with flag arg=${ arg }, test=${ test }`
|
|
514
|
+
* │ }
|
|
515
|
+
* │ }
|
|
516
|
+
* │
|
|
517
|
+
* │ const app = new MyApp()
|
|
518
|
+
* │ app.applyGlobalInterceptors(cliHelpInterceptor())
|
|
519
|
+
* │
|
|
520
|
+
* │ const cli = new MoostCli()
|
|
521
|
+
* │ app.adapter(cli)
|
|
522
|
+
* │ app.init()
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
277
525
|
declare class Moost extends Hookable {
|
|
278
526
|
protected options?: TMoostOptions | undefined;
|
|
279
527
|
protected logger: TConsoleBase;
|
|
@@ -287,18 +535,54 @@ declare class Moost extends Hookable {
|
|
|
287
535
|
constructor(options?: TMoostOptions | undefined);
|
|
288
536
|
_fireEventStart(source: TMoostAdapter<unknown>): void;
|
|
289
537
|
_fireEventEnd(source: TMoostAdapter<unknown>): void;
|
|
538
|
+
/**
|
|
539
|
+
* ### getLogger
|
|
540
|
+
* Provides application logger
|
|
541
|
+
* ```js
|
|
542
|
+
* // get logger with topic = "App"
|
|
543
|
+
* const logger = app.getLogger('App')
|
|
544
|
+
* logger.log('...')
|
|
545
|
+
* ```
|
|
546
|
+
* @param topic
|
|
547
|
+
* @returns
|
|
548
|
+
*/
|
|
290
549
|
getLogger(topic?: string): TConsoleBase;
|
|
291
550
|
adapter<T extends TMoostAdapter<TAny>>(a: T): T;
|
|
292
551
|
getControllersOverview(): TControllerOverview[];
|
|
552
|
+
/**
|
|
553
|
+
* ### init
|
|
554
|
+
* Ititializes adapter. Must be called after adapters are attached.
|
|
555
|
+
*/
|
|
293
556
|
init(): Promise<void>;
|
|
294
557
|
protected bindControllers(): Promise<void>;
|
|
295
558
|
protected bindController(controller: TFunction | TObject, provide: TProvideRegistry, replace: TReplaceRegistry, globalPrefix: string, replaceOwnPrefix?: string): Promise<void>;
|
|
296
559
|
applyGlobalPipes(...items: Array<TPipeFn | TPipeData>): this;
|
|
297
560
|
protected globalInterceptorHandler?: () => Promise<InterceptorHandler>;
|
|
561
|
+
/**
|
|
562
|
+
* Provides InterceptorHandler with global interceptors and pipes.
|
|
563
|
+
* Used to process interceptors when event handler was not found.
|
|
564
|
+
*
|
|
565
|
+
* @returns IterceptorHandler
|
|
566
|
+
*/
|
|
298
567
|
getGlobalInterceptorHandler(): Promise<InterceptorHandler>;
|
|
299
568
|
applyGlobalInterceptors(...items: Array<TInterceptorData['handler'] | TInterceptorData>): this;
|
|
569
|
+
/**
|
|
570
|
+
* Register new entries to provide as dependency injections
|
|
571
|
+
* @param provide - Provide Registry (use createProvideRegistry from '\@prostojs/infact')
|
|
572
|
+
* @returns
|
|
573
|
+
*/
|
|
300
574
|
setProvideRegistry(provide: TProvideRegistry): this;
|
|
575
|
+
/**
|
|
576
|
+
* Register replace classes to provide as dependency injections
|
|
577
|
+
* @param replace - Replace Registry (use createReplaceRegistry from '\@prostojs/infact')
|
|
578
|
+
* @returns
|
|
579
|
+
*/
|
|
301
580
|
setReplaceRegistry(replace: TReplaceRegistry): this;
|
|
581
|
+
/**
|
|
582
|
+
* Register controllers (similar to @ImportController decorator)
|
|
583
|
+
* @param controllers - list of target controllers (instances)
|
|
584
|
+
* @returns
|
|
585
|
+
*/
|
|
302
586
|
registerControllers(...controllers: Array<TObject | TFunction | [string, TObject | TFunction]>): this;
|
|
303
587
|
logMappedHandler(eventName: string, classConstructor: Function, method: string, stroke?: boolean, prefix?: string): void;
|
|
304
588
|
}
|
|
@@ -326,17 +610,17 @@ declare function useControllerContext<T extends object>(): {
|
|
|
326
610
|
getRoute: () => string | undefined;
|
|
327
611
|
getController: () => T;
|
|
328
612
|
getMethod: () => string | undefined;
|
|
329
|
-
getControllerMeta: <
|
|
330
|
-
params: (
|
|
613
|
+
getControllerMeta: <TT extends object>() => (TMoostMetadata<TEmpty> & TT & {
|
|
614
|
+
params: (TT & _prostojs_mate.TMateParamMeta)[];
|
|
331
615
|
}) | undefined;
|
|
332
|
-
getMethodMeta: <
|
|
333
|
-
params: (
|
|
616
|
+
getMethodMeta: <TT extends object>(name?: string) => (TMoostMetadata<TEmpty> & TT & {
|
|
617
|
+
params: (TT & _prostojs_mate.TMateParamMeta)[];
|
|
334
618
|
} & {
|
|
335
|
-
params: (
|
|
336
|
-
} & _prostojs_mate.TMateClassMeta<(TMoostMetadata<TEmpty> &
|
|
337
|
-
params: (
|
|
338
|
-
})["params"][0]> & _prostojs_mate.TMatePropMeta<(TMoostMetadata<TEmpty> &
|
|
339
|
-
params: (
|
|
619
|
+
params: (TT & _prostojs_mate.TMateParamMeta)[];
|
|
620
|
+
} & _prostojs_mate.TMateClassMeta<(TMoostMetadata<TEmpty> & TT & {
|
|
621
|
+
params: (TT & _prostojs_mate.TMateParamMeta)[];
|
|
622
|
+
})["params"][0]> & _prostojs_mate.TMatePropMeta<(TMoostMetadata<TEmpty> & TT & {
|
|
623
|
+
params: (TT & _prostojs_mate.TMateParamMeta)[];
|
|
340
624
|
})["params"][0]>) | undefined;
|
|
341
625
|
getPropertiesList: () => (string | symbol)[];
|
|
342
626
|
getScope: () => true | TInjectableScope;
|
|
@@ -348,8 +632,74 @@ declare function useControllerContext<T extends object>(): {
|
|
|
348
632
|
} & _prostojs_mate.TMateClassMeta<_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & object> & _prostojs_mate.TMatePropMeta<_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & object>) | undefined;
|
|
349
633
|
};
|
|
350
634
|
|
|
635
|
+
/**
|
|
636
|
+
* ### Define Interceptor Function
|
|
637
|
+
*
|
|
638
|
+
* ```ts
|
|
639
|
+
* defineInterceptorFn((before, after, onError) => {
|
|
640
|
+
* //init
|
|
641
|
+
* before(() => {
|
|
642
|
+
* // before handler
|
|
643
|
+
* })
|
|
644
|
+
* after((response, reply) => {
|
|
645
|
+
* // after handler
|
|
646
|
+
* })
|
|
647
|
+
* onError((error, reply) => {
|
|
648
|
+
* // when error occured
|
|
649
|
+
* })
|
|
650
|
+
* },
|
|
651
|
+
* TInterceptorPriority.INTERCEPTOR,
|
|
652
|
+
* )
|
|
653
|
+
* ```
|
|
654
|
+
*
|
|
655
|
+
* @param fn interceptor function
|
|
656
|
+
* @param priority priority of the interceptor where BEFORE_ALL = 0, BEFORE_GUARD = 1, GUARD = 2, AFTER_GUARD = 3, INTERCEPTOR = 4, CATCH_ERROR = 5, AFTER_ALL = 6
|
|
657
|
+
* @returns
|
|
658
|
+
*/
|
|
351
659
|
declare function defineInterceptorFn(fn: TInterceptorFn, priority?: TInterceptorPriority): TInterceptorFn;
|
|
660
|
+
/**
|
|
661
|
+
* Class based interceptor interface
|
|
662
|
+
*
|
|
663
|
+
* Use it to create class-based interceptors and don't forget to make it **@Injectable()**
|
|
664
|
+
*
|
|
665
|
+
* @example
|
|
666
|
+
* "@Injectable()
|
|
667
|
+
* export class MyInterceptor implements TInterceptorClass {
|
|
668
|
+
* static priority = TInterceptorPriority.INTERCEPTOR
|
|
669
|
+
* handler: TInterceptorClass['handler'] = (before, after, onError) => {
|
|
670
|
+
* before((reply) => {
|
|
671
|
+
* console.log('before')
|
|
672
|
+
* })
|
|
673
|
+
* after((response, reply) => {
|
|
674
|
+
* console.log('after')
|
|
675
|
+
* })
|
|
676
|
+
* onError((error, reply) => {
|
|
677
|
+
* console.log('error')
|
|
678
|
+
* })
|
|
679
|
+
* }
|
|
680
|
+
* }
|
|
681
|
+
*/
|
|
352
682
|
type TInterceptorClass = TClassFunction<TInterceptorFn>;
|
|
683
|
+
/**
|
|
684
|
+
* ### Define Pipe Function
|
|
685
|
+
*
|
|
686
|
+
* ```ts
|
|
687
|
+
* // example of a transform pipe
|
|
688
|
+
* const uppercaseTransformPipe = definePipeFn((value, metas, level) => {
|
|
689
|
+
* return typeof value === 'string' ? value.toUpperCase() : value
|
|
690
|
+
* },
|
|
691
|
+
* TPipePriority.TRANSFORM,
|
|
692
|
+
* )
|
|
693
|
+
* ```
|
|
694
|
+
*
|
|
695
|
+
* @param fn interceptor function
|
|
696
|
+
* @param priority priority of the pipe where BEFORE_RESOLVE = 0, RESOLVE = 1, AFTER_RESOLVE = 2, BEFORE_TRANSFORM = 3, TRANSFORM = 4, AFTER_TRANSFORM = 5, BEFORE_VALIDATE = 6, VALIDATE = 7, AFTER_VALIDATE = 8
|
|
697
|
+
* @returns
|
|
698
|
+
*/
|
|
353
699
|
declare function definePipeFn<T extends TObject = TEmpty>(fn: TPipeFn<T>, priority?: TPipePriority): TPipeFn<T>;
|
|
354
700
|
|
|
355
|
-
|
|
701
|
+
declare function createLogger(opts?: Partial<TProstoLoggerOptions>): ProstoLogger;
|
|
702
|
+
declare const loggerConsoleTransport: _prostojs_logger.TProstoLoggerTransportFn<any>;
|
|
703
|
+
|
|
704
|
+
export { ApplyDecorators, Circular, Const, ConstFactory, Controller, Description, Id, ImportController, Inherit, Inject, InjectEventLogger, InjectFromScope, InjectMoostLogger, InjectScopeVars, Injectable, Intercept, InterceptorHandler, Label, LoggerTopic, Moost, Optional, Param, Params, Pipe, Provide, Replace, Required, Resolve, TInterceptorPriority, TPipePriority, Value, createLogger, defineInfactScope, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getInfactScopeVars, getInstanceOwnMethods, getInstanceOwnProps, getMoostInfact, getMoostMate, getNewMoostInfact, loggerConsoleTransport, registerEventScope, resolvePipe, setControllerContext, setInfactLoggingOptions, useControllerContext };
|
|
705
|
+
export type { TCallableClassFunction, TClassConstructor, TClassFunction, TContextInjectorHook, TControllerOverview, TInjectableScope, TInterceptorAfter, TInterceptorBefore, TInterceptorClass, TInterceptorData, TInterceptorFn, TInterceptorOnError, TMoostAdapter, TMoostAdapterOptions, TMoostEventHandlerHookOptions, TMoostEventHandlerOptions, TMoostHandler, TMoostMetadata, TMoostOptions, TMoostParamsMetadata, TPipeData, TPipeFn, TPipeMetas };
|