@middy/service-discovery 6.1.6 → 6.2.1

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.
Files changed (3) hide show
  1. package/index.d.ts +48 -42
  2. package/index.js +65 -65
  3. package/package.json +71 -74
package/index.d.ts CHANGED
@@ -1,50 +1,56 @@
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'
1
+ import type {
2
+ DiscoverInstancesCommandInput,
3
+ HttpInstanceSummary,
4
+ ServiceDiscoveryClient,
5
+ ServiceDiscoveryClientConfig,
6
+ } from "@aws-sdk/client-servicediscovery";
7
+ import type middy from "@middy/core";
8
+ import type { Options as MiddyOptions } from "@middy/util";
9
+ import type { Context as LambdaContext } from "aws-lambda";
10
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 }
11
+ interface ServiceDiscoveryOptions<
12
+ AwsServiceDiscoveryClient = ServiceDiscoveryClient,
13
+ > extends Pick<
14
+ MiddyOptions<AwsServiceDiscoveryClient, ServiceDiscoveryClientConfig>,
15
+ | "AwsClient"
16
+ | "awsClientOptions"
17
+ | "awsClientCapture"
18
+ | "disablePrefetch"
19
+ | "cacheKey"
20
+ | "cacheExpiry"
21
+ | "setToContext"
22
+ > {
23
+ fetchData?: { [key: string]: DiscoverInstancesCommandInput };
26
24
  }
27
25
 
28
26
  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
27
+ TOptions extends { setToContext: true }
28
+ ? TOptions extends { fetchData: infer TFetchData }
29
+ ? LambdaContext & {
30
+ [Key in keyof TFetchData]: HttpInstanceSummary[];
31
+ }
32
+ : never
33
+ : LambdaContext;
36
34
 
37
35
  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
- : {}
36
+ TOptions extends ServiceDiscoveryOptions
37
+ ? TOptions extends { fetchData: infer TFetchData }
38
+ ? {
39
+ [Key in keyof TFetchData]: HttpInstanceSummary[];
40
+ }
41
+ : {}
42
+ : {};
45
43
 
46
- declare function serviceDiscovery<TOptions extends ServiceDiscoveryOptions | undefined> (
47
- options?: TOptions
48
- ): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>, Internal<TOptions>>
44
+ declare function serviceDiscovery<
45
+ TOptions extends ServiceDiscoveryOptions | undefined,
46
+ >(
47
+ options?: TOptions,
48
+ ): middy.MiddlewareObj<
49
+ unknown,
50
+ any,
51
+ Error,
52
+ Context<TOptions>,
53
+ Internal<TOptions>
54
+ >;
49
55
 
50
- export default serviceDiscovery
56
+ export default serviceDiscovery;
package/index.js CHANGED
@@ -1,81 +1,81 @@
1
1
  import {
2
- canPrefetch,
3
- createPrefetchClient,
4
- createClient,
5
- getCache,
6
- getInternal,
7
- processCache,
8
- modifyCache,
9
- catchInvalidSignatureException
10
- } from '@middy/util'
2
+ DiscoverInstancesCommand,
3
+ ServiceDiscoveryClient,
4
+ } from "@aws-sdk/client-servicediscovery";
11
5
  import {
12
- ServiceDiscoveryClient,
13
- DiscoverInstancesCommand
14
- } from '@aws-sdk/client-servicediscovery'
6
+ canPrefetch,
7
+ catchInvalidSignatureException,
8
+ createClient,
9
+ createPrefetchClient,
10
+ getCache,
11
+ getInternal,
12
+ modifyCache,
13
+ processCache,
14
+ } from "@middy/util";
15
15
 
16
16
  const defaults = {
17
- AwsClient: ServiceDiscoveryClient,
18
- awsClientOptions: {},
19
- awsClientAssumeRole: undefined,
20
- awsClientCapture: undefined,
21
- fetchData: {}, // { contextKey: {NamespaceName, ServiceName, HealthStatus} }
22
- disablePrefetch: false,
23
- cacheKey: 'cloud-map',
24
- cacheKeyExpiry: {},
25
- cacheExpiry: -1,
26
- setToContext: false
27
- }
17
+ AwsClient: ServiceDiscoveryClient,
18
+ awsClientOptions: {},
19
+ awsClientAssumeRole: undefined,
20
+ awsClientCapture: undefined,
21
+ fetchData: {}, // { contextKey: {NamespaceName, ServiceName, HealthStatus} }
22
+ disablePrefetch: false,
23
+ cacheKey: "cloud-map",
24
+ cacheKeyExpiry: {},
25
+ cacheExpiry: -1,
26
+ setToContext: false,
27
+ };
28
28
 
29
29
  const serviceDiscoveryMiddleware = (opts = {}) => {
30
- const options = { ...defaults, ...opts }
30
+ const options = { ...defaults, ...opts };
31
31
 
32
- const fetchRequest = (request, cachedValues = {}) => {
33
- const values = {}
32
+ const fetchRequest = (request, cachedValues = {}) => {
33
+ const values = {};
34
34
 
35
- for (const internalKey of Object.keys(options.fetchData)) {
36
- if (cachedValues[internalKey]) continue
35
+ for (const internalKey of Object.keys(options.fetchData)) {
36
+ if (cachedValues[internalKey]) continue;
37
37
 
38
- const command = new DiscoverInstancesCommand(
39
- options.fetchData[internalKey]
40
- )
41
- values[internalKey] = client
42
- .send(command)
43
- .catch((e) => catchInvalidSignatureException(e, client, command))
44
- .then((resp) => resp.Instances)
45
- .catch((e) => {
46
- const value = getCache(options.cacheKey).value ?? {}
47
- value[internalKey] = undefined
48
- modifyCache(options.cacheKey, value)
49
- throw e
50
- })
51
- }
38
+ const command = new DiscoverInstancesCommand(
39
+ options.fetchData[internalKey],
40
+ );
41
+ values[internalKey] = client
42
+ .send(command)
43
+ .catch((e) => catchInvalidSignatureException(e, client, command))
44
+ .then((resp) => resp.Instances)
45
+ .catch((e) => {
46
+ const value = getCache(options.cacheKey).value ?? {};
47
+ value[internalKey] = undefined;
48
+ modifyCache(options.cacheKey, value);
49
+ throw e;
50
+ });
51
+ }
52
52
 
53
- return values
54
- }
53
+ return values;
54
+ };
55
55
 
56
- let client
57
- if (canPrefetch(options)) {
58
- client = createPrefetchClient(options)
59
- processCache(options, fetchRequest)
60
- }
56
+ let client;
57
+ if (canPrefetch(options)) {
58
+ client = createPrefetchClient(options);
59
+ processCache(options, fetchRequest);
60
+ }
61
61
 
62
- const serviceDiscoveryMiddlewareBefore = async (request) => {
63
- if (!client) {
64
- client = await createClient(options, request)
65
- }
62
+ const serviceDiscoveryMiddlewareBefore = async (request) => {
63
+ if (!client) {
64
+ client = await createClient(options, request);
65
+ }
66
66
 
67
- const { value } = processCache(options, fetchRequest, request)
67
+ const { value } = processCache(options, fetchRequest, request);
68
68
 
69
- Object.assign(request.internal, value)
69
+ Object.assign(request.internal, value);
70
70
 
71
- if (options.setToContext) {
72
- const data = await getInternal(Object.keys(options.fetchData), request)
73
- if (options.setToContext) Object.assign(request.context, data)
74
- }
75
- }
71
+ if (options.setToContext) {
72
+ const data = await getInternal(Object.keys(options.fetchData), request);
73
+ if (options.setToContext) Object.assign(request.context, data);
74
+ }
75
+ };
76
76
 
77
- return {
78
- before: serviceDiscoveryMiddlewareBefore
79
- }
80
- }
81
- export default serviceDiscoveryMiddleware
77
+ return {
78
+ before: serviceDiscoveryMiddlewareBefore,
79
+ };
80
+ };
81
+ export default serviceDiscoveryMiddleware;
package/package.json CHANGED
@@ -1,76 +1,73 @@
1
1
  {
2
- "name": "@middy/service-discovery",
3
- "version": "6.1.6",
4
- "description": "Service Discovery (Cloud Map) instances middleware for the middy framework",
5
- "type": "module",
6
- "engines": {
7
- "node": ">=20"
8
- },
9
- "engineStrict": true,
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "module": "./index.js",
14
- "exports": {
15
- ".": {
16
- "import": {
17
- "types": "./index.d.ts",
18
- "default": "./index.js"
19
- },
20
- "require": {
21
- "default": "./index.js"
22
- }
23
- }
24
- },
25
- "types": "index.d.ts",
26
- "files": [
27
- "index.js",
28
- "index.d.ts"
29
- ],
30
- "scripts": {
31
- "test": "npm run test:unit && npm run test:fuzz",
32
- "test:unit": "node --test __tests__/index.js",
33
- "test:fuzz": "node --test __tests__/fuzz.js",
34
- "test:benchmark": "node __benchmarks__/index.js"
35
- },
36
- "license": "MIT",
37
- "keywords": [
38
- "Lambda",
39
- "Middleware",
40
- "Serverless",
41
- "Framework",
42
- "AWS",
43
- "AWS Lambda",
44
- "Middy",
45
- "Service Discovery",
46
- "SCloud Map",
47
- "Instances"
48
- ],
49
- "author": {
50
- "name": "Middy contributors",
51
- "url": "https://github.com/middyjs/middy/graphs/contributors"
52
- },
53
- "repository": {
54
- "type": "git",
55
- "url": "git+https://github.com/middyjs/middy.git",
56
- "directory": "packages/sts"
57
- },
58
- "bugs": {
59
- "url": "https://github.com/middyjs/middy/issues"
60
- },
61
- "homepage": "https://middy.js.org",
62
- "funding": {
63
- "type": "github",
64
- "url": "https://github.com/sponsors/willfarrell"
65
- },
66
- "dependencies": {
67
- "@middy/util": "6.1.6"
68
- },
69
- "devDependencies": {
70
- "@aws-sdk/client-servicediscovery": "^3.0.0",
71
- "@middy/core": "6.1.6",
72
- "@types/aws-lambda": "^8.10.101",
73
- "aws-xray-sdk": "^3.3.3"
74
- },
75
- "gitHead": "b84840ec8afd289f6decfd0d645be4899051792d"
2
+ "name": "@middy/service-discovery",
3
+ "version": "6.2.1",
4
+ "description": "Service Discovery (Cloud Map) instances middleware for the middy framework",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
9
+ "engineStrict": true,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "module": "./index.js",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./index.d.ts",
18
+ "default": "./index.js"
19
+ },
20
+ "require": {
21
+ "default": "./index.js"
22
+ }
23
+ }
24
+ },
25
+ "types": "index.d.ts",
26
+ "files": ["index.js", "index.d.ts"],
27
+ "scripts": {
28
+ "test": "npm run test:unit && npm run test:fuzz",
29
+ "test:unit": "node --test",
30
+ "test:fuzz": "node --test index.fuzz.js",
31
+ "test:perf": "node --test index.perf.js"
32
+ },
33
+ "license": "MIT",
34
+ "keywords": [
35
+ "Lambda",
36
+ "Middleware",
37
+ "Serverless",
38
+ "Framework",
39
+ "AWS",
40
+ "AWS Lambda",
41
+ "Middy",
42
+ "Service Discovery",
43
+ "SCloud Map",
44
+ "Instances"
45
+ ],
46
+ "author": {
47
+ "name": "Middy contributors",
48
+ "url": "https://github.com/middyjs/middy/graphs/contributors"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/middyjs/middy.git",
53
+ "directory": "packages/sts"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/middyjs/middy/issues"
57
+ },
58
+ "homepage": "https://middy.js.org",
59
+ "funding": {
60
+ "type": "github",
61
+ "url": "https://github.com/sponsors/willfarrell"
62
+ },
63
+ "dependencies": {
64
+ "@middy/util": "6.2.1"
65
+ },
66
+ "devDependencies": {
67
+ "@aws-sdk/client-servicediscovery": "^3.0.0",
68
+ "@middy/core": "6.2.1",
69
+ "@types/aws-lambda": "^8.10.101",
70
+ "aws-xray-sdk": "^3.3.3"
71
+ },
72
+ "gitHead": "b84840ec8afd289f6decfd0d645be4899051792d"
76
73
  }