|
1 |
| -import type { ConfigServiceInterface } from '../config'; |
2 |
| -import type { Handler } from 'aws-lambda'; |
3 |
| -import type { |
4 |
| - AsyncHandler, |
5 |
| - LambdaInterface, |
6 |
| - SyncHandler, |
7 |
| -} from '@aws-lambda-powertools/commons/types'; |
| 1 | +import type { ConfigServiceInterface } from './ConfigServiceInterface.js'; |
| 2 | +import type { HandlerMethodDecorator } from '@aws-lambda-powertools/commons/types'; |
| 3 | +import type { Segment, Subsegment } from 'aws-xray-sdk-core'; |
8 | 4 |
|
9 | 5 | /**
|
10 | 6 | * Options for the tracer class to be used during initialization.
|
@@ -100,28 +96,51 @@ type CaptureMethodOptions = {
|
100 | 96 | captureResponse?: boolean;
|
101 | 97 | };
|
102 | 98 |
|
103 |
| -type HandlerMethodDecorator = ( |
104 |
| - target: LambdaInterface, |
| 99 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 100 | +type AnyClassMethod = (...args: any[]) => any; |
| 101 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 102 | +type AnyClass = new (...args: any[]) => any; |
| 103 | + |
| 104 | +type MethodDecorator<T extends AnyClass> = ( |
| 105 | + target: InstanceType<T>, |
105 | 106 | propertyKey: string | symbol,
|
106 |
| - descriptor: |
107 |
| - | TypedPropertyDescriptor<SyncHandler<Handler>> |
108 |
| - | TypedPropertyDescriptor<AsyncHandler<Handler>> |
| 107 | + descriptor: TypedPropertyDescriptor<AnyClassMethod> |
109 | 108 | ) => void;
|
110 | 109 |
|
111 |
| -// TODO: Revisit type below & make it more specific |
112 |
| -type MethodDecorator = ( |
113 |
| - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
114 |
| - target: any, |
115 |
| - propertyKey: string | symbol, |
116 |
| - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
117 |
| - descriptor: TypedPropertyDescriptor<any> |
118 |
| - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
119 |
| -) => any; |
| 110 | +interface TracerInterface { |
| 111 | + addErrorAsMetadata(error: Error, remote?: boolean): void; |
| 112 | + addResponseAsMetadata(data?: unknown, methodName?: string): void; |
| 113 | + addServiceNameAnnotation(): void; |
| 114 | + annotateColdStart(): void; |
| 115 | + captureAWS<T>(aws: T): void | T; |
| 116 | + captureAWSv3Client<T>(service: T): void | T; |
| 117 | + captureAWSClient<T>(service: T): void | T; |
| 118 | + captureLambdaHandler( |
| 119 | + options?: CaptureLambdaHandlerOptions |
| 120 | + ): HandlerMethodDecorator; |
| 121 | + captureMethod<T extends AnyClass>( |
| 122 | + options?: CaptureMethodOptions |
| 123 | + ): MethodDecorator<T>; |
| 124 | + getSegment(): Segment | Subsegment | undefined; |
| 125 | + getRootXrayTraceId(): string | undefined; |
| 126 | + isTraceSampled(): boolean; |
| 127 | + isTracingEnabled(): boolean; |
| 128 | + putAnnotation: (key: string, value: string | number | boolean) => void; |
| 129 | + putMetadata: ( |
| 130 | + key: string, |
| 131 | + value: unknown, |
| 132 | + namespace?: string | undefined |
| 133 | + ) => void; |
| 134 | + setSegment(segment: Segment | Subsegment): void; |
| 135 | +} |
120 | 136 |
|
121 | 137 | export {
|
122 | 138 | TracerOptions,
|
123 | 139 | CaptureLambdaHandlerOptions,
|
124 | 140 | CaptureMethodOptions,
|
125 | 141 | HandlerMethodDecorator,
|
| 142 | + AnyClass, |
| 143 | + AnyClassMethod, |
126 | 144 | MethodDecorator,
|
| 145 | + TracerInterface, |
127 | 146 | };
|
0 commit comments