moost 0.3.11 → 0.3.13

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.d.ts CHANGED
@@ -1,639 +1,573 @@
1
- import { createProvideRegistry } from '@prostojs/infact';
2
- import { EventLogger } from '@wooksjs/event-core';
3
- import { Infact } from '@prostojs/infact';
4
- import { Mate } from '@prostojs/mate';
5
- import { TConsoleBase } from '@prostojs/logger';
6
- import { THook } from '@wooksjs/event-core';
7
- import { TMateClassMeta } from '@prostojs/mate';
8
- import { TMateParamMeta } from '@prostojs/mate';
9
- import { TMatePropMeta } from '@prostojs/mate';
10
- import { TProvideFn } from '@prostojs/infact';
11
- import { TProvideRegistry } from '@prostojs/infact';
12
- import { useEventContext } from '@wooksjs/event-core';
13
- import { useEventLogger } from '@wooksjs/event-core';
14
-
15
- export declare function Circular<T = unknown>(resolver: () => TClassConstructor<T>): ParameterDecorator;
16
-
17
- /**
18
- * Provide Const Value
19
- * @decorator
20
- * @param value - provided value
21
- * @param label - label of the field
22
- * @paramType unknown
23
- */
24
- export declare function Const<T>(value: T, label?: string): ParameterDecorator & PropertyDecorator;
25
-
26
- /**
27
- * Provide Const Value from Factory fn
28
- * @decorator
29
- * @param factory - value Factory fn
30
- * @param label - label of the field
31
- * @paramType unknown
32
- */
33
- export declare function ConstFactory<T>(factory: () => T | Promise<T>, label?: string): ParameterDecorator & PropertyDecorator;
34
-
35
- /**
36
- * ## Controller
37
- * ### @Decorator
38
- * Set Class as a Controller
39
- * @param prefix - define the prefix for all the paths of this controller
40
- */
41
- export declare function Controller(prefix?: string): ClassDecorator;
42
-
43
- export { createProvideRegistry }
44
-
45
- /**
46
- * ### Define Interceptor Function
47
- *
48
- * ```ts
49
- * defineInterceptorFn((before, after, onError) => {
50
- * //init
51
- * before(() => {
52
- * // before handler
53
- * })
54
- * after((response, reply) => {
55
- * // after handler
56
- * })
57
- * onError((error, reply) => {
58
- * // when error occured
59
- * })
60
- * },
61
- * TInterceptorPriority.INTERCEPTOR,
62
- * )
63
- * ```
64
- *
65
- * @param fn interceptor function
66
- * @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
67
- * @returns
68
- */
69
- export declare function defineInterceptorFn(fn: TInterceptorFn, priority?: TInterceptorPriority): TInterceptorFn;
70
-
71
- export declare function defineMoostEventHandler<T>(options: TMoostEventHandlerOptions<T>): () => Promise<unknown>;
72
-
73
- /**
74
- * ### Define Pipe Function
75
- *
76
- * ```ts
77
- * // example of a transform pipe
78
- * const uppercaseTransformPipe = definePipeFn((value, metas, level) => {
79
- * return typeof value === 'string' ? value.toUpperCase() : value
80
- * },
81
- * TPipePriority.TRANSFORM,
82
- * )
83
- * ```
84
- *
85
- * @param fn interceptor function
86
- * @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
87
- * @returns
88
- */
89
- export declare function definePipeFn<T extends TObject = TEmpty>(fn: TPipeFn<T>, priority?: TPipePriority): TPipeFn<T>;
90
-
91
- /**
92
- * ## Description
93
- * ### @Decorator
94
- * _Common purpose decorator that may be used by various adapters for various purposes_
95
- *
96
- * Stores Description metadata
97
- */
98
- export declare function Description(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
99
-
100
- export { EventLogger }
101
-
102
- export declare function getMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
103
-
104
- export declare function getMoostMate<Class extends TObject = TEmpty, Prop extends TObject = TEmpty, Param extends TObject = TEmpty>(): Mate<TMoostMetadata<TEmpty> & Class & {
105
- params: (Param & TMateParamMeta)[];
106
- }, TMoostMetadata<TEmpty> & Prop & {
107
- params: (Param & TMateParamMeta)[];
108
- }>;
109
-
110
- export declare function getNewMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
111
-
112
- /**
113
- * ## Id
114
- * ### @Decorator
115
- * _Common purpose decorator that may be used by various adapters for various purposes_
116
- *
117
- * Stores Id metadata
118
- */
119
- export declare function Id(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
120
-
121
- /**
122
- * ## ImportController
123
- * ### @Decorator
124
- * Attach sub-controller
125
- * @param controller - target controller (instance) to import
126
- * @param provide - provide registry for the target controller
127
- */
128
- export declare function ImportController(controller: TFunction | TObject, provide?: TProvideRegistry): ClassDecorator;
129
-
130
- /**
131
- * ## ImportController
132
- * ### @Decorator
133
- * Attach sub-controller
134
- * @param prefix - redefine the prefix for all the paths of this controller
135
- * @param controller - point to a controller (instance) to import
136
- * @param provide - provide registry for the target controller
137
- */
138
- export declare function ImportController(prefix: string, controller: TFunction | TObject, provide?: TProvideRegistry): ClassDecorator;
139
-
140
- /**
141
- * ## Inherit
142
- * ### @Decorator
143
- * Inherit metadata from super class
144
- * @returns
145
- */
146
- export declare const Inherit: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
147
-
148
- /**
149
- * ## Inject
150
- * ### @Decorator
151
- * Defines a key from provide registry to inject value
152
- * (For optional values use with @Optional())
153
- * @param type - string or class constructor
154
- */
155
- export declare function Inject(type: string | TClassConstructor): ParameterDecorator;
156
-
157
- /**
158
- * ## Injectable
159
- * ### @Decorator
160
- * Mark the Class as Injectable to enable it to be used in dependency injection
161
- * @param scope - Scope for injection ("FOR_EVENT" | "SINGLETON" | true)
162
- * FOR_EVENT - will create a new instance for each incoming request
163
- * SINGLETON | true - will create a new instance only once
164
- * @param label - field label
165
- */
166
- export declare function Injectable(scope?: true | TInjectableScope): ClassDecorator;
167
-
168
- /**
169
- * Resolves event logger from event context
170
- * @param topic
171
- * @returns Resolver to '@wooksjs/event-core' (EventLogger)
172
- */
173
- export declare function InjectEventLogger(topic?: string): ParameterDecorator & PropertyDecorator;
174
-
175
- /**
176
- * ## Intercept
177
- * ### @Decorator
178
- * Set interceptor
179
- * @param handler interceptor fn (use defineInterceptorFn)
180
- * @param priority interceptor priority
181
- * @returns
182
- */
183
- export declare function Intercept(handler: TCallableClassFunction<TInterceptorFn>, priority?: TInterceptorPriority): ClassDecorator & MethodDecorator;
184
-
185
- export declare class InterceptorHandler {
186
- protected handlers: TInterceptorFn[];
187
- constructor(handlers: TInterceptorFn[]);
188
- protected before: TInterceptorBefore[];
189
- protected after: TInterceptorAfter[];
190
- protected onError: TInterceptorOnError[];
191
- response?: unknown;
192
- responseOverwritten: boolean;
193
- replyFn(reply: unknown): void;
194
- init(): Promise<{} | null | undefined>;
195
- fireBefore(response: unknown): Promise<unknown>;
196
- fireAfter(response: unknown): Promise<unknown>;
197
- }
198
-
199
- /**
200
- * ## Label
201
- * ### @Decorator
202
- * _Common purpose decorator that may be used by various adapters for various purposes_
203
- *
204
- * Stores Label metadata
205
- */
206
- export declare function Label(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
207
-
208
- /**
209
- * ## Moost
210
- * Main moostjs class that serves as a shell for Moost Adapters
211
- *
212
- * ### Usage with HTTP Adapter
213
- * ```ts
214
- * │ // HTTP server example
215
- * │ import { MoostHttp, Get } from '@moostjs/event-http'
216
- * │ import { Moost, Param } from 'moost'
217
- * │
218
- * │ class MyServer extends Moost {
219
- * @Get('test/:name')
220
- * │ test(@Param('name') name: string) {
221
- * │ return { message: `Hello ${name}!` }
222
- * │ }
223
- * │ }
224
- *
225
- * │ const app = new MyServer()
226
- * │ const http = new MoostHttp()
227
- * │ app.adapter(http).listen(3000, () => {
228
- * │ app.getLogger('MyApp').log('Up on port 3000')
229
- * │ })
230
- * │ app.init()
231
- * ```
232
- * ### Usage with CLI Adapter
233
- * ```ts
234
- * │ // CLI example
235
- * │ import { MoostCli, Cli, CliOption, cliHelpInterceptor } from '@moostjs/event-cli'
236
- * │ import { Moost, Param } from 'moost'
237
- *
238
- * │ class MyApp extends Moost {
239
- * │ @Cli('command/:arg')
240
- * │ command(
241
- * │ @Param('arg')
242
- * │ arg: string,
243
- * @CliOption('test', 't')
244
- * │ test: boolean,
245
- * ) {
246
- * │ return `command run with flag arg=${ arg }, test=${ test }`
247
- * │ }
248
- * │ }
249
- *
250
- * │ const app = new MyApp()
251
- * │ app.applyGlobalInterceptors(cliHelpInterceptor())
252
- *
253
- * │ const cli = new MoostCli()
254
- * │ app.adapter(cli)
255
- * │ app.init()
256
- * ```
257
- */
258
- export declare class Moost {
259
- protected options?: TMoostOptions | undefined;
260
- protected logger: TConsoleBase;
261
- protected pipes: TPipeData[];
262
- protected interceptors: TInterceptorData[];
263
- protected adapters: TMoostAdapter<TAny>[];
264
- protected controllersOverview: TControllerOverview[];
265
- protected provide: TProvideRegistry;
266
- protected unregisteredControllers: (TObject | TFunction | [string, TObject | TFunction])[];
267
- constructor(options?: TMoostOptions | undefined);
268
- /**
269
- * ### getLogger
270
- * Provides application logger
271
- * ```js
272
- * // get logger with topic = "App"
273
- * const logger = app.getLogger('App')
274
- * logger.log('...')
275
- * ```
276
- * @param topic
277
- * @returns
278
- */
279
- getLogger(topic: string): TConsoleBase;
280
- adapter<T extends TMoostAdapter<TAny>>(a: T): T;
281
- getControllersOverview(): TControllerOverview[];
282
- /**
283
- * ### init
284
- * Ititializes adapter. Must be called after adapters are attached.
285
- */
286
- init(): Promise<void>;
287
- protected bindControllers(): Promise<void>;
288
- protected bindController(controller: TFunction | TObject, provide: TProvideRegistry, globalPrefix: string, replaceOwnPrefix?: string): Promise<void>;
289
- applyGlobalPipes(...items: (TPipeFn | TPipeData)[]): this;
290
- protected globalInterceptorHandler?: () => Promise<InterceptorHandler>;
291
- /**
292
- * Provides InterceptorHandler with global interceptors and pipes.
293
- * Used to process interceptors when event handler was not found.
294
- *
295
- * @returns IterceptorHandler
296
- */
297
- getGlobalInterceptorHandler(): Promise<InterceptorHandler>;
298
- applyGlobalInterceptors(...items: (TInterceptorData['handler'] | TInterceptorData)[]): this;
299
- /**
300
- * Register new entried to provide as dependency injections
301
- * @param provide - Provide Registry (use createProvideRegistry from '\@prostojs/infact')
302
- * @returns
303
- */
304
- setProvideRegistry(provide: TProvideRegistry): this;
305
- /**
306
- * Register controllers (similar to @ImportController decorator)
307
- * @param controllers - list of target controllers (instances)
308
- * @returns
309
- */
310
- registerControllers(...controllers: (TObject | TFunction | [string, TObject | TFunction])[]): this;
311
- }
312
-
313
- /**
314
- * ## Optional
315
- * ### @Decorator
316
- * _Common purpose decorator that may be used by various adapters for various purposes_
317
- *
318
- * Stores Optional metadata
319
- */
320
- export declare function Optional(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
321
-
322
- /**
323
- * Get Param Value from url parh
324
- * @decorator
325
- * @param name - param name
326
- * @paramType string
327
- */
328
- export declare function Param(name: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
329
-
330
- /**
331
- * Get Parsed Params from url parh
332
- * @decorator
333
- * @paramType object
334
- */
335
- export declare function Params(): ParameterDecorator & PropertyDecorator;
336
-
337
- /**
338
- * ## Pipe
339
- * ### @Decorator
340
- * Attach pipe
341
- * @param handler pipe handler
342
- * @param priority pipe priority
343
- * @returns
344
- */
345
- export declare function Pipe(handler: TPipeFn, priority?: TPipePriority): ClassDecorator & MethodDecorator & ParameterDecorator;
346
-
347
- /**
348
- * ## Provide
349
- * ### @Decorator
350
- * Defines provide registry for class (and all the children)
351
- * @param type - string or class constructor
352
- * @param fn - factory function for provided value
353
- */
354
- export declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator;
355
-
356
- export declare function registerEventScope(scopeId: string): () => void;
357
-
358
- /**
359
- * ## Required
360
- * ### @Decorator
361
- * _Common purpose decorator that may be used by various adapters for various purposes_
362
- *
363
- * Stores Required metadata
364
- */
365
- declare function Required_2(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
366
- export { Required_2 as Required }
367
-
368
- /**
369
- * Hook to the Response Status
370
- * @decorator
371
- * @param resolver - resolver function
372
- * @param label - field label
373
- * @paramType unknown
374
- */
375
- export declare function Resolve<T extends TObject = TEmpty>(resolver: (metas: TPipeMetas<T>, level: TDecoratorLevel) => unknown, label?: string): ParameterDecorator & PropertyDecorator;
376
-
377
- export declare const resolvePipe: TPipeFn<TEmpty>;
378
-
379
- export declare function setControllerContext<T>(controller: T, method: keyof T): void;
380
-
381
- declare type TAny = any;
382
-
383
- declare type TAnyFn = {
384
- (...a: TAny[]): unknown;
385
- };
386
-
387
- export declare type TCallableClassFunction<T extends TAnyFn = TAnyFn> = T | TClassFunctionConstructor;
388
-
389
- declare type TClassConstructor<T = unknown> = new (...args: TAny[]) => T;
390
-
391
- export declare interface TClassFunction<T extends TAnyFn = TAnyFn> {
392
- handler: T;
393
- }
394
-
395
- declare interface TClassFunctionConstructor<T extends TAnyFn = TAnyFn> {
396
- new (...a: TAny[]): TClassFunction<T>;
397
- }
398
-
399
- declare interface TCommonMetaFields {
400
- id?: string;
401
- label?: string;
402
- value?: unknown;
403
- description?: string;
404
- optional?: boolean;
405
- required?: boolean;
406
- }
407
-
408
- declare interface TCommonMoostMeta {
409
- inherit?: boolean;
410
- pipes?: TPipeData[];
411
- resolver?: (metas: TPipeMetas<TAny>, level: TDecoratorLevel) => unknown;
412
- type?: TFunction;
413
- }
414
-
415
- export declare interface TControllerOverview {
416
- meta: TMoostMetadata;
417
- computedPrefix: string;
418
- type: TFunction;
419
- handlers: THandlerOverview[];
420
- }
421
-
422
- declare interface TCustom {
423
- pipes?: TPipeData[];
424
- }
425
-
426
- declare type TDecoratorLevel = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
427
-
428
- declare interface TEmpty {
429
- }
430
-
431
- declare type TFunction = Function;
432
-
433
- declare interface THandlerOverview {
434
- meta: TMoostMetadata;
435
- path?: string;
436
- type: string;
437
- method: string;
438
- handler: TMoostHandler<TEmpty>;
439
- registeredAs: {
440
- path: string;
441
- args: string[];
442
- }[];
443
- }
444
-
445
- export { THook }
446
-
447
- export declare type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
448
-
449
- export declare type TInterceptorAfter = (response: TAny, reply: (response: TAny) => void) => void | Promise<void>;
450
-
451
- export declare type TInterceptorBefore = (reply: (response: TAny) => void) => void | Promise<void>;
452
-
453
- export declare type TInterceptorClass = TClassFunction<TInterceptorFn>;
454
-
455
- export declare interface TInterceptorData {
456
- handler: TCallableClassFunction<TInterceptorFn>;
457
- priority: TInterceptorPriority;
458
- }
459
-
460
- export declare type TInterceptorFn = {
461
- (before: (fn: TInterceptorBefore) => void, after: (fn: TInterceptorAfter) => void, onError: (fn: TInterceptorOnError) => void): unknown | Promise<unknown>;
462
- priority?: TInterceptorPriority;
463
- };
464
-
465
- export declare type TInterceptorOnError = (error: Error, reply: (response: TAny) => void) => void | Promise<void>;
466
-
467
- export declare enum TInterceptorPriority {
468
- BEFORE_ALL = 0,
469
- BEFORE_GUARD = 1,
470
- GUARD = 2,
471
- AFTER_GUARD = 3,
472
- INTERCEPTOR = 4,
473
- CATCH_ERROR = 5,
474
- AFTER_ALL = 6
475
- }
476
-
477
- export declare interface TMoostAdapter<H> {
478
- bindHandler<T extends TObject = TObject>(options: TMoostAdapterOptions<H, T>): void | Promise<void>;
479
- onInit?: (moost: Moost) => void | Promise<void>;
480
- getProvideRegistry?: () => TProvideRegistry;
481
- }
482
-
483
- export declare interface TMoostAdapterOptions<H, T> {
484
- prefix: string;
485
- fakeInstance: T;
486
- getInstance: () => Promise<T>;
487
- method: keyof T;
488
- handlers: TMoostHandler<H>[];
489
- getIterceptorHandler: () => Promise<InterceptorHandler>;
490
- resolveArgs: () => Promise<unknown[]>;
491
- logHandler: (eventName: string) => void;
492
- register: (handler: TMoostHandler<TEmpty>, path: string, args: string[]) => void;
493
- }
494
-
495
- export declare interface TMoostEventHandlerHookOptions<T> {
496
- restoreCtx: () => void;
497
- scopeId: string;
498
- logger: ReturnType<typeof useEventLogger>;
499
- unscope: () => void;
500
- instance?: T;
501
- method?: keyof T;
502
- getResponse: () => unknown;
503
- reply: (r: unknown) => void;
504
- }
505
-
506
- export declare interface TMoostEventHandlerOptions<T> {
507
- contextType?: string | string[];
508
- loggerTitle: string;
509
- getIterceptorHandler: () => Promise<InterceptorHandler> | InterceptorHandler | undefined;
510
- getControllerInstance: () => Promise<T> | T | undefined;
511
- controllerMethod?: keyof T;
512
- callControllerMethod?: (args: unknown[]) => unknown;
513
- resolveArgs?: () => Promise<unknown[]> | unknown[];
514
- logErrors?: boolean;
515
- manualUnscope?: boolean;
516
- hooks?: {
517
- init?: (opts: TMoostEventHandlerHookOptions<T>) => unknown;
518
- end?: (opts: TMoostEventHandlerHookOptions<T>) => unknown;
519
- };
520
- }
521
-
522
- export declare type TMoostHandler<T> = {
523
- type: string;
524
- path?: string;
525
- } & T;
526
-
527
- export declare interface TMoostMetadata<H extends TObject = TEmpty> extends TCommonMetaFields, TCommonMoostMeta {
528
- requiredProps?: (string | symbol)[];
529
- controller?: {
530
- prefix?: string;
531
- };
532
- importController?: {
533
- prefix?: string;
534
- typeResolver?: TClassConstructor | (() => TClassConstructor | TObject | Promise<TClassConstructor | TObject>);
535
- provide?: TProvideRegistry;
536
- }[];
537
- properties?: (string | symbol)[];
538
- injectable?: true | TInjectableScope;
539
- interceptors?: TInterceptorData[];
540
- handlers?: TMoostHandler<H>[];
541
- returnType?: TFunction;
542
- provide?: TProvideRegistry;
543
- params: (TMateParamMeta & TMoostParamsMetadata)[];
544
- }
545
-
546
- export declare interface TMoostOptions {
547
- /**
548
- * Prefix that is used for each event path
549
- */
550
- globalPrefix?: string;
551
- logger?: TConsoleBase;
552
- }
553
-
554
- export declare interface TMoostParamsMetadata extends TCommonMetaFields, TCommonMoostMeta {
555
- circular?: () => TAny;
556
- inject?: string | symbol | TClassConstructor;
557
- nullable?: boolean;
558
- paramSource?: string;
559
- paramName?: string;
560
- }
561
-
562
- declare type TObject = object;
563
-
564
- export declare interface TPipeData {
565
- handler: TPipeFn;
566
- priority: TPipePriority;
567
- }
568
-
569
- export declare type TPipeFn<T extends TObject = TEmpty> = {
570
- (value: unknown, metas: TPipeMetas<T>, level: TDecoratorLevel): unknown | Promise<unknown>;
571
- priority?: TPipePriority;
572
- };
573
-
574
- export declare interface TPipeMetas<T extends TObject = TEmpty> {
575
- classMeta?: TMoostMetadata & T;
576
- methodMeta?: TMoostMetadata & T;
577
- propMeta?: TMoostMetadata & T;
578
- paramMeta?: TMoostParamsMetadata & T;
579
- targetMeta?: TMoostParamsMetadata & T;
580
- instance?: TObject;
581
- type: TFunction;
582
- index?: number;
583
- key: string | symbol;
584
- }
585
-
586
- export declare enum TPipePriority {
587
- BEFORE_RESOLVE = 0,
588
- RESOLVE = 1,
589
- AFTER_RESOLVE = 2,
590
- BEFORE_TRANSFORM = 3,
591
- TRANSFORM = 4,
592
- AFTER_TRANSFORM = 5,
593
- BEFORE_VALIDATE = 6,
594
- VALIDATE = 7,
595
- AFTER_VALIDATE = 8
596
- }
597
-
598
- export { TProvideRegistry }
599
-
600
- export declare function useControllerContext<T extends object>(): {
601
- instantiate: <T_1>(c: TClassConstructor<T_1>) => Promise<T_1>;
602
- getController: () => T;
603
- getMethod: () => keyof T;
604
- getControllerMeta: () => (TMoostMetadata<TEmpty> & TEmpty & {
605
- params: (TEmpty & TMateParamMeta)[];
606
- }) | (TMoostMetadata<TEmpty> & TEmpty & {
607
- params: (TEmpty & TMateParamMeta)[];
608
- } & {
609
- params: (TEmpty & TMateParamMeta)[];
610
- } & TMateClassMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty> & TMatePropMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty>);
611
- getMethodMeta: (name?: string) => TMoostMetadata<TEmpty> & TEmpty & {
612
- params: (TEmpty & TMateParamMeta)[];
613
- } & {
614
- params: (TEmpty & TMateParamMeta)[];
615
- } & TMateClassMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty> & TMatePropMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty>;
616
- getPropertiesList: () => (string | symbol)[];
617
- getScope: () => true | TInjectableScope;
618
- getParamsMeta: () => (TMateParamMeta & TMoostParamsMetadata)[] & (TEmpty & TMateParamMeta)[] & (TMateParamMeta & TMoostParamsMetadata & TEmpty)[];
619
- getPropMeta: (name: string) => TMoostMetadata<TEmpty> & TEmpty & {
620
- params: (TEmpty & TMateParamMeta)[];
621
- } & {
622
- params: (TEmpty & TMateParamMeta)[];
623
- } & TMateClassMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty> & TMatePropMeta<TMateParamMeta & TMoostParamsMetadata & TEmpty>;
624
- };
625
-
626
- export { useEventContext }
627
-
628
- export { useEventLogger }
629
-
630
- /**
631
- * ## Value
632
- * ### @Decorator
633
- * _Common purpose decorator that may be used by various adapters for various purposes_
634
- *
635
- * Stores Value metadata
636
- */
637
- export declare function Value(value: unknown): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
638
-
639
- export { }
1
+ import * as _prostojs_mate from '@prostojs/mate';
2
+ import { TMateParamMeta, Mate } from '@prostojs/mate';
3
+ import { TProvideRegistry, Infact, TProvideFn } from '@prostojs/infact';
4
+ export { TProvideRegistry, createProvideRegistry } from '@prostojs/infact';
5
+ import { TConsoleBase } from '@prostojs/logger';
6
+ import { useEventLogger } from '@wooksjs/event-core';
7
+ export { EventLogger, THook, useEventContext, useEventLogger } from '@wooksjs/event-core';
8
+
9
+ type TAny = any;
10
+ type TAnyFn = {
11
+ (...a: TAny[]): unknown;
12
+ };
13
+ type TObject = object;
14
+ type TFunction = Function;
15
+ type TClassConstructor<T = unknown> = new (...args: TAny[]) => T;
16
+ interface TEmpty {
17
+ }
18
+
19
+ interface TClassFunction<T extends TAnyFn = TAnyFn> {
20
+ handler: T;
21
+ }
22
+ interface TClassFunctionConstructor<T extends TAnyFn = TAnyFn> {
23
+ new (...a: TAny[]): TClassFunction<T>;
24
+ }
25
+ type TCallableClassFunction<T extends TAnyFn = TAnyFn> = T | TClassFunctionConstructor;
26
+
27
+ type TInterceptorBefore = (reply: (response: TAny) => void) => void | Promise<void>;
28
+ type TInterceptorAfter = (response: TAny, reply: (response: TAny) => void) => void | Promise<void>;
29
+ type TInterceptorOnError = (error: Error, reply: (response: TAny) => void) => void | Promise<void>;
30
+ type TInterceptorFn = {
31
+ (before: (fn: TInterceptorBefore) => void, after: (fn: TInterceptorAfter) => void, onError: (fn: TInterceptorOnError) => void): unknown | Promise<unknown>;
32
+ priority?: TInterceptorPriority;
33
+ };
34
+ declare enum TInterceptorPriority {
35
+ BEFORE_ALL = 0,
36
+ BEFORE_GUARD = 1,
37
+ GUARD = 2,
38
+ AFTER_GUARD = 3,
39
+ INTERCEPTOR = 4,
40
+ CATCH_ERROR = 5,
41
+ AFTER_ALL = 6
42
+ }
43
+ /**
44
+ * ## Intercept
45
+ * ### @Decorator
46
+ * Set interceptor
47
+ * @param handler interceptor fn (use defineInterceptorFn)
48
+ * @param priority interceptor priority
49
+ * @returns
50
+ */
51
+ declare function Intercept(handler: TCallableClassFunction<TInterceptorFn>, priority?: TInterceptorPriority): ClassDecorator & MethodDecorator;
52
+
53
+ type TDecoratorLevel = 'CLASS' | 'METHOD' | 'PROP' | 'PARAM';
54
+
55
+ interface TPipeMetas<T extends TObject = TEmpty> {
56
+ classMeta?: TMoostMetadata & T;
57
+ methodMeta?: TMoostMetadata & T;
58
+ propMeta?: TMoostMetadata & T;
59
+ paramMeta?: TMoostParamsMetadata & T;
60
+ targetMeta?: TMoostParamsMetadata & T;
61
+ instance?: TObject;
62
+ type: TFunction;
63
+ index?: number;
64
+ key: string | symbol;
65
+ }
66
+ type TPipeFn<T extends TObject = TEmpty> = {
67
+ (value: unknown, metas: TPipeMetas<T>, level: TDecoratorLevel): unknown | Promise<unknown>;
68
+ priority?: TPipePriority;
69
+ };
70
+ declare enum TPipePriority {
71
+ BEFORE_RESOLVE = 0,
72
+ RESOLVE = 1,
73
+ AFTER_RESOLVE = 2,
74
+ BEFORE_TRANSFORM = 3,
75
+ TRANSFORM = 4,
76
+ AFTER_TRANSFORM = 5,
77
+ BEFORE_VALIDATE = 6,
78
+ VALIDATE = 7,
79
+ AFTER_VALIDATE = 8
80
+ }
81
+ interface TPipeData {
82
+ handler: TPipeFn;
83
+ priority: TPipePriority;
84
+ }
85
+
86
+ declare const resolvePipe: TPipeFn<TEmpty>;
87
+
88
+ interface TMoostMetadata<H extends TObject = TEmpty> extends TCommonMetaFields, TCommonMoostMeta {
89
+ requiredProps?: (string | symbol)[];
90
+ controller?: {
91
+ prefix?: string;
92
+ };
93
+ importController?: {
94
+ prefix?: string;
95
+ typeResolver?: TClassConstructor | (() => TClassConstructor | TObject | Promise<TClassConstructor | TObject>);
96
+ provide?: TProvideRegistry;
97
+ }[];
98
+ properties?: (string | symbol)[];
99
+ injectable?: true | TInjectableScope;
100
+ interceptors?: TInterceptorData[];
101
+ handlers?: TMoostHandler<H>[];
102
+ returnType?: TFunction;
103
+ provide?: TProvideRegistry;
104
+ params: (TMateParamMeta & TMoostParamsMetadata)[];
105
+ }
106
+ interface TMoostParamsMetadata extends TCommonMetaFields, TCommonMoostMeta {
107
+ circular?: () => TAny;
108
+ inject?: string | symbol | TClassConstructor;
109
+ nullable?: boolean;
110
+ paramSource?: string;
111
+ paramName?: string;
112
+ }
113
+ type TInjectableScope = 'FOR_EVENT' | 'SINGLETON';
114
+ type TMoostHandler<T> = {
115
+ type: string;
116
+ path?: string;
117
+ } & T;
118
+ interface TInterceptorData {
119
+ handler: TCallableClassFunction<TInterceptorFn>;
120
+ priority: TInterceptorPriority;
121
+ }
122
+ declare function getMoostMate<Class extends TObject = TEmpty, Prop extends TObject = TEmpty, Param extends TObject = TEmpty>(): Mate<TMoostMetadata<TEmpty> & Class & {
123
+ params: (Param & TMateParamMeta)[];
124
+ }, TMoostMetadata<TEmpty> & Prop & {
125
+ params: (Param & TMateParamMeta)[];
126
+ }>;
127
+ interface TCommonMetaFields {
128
+ id?: string;
129
+ label?: string;
130
+ value?: unknown;
131
+ description?: string;
132
+ optional?: boolean;
133
+ required?: boolean;
134
+ }
135
+ interface TCommonMoostMeta {
136
+ inherit?: boolean;
137
+ pipes?: TPipeData[];
138
+ resolver?: (metas: TPipeMetas<TAny>, level: TDecoratorLevel) => unknown;
139
+ type?: TFunction;
140
+ }
141
+
142
+ declare function getMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
143
+ interface TCustom {
144
+ pipes?: TPipeData[];
145
+ }
146
+ declare function getNewMoostInfact(): Infact<TMoostMetadata<TEmpty>, TMoostMetadata<TEmpty>, TMoostParamsMetadata, TCustom>;
147
+
148
+ /**
149
+ * Hook to the Response Status
150
+ * @decorator
151
+ * @param resolver - resolver function
152
+ * @param label - field label
153
+ * @paramType unknown
154
+ */
155
+ declare function Resolve<T extends TObject = TEmpty>(resolver: (metas: TPipeMetas<T>, level: TDecoratorLevel) => unknown, label?: string): ParameterDecorator & PropertyDecorator;
156
+ /**
157
+ * Get Param Value from url parh
158
+ * @decorator
159
+ * @param name - param name
160
+ * @paramType string
161
+ */
162
+ declare function Param(name: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
163
+ /**
164
+ * Get Parsed Params from url parh
165
+ * @decorator
166
+ * @paramType object
167
+ */
168
+ declare function Params(): ParameterDecorator & PropertyDecorator;
169
+ /**
170
+ * Provide Const Value
171
+ * @decorator
172
+ * @param value - provided value
173
+ * @param label - label of the field
174
+ * @paramType unknown
175
+ */
176
+ declare function Const<T>(value: T, label?: string): ParameterDecorator & PropertyDecorator;
177
+ /**
178
+ * Provide Const Value from Factory fn
179
+ * @decorator
180
+ * @param factory - value Factory fn
181
+ * @param label - label of the field
182
+ * @paramType unknown
183
+ */
184
+ declare function ConstFactory<T>(factory: () => T | Promise<T>, label?: string): ParameterDecorator & PropertyDecorator;
185
+ /**
186
+ * Resolves event logger from event context
187
+ * @param topic
188
+ * @returns Resolver to '@wooksjs/event-core' (EventLogger)
189
+ */
190
+ declare function InjectEventLogger(topic?: string): ParameterDecorator & PropertyDecorator;
191
+
192
+ /**
193
+ * ## Controller
194
+ * ### @Decorator
195
+ * Set Class as a Controller
196
+ * @param prefix - define the prefix for all the paths of this controller
197
+ */
198
+ declare function Controller(prefix?: string): ClassDecorator;
199
+ /**
200
+ * ## ImportController
201
+ * ### @Decorator
202
+ * Attach sub-controller
203
+ * @param controller - target controller (instance) to import
204
+ * @param provide - provide registry for the target controller
205
+ */
206
+ declare function ImportController(controller: TFunction | TObject, provide?: TProvideRegistry): ClassDecorator;
207
+ /**
208
+ * ## ImportController
209
+ * ### @Decorator
210
+ * Attach sub-controller
211
+ * @param prefix - redefine the prefix for all the paths of this controller
212
+ * @param controller - point to a controller (instance) to import
213
+ * @param provide - provide registry for the target controller
214
+ */
215
+ declare function ImportController(prefix: string, controller: TFunction | TObject, provide?: TProvideRegistry): ClassDecorator;
216
+
217
+ /**
218
+ * ## Injectable
219
+ * ### @Decorator
220
+ * Mark the Class as Injectable to enable it to be used in dependency injection
221
+ * @param scope - Scope for injection ("FOR_EVENT" | "SINGLETON" | true)
222
+ * FOR_EVENT - will create a new instance for each incoming request
223
+ * SINGLETON | true - will create a new instance only once
224
+ * @param label - field label
225
+ */
226
+ declare function Injectable(scope?: true | TInjectableScope): ClassDecorator;
227
+
228
+ declare function Circular<T = unknown>(resolver: () => TClassConstructor<T>): ParameterDecorator;
229
+
230
+ /**
231
+ * ## Provide
232
+ * ### @Decorator
233
+ * Defines provide registry for class (and all the children)
234
+ * @param type - string or class constructor
235
+ * @param fn - factory function for provided value
236
+ */
237
+ declare function Provide(type: string | TClassConstructor, fn: TProvideFn): ClassDecorator;
238
+ /**
239
+ * ## Inject
240
+ * ### @Decorator
241
+ * Defines a key from provide registry to inject value
242
+ * (For optional values use with @Optional())
243
+ * @param type - string or class constructor
244
+ */
245
+ declare function Inject(type: string | TClassConstructor): ParameterDecorator;
246
+
247
+ /**
248
+ * ## Label
249
+ * ### @Decorator
250
+ * _Common purpose decorator that may be used by various adapters for various purposes_
251
+ *
252
+ * Stores Label metadata
253
+ */
254
+ declare function Label(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
255
+ /**
256
+ * ## Description
257
+ * ### @Decorator
258
+ * _Common purpose decorator that may be used by various adapters for various purposes_
259
+ *
260
+ * Stores Description metadata
261
+ */
262
+ declare function Description(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
263
+ /**
264
+ * ## Value
265
+ * ### @Decorator
266
+ * _Common purpose decorator that may be used by various adapters for various purposes_
267
+ *
268
+ * Stores Value metadata
269
+ */
270
+ declare function Value(value: unknown): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
271
+ /**
272
+ * ## Id
273
+ * ### @Decorator
274
+ * _Common purpose decorator that may be used by various adapters for various purposes_
275
+ *
276
+ * Stores Id metadata
277
+ */
278
+ declare function Id(value: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
279
+ /**
280
+ * ## Optional
281
+ * ### @Decorator
282
+ * _Common purpose decorator that may be used by various adapters for various purposes_
283
+ *
284
+ * Stores Optional metadata
285
+ */
286
+ declare function Optional(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
287
+ /**
288
+ * ## Required
289
+ * ### @Decorator
290
+ * _Common purpose decorator that may be used by various adapters for various purposes_
291
+ *
292
+ * Stores Required metadata
293
+ */
294
+ declare function Required(): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
295
+
296
+ /**
297
+ * ## Inherit
298
+ * ### @Decorator
299
+ * Inherit metadata from super class
300
+ * @returns
301
+ */
302
+ declare const Inherit: () => MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator;
303
+
304
+ /**
305
+ * ## Pipe
306
+ * ### @Decorator
307
+ * Attach pipe
308
+ * @param handler pipe handler
309
+ * @param priority pipe priority
310
+ * @returns
311
+ */
312
+ declare function Pipe(handler: TPipeFn, priority?: TPipePriority): ClassDecorator & MethodDecorator & ParameterDecorator;
313
+
314
+ declare class InterceptorHandler {
315
+ protected handlers: TInterceptorFn[];
316
+ constructor(handlers: TInterceptorFn[]);
317
+ protected before: TInterceptorBefore[];
318
+ protected after: TInterceptorAfter[];
319
+ protected onError: TInterceptorOnError[];
320
+ response?: unknown;
321
+ responseOverwritten: boolean;
322
+ replyFn(reply: unknown): void;
323
+ init(): Promise<{} | null | undefined>;
324
+ fireBefore(response: unknown): Promise<unknown>;
325
+ fireAfter(response: unknown): Promise<unknown>;
326
+ }
327
+
328
+ interface TControllerOverview {
329
+ meta: TMoostMetadata;
330
+ computedPrefix: string;
331
+ type: TFunction;
332
+ handlers: THandlerOverview[];
333
+ }
334
+ interface THandlerOverview {
335
+ meta: TMoostMetadata;
336
+ path?: string;
337
+ type: string;
338
+ method: string;
339
+ handler: TMoostHandler<TEmpty>;
340
+ registeredAs: {
341
+ path: string;
342
+ args: string[];
343
+ }[];
344
+ }
345
+
346
+ interface TMoostOptions {
347
+ /**
348
+ * Prefix that is used for each event path
349
+ */
350
+ globalPrefix?: string;
351
+ logger?: TConsoleBase;
352
+ }
353
+ /**
354
+ * ## Moost
355
+ * Main moostjs class that serves as a shell for Moost Adapters
356
+ *
357
+ * ### Usage with HTTP Adapter
358
+ * ```ts
359
+ * │ // HTTP server example
360
+ * │ import { MoostHttp, Get } from '@moostjs/event-http'
361
+ * │ import { Moost, Param } from 'moost'
362
+ *
363
+ * │ class MyServer extends Moost {
364
+ * │ @Get('test/:name')
365
+ * │ test(@Param('name') name: string) {
366
+ * │ return { message: `Hello ${name}!` }
367
+ * │ }
368
+ * │ }
369
+ *
370
+ * │ const app = new MyServer()
371
+ * │ const http = new MoostHttp()
372
+ * │ app.adapter(http).listen(3000, () => {
373
+ * │ app.getLogger('MyApp').log('Up on port 3000')
374
+ * │ })
375
+ * │ app.init()
376
+ * ```
377
+ * ### Usage with CLI Adapter
378
+ * ```ts
379
+ * │ // CLI example
380
+ * │ import { MoostCli, Cli, CliOption, cliHelpInterceptor } from '@moostjs/event-cli'
381
+ * │ import { Moost, Param } from 'moost'
382
+ * │
383
+ * │ class MyApp extends Moost {
384
+ * │ @Cli('command/:arg')
385
+ * │ command(
386
+ * │ @Param('arg')
387
+ * │ arg: string,
388
+ * │ @CliOption('test', 't')
389
+ * │ test: boolean,
390
+ * │ ) {
391
+ * │ return `command run with flag arg=${ arg }, test=${ test }`
392
+ * │ }
393
+ * │ }
394
+ * │
395
+ * │ const app = new MyApp()
396
+ * │ app.applyGlobalInterceptors(cliHelpInterceptor())
397
+ * │
398
+ * │ const cli = new MoostCli()
399
+ * │ app.adapter(cli)
400
+ * │ app.init()
401
+ * ```
402
+ */
403
+ declare class Moost {
404
+ protected options?: TMoostOptions | undefined;
405
+ protected logger: TConsoleBase;
406
+ protected pipes: TPipeData[];
407
+ protected interceptors: TInterceptorData[];
408
+ protected adapters: TMoostAdapter<TAny>[];
409
+ protected controllersOverview: TControllerOverview[];
410
+ protected provide: TProvideRegistry;
411
+ protected unregisteredControllers: (TObject | TFunction | [string, TObject | TFunction])[];
412
+ constructor(options?: TMoostOptions | undefined);
413
+ /**
414
+ * ### getLogger
415
+ * Provides application logger
416
+ * ```js
417
+ * // get logger with topic = "App"
418
+ * const logger = app.getLogger('App')
419
+ * logger.log('...')
420
+ * ```
421
+ * @param topic
422
+ * @returns
423
+ */
424
+ getLogger(topic: string): TConsoleBase;
425
+ adapter<T extends TMoostAdapter<TAny>>(a: T): T;
426
+ getControllersOverview(): TControllerOverview[];
427
+ /**
428
+ * ### init
429
+ * Ititializes adapter. Must be called after adapters are attached.
430
+ */
431
+ init(): Promise<void>;
432
+ protected bindControllers(): Promise<void>;
433
+ protected bindController(controller: TFunction | TObject, provide: TProvideRegistry, globalPrefix: string, replaceOwnPrefix?: string): Promise<void>;
434
+ applyGlobalPipes(...items: (TPipeFn | TPipeData)[]): this;
435
+ protected globalInterceptorHandler?: () => Promise<InterceptorHandler>;
436
+ /**
437
+ * Provides InterceptorHandler with global interceptors and pipes.
438
+ * Used to process interceptors when event handler was not found.
439
+ *
440
+ * @returns IterceptorHandler
441
+ */
442
+ getGlobalInterceptorHandler(): Promise<InterceptorHandler>;
443
+ applyGlobalInterceptors(...items: (TInterceptorData['handler'] | TInterceptorData)[]): this;
444
+ /**
445
+ * Register new entried to provide as dependency injections
446
+ * @param provide - Provide Registry (use createProvideRegistry from '\@prostojs/infact')
447
+ * @returns
448
+ */
449
+ setProvideRegistry(provide: TProvideRegistry): this;
450
+ /**
451
+ * Register controllers (similar to @ImportController decorator)
452
+ * @param controllers - list of target controllers (instances)
453
+ * @returns
454
+ */
455
+ registerControllers(...controllers: (TObject | TFunction | [string, TObject | TFunction])[]): this;
456
+ }
457
+ interface TMoostAdapterOptions<H, T> {
458
+ prefix: string;
459
+ fakeInstance: T;
460
+ getInstance: () => Promise<T>;
461
+ method: keyof T;
462
+ handlers: TMoostHandler<H>[];
463
+ getIterceptorHandler: () => Promise<InterceptorHandler>;
464
+ resolveArgs: () => Promise<unknown[]>;
465
+ logHandler: (eventName: string) => void;
466
+ register: (handler: TMoostHandler<TEmpty>, path: string, args: string[]) => void;
467
+ }
468
+ interface TMoostAdapter<H> {
469
+ bindHandler<T extends TObject = TObject>(options: TMoostAdapterOptions<H, T>): void | Promise<void>;
470
+ onInit?: (moost: Moost) => void | Promise<void>;
471
+ getProvideRegistry?: () => TProvideRegistry;
472
+ }
473
+
474
+ declare function setControllerContext<T>(controller: T, method: keyof T): void;
475
+ declare function useControllerContext<T extends object>(): {
476
+ instantiate: <T_1>(c: TClassConstructor<T_1>) => Promise<T_1>;
477
+ getController: () => T;
478
+ getMethod: () => keyof T;
479
+ getControllerMeta: () => (TMoostMetadata<TEmpty> & TEmpty & {
480
+ params: (TEmpty & _prostojs_mate.TMateParamMeta)[];
481
+ }) | (TMoostMetadata<TEmpty> & TEmpty & {
482
+ params: (TEmpty & _prostojs_mate.TMateParamMeta)[];
483
+ } & {
484
+ params: (TEmpty & _prostojs_mate.TMateParamMeta)[];
485
+ } & _prostojs_mate.TMateClassMeta<_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & TEmpty> & _prostojs_mate.TMatePropMeta<_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & TEmpty>);
486
+ getMethodMeta: (name?: string) => TMoostMetadata<TEmpty> & TEmpty & {
487
+ params: (TEmpty & _prostojs_mate.TMateParamMeta)[];
488
+ } & {
489
+ params: (TEmpty & _prostojs_mate.TMateParamMeta)[];
490
+ } & _prostojs_mate.TMateClassMeta<_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & TEmpty> & _prostojs_mate.TMatePropMeta<_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & TEmpty>;
491
+ getPropertiesList: () => (string | symbol)[];
492
+ getScope: () => true | TInjectableScope;
493
+ getParamsMeta: () => (_prostojs_mate.TMateParamMeta & TMoostParamsMetadata)[] & (TEmpty & _prostojs_mate.TMateParamMeta)[] & (_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & TEmpty)[];
494
+ getPropMeta: (name: string) => TMoostMetadata<TEmpty> & TEmpty & {
495
+ params: (TEmpty & _prostojs_mate.TMateParamMeta)[];
496
+ } & {
497
+ params: (TEmpty & _prostojs_mate.TMateParamMeta)[];
498
+ } & _prostojs_mate.TMateClassMeta<_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & TEmpty> & _prostojs_mate.TMatePropMeta<_prostojs_mate.TMateParamMeta & TMoostParamsMetadata & TEmpty>;
499
+ };
500
+
501
+ interface TMoostEventHandlerHookOptions<T> {
502
+ restoreCtx: () => void;
503
+ scopeId: string;
504
+ logger: ReturnType<typeof useEventLogger>;
505
+ unscope: () => void;
506
+ instance?: T;
507
+ method?: keyof T;
508
+ getResponse: () => unknown;
509
+ reply: (r: unknown) => void;
510
+ }
511
+ interface TMoostEventHandlerOptions<T> {
512
+ contextType?: string | string[];
513
+ loggerTitle: string;
514
+ getIterceptorHandler: () => Promise<InterceptorHandler> | InterceptorHandler | undefined;
515
+ getControllerInstance: () => Promise<T> | T | undefined;
516
+ controllerMethod?: keyof T;
517
+ callControllerMethod?: (args: unknown[]) => unknown;
518
+ resolveArgs?: () => Promise<unknown[]> | unknown[];
519
+ logErrors?: boolean;
520
+ manualUnscope?: boolean;
521
+ hooks?: {
522
+ init?: (opts: TMoostEventHandlerHookOptions<T>) => unknown;
523
+ end?: (opts: TMoostEventHandlerHookOptions<T>) => unknown;
524
+ };
525
+ }
526
+ declare function registerEventScope(scopeId: string): () => void;
527
+ declare function defineMoostEventHandler<T>(options: TMoostEventHandlerOptions<T>): () => Promise<unknown>;
528
+
529
+ /**
530
+ * ### Define Interceptor Function
531
+ *
532
+ * ```ts
533
+ * defineInterceptorFn((before, after, onError) => {
534
+ * //init
535
+ * before(() => {
536
+ * // before handler
537
+ * })
538
+ * after((response, reply) => {
539
+ * // after handler
540
+ * })
541
+ * onError((error, reply) => {
542
+ * // when error occured
543
+ * })
544
+ * },
545
+ * TInterceptorPriority.INTERCEPTOR,
546
+ * )
547
+ * ```
548
+ *
549
+ * @param fn interceptor function
550
+ * @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
551
+ * @returns
552
+ */
553
+ declare function defineInterceptorFn(fn: TInterceptorFn, priority?: TInterceptorPriority): TInterceptorFn;
554
+ type TInterceptorClass = TClassFunction<TInterceptorFn>;
555
+ /**
556
+ * ### Define Pipe Function
557
+ *
558
+ * ```ts
559
+ * // example of a transform pipe
560
+ * const uppercaseTransformPipe = definePipeFn((value, metas, level) => {
561
+ * return typeof value === 'string' ? value.toUpperCase() : value
562
+ * },
563
+ * TPipePriority.TRANSFORM,
564
+ * )
565
+ * ```
566
+ *
567
+ * @param fn interceptor function
568
+ * @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
569
+ * @returns
570
+ */
571
+ declare function definePipeFn<T extends TObject = TEmpty>(fn: TPipeFn<T>, priority?: TPipePriority): TPipeFn<T>;
572
+
573
+ export { Circular, Const, ConstFactory, Controller, Description, Id, ImportController, Inherit, Inject, InjectEventLogger, Injectable, Intercept, InterceptorHandler, Label, Moost, Optional, Param, Params, Pipe, Provide, Required, Resolve, type TCallableClassFunction, type TClassFunction, type TControllerOverview, type TInjectableScope, type TInterceptorAfter, type TInterceptorBefore, type TInterceptorClass, type TInterceptorData, type TInterceptorFn, type TInterceptorOnError, TInterceptorPriority, type TMoostAdapter, type TMoostAdapterOptions, type TMoostEventHandlerHookOptions, type TMoostEventHandlerOptions, type TMoostHandler, type TMoostMetadata, type TMoostOptions, type TMoostParamsMetadata, type TPipeData, type TPipeFn, type TPipeMetas, TPipePriority, Value, defineInterceptorFn, defineMoostEventHandler, definePipeFn, getMoostInfact, getMoostMate, getNewMoostInfact, registerEventScope, resolvePipe, setControllerContext, useControllerContext };