1 | import { Context } from './context';
|
2 | import { InvocationArgs, InvocationSource } from './invocation';
|
3 | import { ResolutionSession } from './resolution-session';
|
4 | import { ValueOrPromise } from './value-promise';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export type AsValueOrPromise<T> = T extends Promise<unknown> ? T : ValueOrPromise<T>;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export type AsInterceptedFunction<T> = T extends (...args: InvocationArgs) => infer R ? (...args: Parameters<T>) => AsValueOrPromise<R> : T;
|
15 |
|
16 |
|
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 | export type AsyncProxy<T> = {
|
45 | [P in keyof T]: AsInterceptedFunction<T[P]>;
|
46 | };
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | export declare class ProxySource implements InvocationSource<ResolutionSession> {
|
52 | readonly value: ResolutionSession;
|
53 | type: string;
|
54 | constructor(value: ResolutionSession);
|
55 | toString(): string;
|
56 | }
|
57 | /**
|
58 | * A proxy handler that applies interceptors
|
59 | *
|
60 | * See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy
|
61 | */
|
62 | export declare class InterceptionHandler<T extends object> implements ProxyHandler<T> {
|
63 | private context;
|
64 | private session?;
|
65 | private source?;
|
66 | constructor(context?: Context, session?: ResolutionSession | undefined, source?: InvocationSource<unknown> | undefined);
|
67 | get(target: T, propertyName: PropertyKey, receiver: unknown): any;
|
68 | }
|
69 | /**
|
70 | * Create a proxy that applies interceptors for method invocations
|
71 | * @param target - Target class or object
|
72 | * @param context - Context object
|
73 | * @param session - Resolution session
|
74 | * @param source - Invocation source
|
75 | */
|
76 | export declare function createProxyWithInterceptors<T extends object>(target: T, context?: Context, session?: ResolutionSession, source?: InvocationSource): AsyncProxy<T>;
|