1 | import middy from '@middy/core'
|
2 | import { Options as MiddyOptions } from '@middy/util'
|
3 | import { Context as LambdaContext } from 'aws-lambda'
|
4 | import {
|
5 | ServiceDiscoveryClient,
|
6 | ServiceDiscoveryClientConfig,
|
7 | DiscoverInstancesCommandInput,
|
8 | HttpInstanceSummary
|
9 | } from '@aws-sdk/client-servicediscovery'
|
10 |
|
11 | interface ServiceDiscoveryOptions<AwsServiceDiscoveryClient = ServiceDiscoveryClient>
|
12 | extends Pick<
|
13 | MiddyOptions<
|
14 | AwsServiceDiscoveryClient,
|
15 | ServiceDiscoveryClientConfig
|
16 | >,
|
17 | | 'AwsClient'
|
18 | | 'awsClientOptions'
|
19 | | 'awsClientCapture'
|
20 | | 'disablePrefetch'
|
21 | | 'cacheKey'
|
22 | | 'cacheExpiry'
|
23 | | 'setToContext'
|
24 | > {
|
25 | fetchData?: { [key: string]: DiscoverInstancesCommandInput }
|
26 | }
|
27 |
|
28 | export type Context<TOptions extends ServiceDiscoveryOptions | undefined> =
|
29 | TOptions extends { setToContext: true }
|
30 | ? TOptions extends { fetchData: infer TFetchData }
|
31 | ? LambdaContext & {
|
32 | [Key in keyof TFetchData]: HttpInstanceSummary[]
|
33 | }
|
34 | : never
|
35 | : LambdaContext
|
36 |
|
37 | export type Internal<TOptions extends ServiceDiscoveryOptions | undefined> =
|
38 | TOptions extends ServiceDiscoveryOptions
|
39 | ? TOptions extends { fetchData: infer TFetchData }
|
40 | ? {
|
41 | [Key in keyof TFetchData]: HttpInstanceSummary[]
|
42 | }
|
43 | : {}
|
44 | : {}
|
45 |
|
46 | declare function serviceDiscovery<TOptions extends ServiceDiscoveryOptions | undefined> (
|
47 | options?: TOptions
|
48 | ): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>, Internal<TOptions>>
|
49 |
|
50 | export default serviceDiscovery
|
51 |
|
\ | No newline at end of file |