1 | import { BindingFilter } from './binding-filter';
|
2 | import { BindingAddress } from './binding-key';
|
3 | import { BindingComparator } from './binding-sorter';
|
4 | import { Context } from './context';
|
5 | import { InvocationResult } from './invocation';
|
6 | import { ValueOrPromise } from './value-promise';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export type NonVoid = string | number | boolean | null | undefined | object;
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export type Next = () => ValueOrPromise<NonVoid>;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | export type GenericInterceptor<C extends Context = Context> = (context: C, next: Next) => ValueOrPromise<NonVoid>;
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | export type GenericInterceptorOrKey<C extends Context = Context> = BindingAddress<GenericInterceptor<C>> | GenericInterceptor<C>;
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | export declare class GenericInterceptorChain<C extends Context = Context> {
|
65 | private context;
|
66 | |
67 |
|
68 |
|
69 | protected getInterceptors: () => GenericInterceptorOrKey<C>[];
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | constructor(context: C, interceptors: GenericInterceptorOrKey<C>[]);
|
77 | /**
|
78 | * Create an invocation interceptor chain with a binding filter and comparator.
|
79 | * The interceptors are discovered from the context using the binding filter and
|
80 | * sorted by the comparator (if provided).
|
81 | *
|
82 | * @param context - Context object
|
83 | * @param filter - A binding filter function to select interceptors
|
84 | * @param comparator - An optional comparator to sort matched interceptor bindings
|
85 | */
|
86 | constructor(context: C, filter: BindingFilter, comparator?: BindingComparator);
|
87 | /**
|
88 | * Invoke the interceptor chain
|
89 | */
|
90 | invokeInterceptors(finalHandler?: Next): ValueOrPromise<InvocationResult>;
|
91 | /**
|
92 | * Use the interceptor chain as an interceptor
|
93 | */
|
94 | asInterceptor(): GenericInterceptor<C>;
|
95 | /**
|
96 | * Invoke downstream interceptors or the target method
|
97 | */
|
98 | private next;
|
99 | /**
|
100 | * Invoke downstream interceptors
|
101 | */
|
102 | private invokeNextInterceptor;
|
103 | /**
|
104 | * Return the interceptor function or resolve the interceptor function as a binding
|
105 | * from the context
|
106 | *
|
107 | * @param interceptor - Interceptor function or binding key
|
108 | */
|
109 | private loadInterceptor;
|
110 | }
|
111 | /**
|
112 | * Invoke a chain of interceptors with the context
|
113 | * @param context - Context object
|
114 | * @param interceptors - An array of interceptor functions or binding keys
|
115 | */
|
116 | export declare function invokeInterceptors<C extends Context = Context, T = InvocationResult>(context: C, interceptors: GenericInterceptorOrKey<C>[]): ValueOrPromise<T | undefined>;
|
117 | /**
|
118 | * Compose a list of interceptors as a single interceptor
|
119 | * @param interceptors - A list of interceptor functions or binding keys
|
120 | */
|
121 | export declare function composeInterceptors<C extends Context = Context>(...interceptors: GenericInterceptorOrKey<C>[]): GenericInterceptor<C>;
|