@middy/util 4.5.5 → 4.6.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.
package/index.cjs CHANGED
@@ -130,7 +130,8 @@ const sanitizeKey = (key)=>{
130
130
  };
131
131
  const cache = {};
132
132
  const processCache = (options, fetch = ()=>undefined, request)=>{
133
- const { cacheExpiry, cacheKey } = options;
133
+ let { cacheKey, cacheKeyExpiry, cacheExpiry } = options;
134
+ cacheExpiry = cacheKeyExpiry?.[cacheKey] ?? cacheExpiry;
134
135
  if (cacheExpiry) {
135
136
  const cached = getCache(cacheKey);
136
137
  const unexpired = cached.expiry && (cacheExpiry < 0 || cached.expiry > Date.now());
@@ -153,9 +154,11 @@ const processCache = (options, fetch = ()=>undefined, request)=>{
153
154
  }
154
155
  }
155
156
  const value = fetch(request);
156
- const expiry = Date.now() + cacheExpiry;
157
+ const now = Date.now();
158
+ const expiry = cacheExpiry > 86400000 ? cacheExpiry : now + cacheExpiry;
159
+ const duration = cacheExpiry > 86400000 ? cacheExpiry - now : cacheExpiry;
157
160
  if (cacheExpiry) {
158
- const refresh = cacheExpiry > 0 ? setInterval(()=>processCache(options, fetch, request), cacheExpiry) : undefined;
161
+ const refresh = duration > 0 ? setInterval(()=>processCache(options, fetch, request), duration) : undefined;
159
162
  cache[cacheKey] = {
160
163
  value,
161
164
  expiry,
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import middy from '@middy/core'
2
2
 
3
3
  interface Options<Client, ClientOptions> {
4
- AwsClient?: new (...args: any[]) => Client
4
+ AwsClient?: new (...[config]: [any] | any) => Client
5
5
  awsClientOptions?: Partial<ClientOptions>
6
6
  awsClientAssumeRole?: string
7
7
  awsClientCapture?: (service: Client) => Client
package/index.js CHANGED
@@ -76,7 +76,8 @@ export const sanitizeKey = (key)=>{
76
76
  };
77
77
  const cache = {};
78
78
  export const processCache = (options, fetch = ()=>undefined, request)=>{
79
- const { cacheExpiry, cacheKey } = options;
79
+ let { cacheKey, cacheKeyExpiry, cacheExpiry } = options;
80
+ cacheExpiry = cacheKeyExpiry?.[cacheKey] ?? cacheExpiry;
80
81
  if (cacheExpiry) {
81
82
  const cached = getCache(cacheKey);
82
83
  const unexpired = cached.expiry && (cacheExpiry < 0 || cached.expiry > Date.now());
@@ -99,9 +100,11 @@ export const processCache = (options, fetch = ()=>undefined, request)=>{
99
100
  }
100
101
  }
101
102
  const value = fetch(request);
102
- const expiry = Date.now() + cacheExpiry;
103
+ const now = Date.now();
104
+ const expiry = cacheExpiry > 86400000 ? cacheExpiry : now + cacheExpiry;
105
+ const duration = cacheExpiry > 86400000 ? cacheExpiry - now : cacheExpiry;
103
106
  if (cacheExpiry) {
104
- const refresh = cacheExpiry > 0 ? setInterval(()=>processCache(options, fetch, request), cacheExpiry) : undefined;
107
+ const refresh = duration > 0 ? setInterval(()=>processCache(options, fetch, request), duration) : undefined;
105
108
  cache[cacheKey] = {
106
109
  value,
107
110
  expiry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/util",
3
- "version": "4.5.5",
3
+ "version": "4.6.1",
4
4
  "description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@aws-sdk/client-ssm": "^3.0.0",
64
- "@middy/core": "4.5.5",
64
+ "@middy/core": "4.6.1",
65
65
  "@types/aws-lambda": "^8.10.76",
66
66
  "@types/node": "^20.0.0",
67
67
  "aws-xray-sdk": "^3.3.3"
@@ -71,5 +71,5 @@
71
71
  "type": "github",
72
72
  "url": "https://github.com/sponsors/willfarrell"
73
73
  },
74
- "gitHead": "e8458a63a1b10932c30556cd8e2bdc4775858d0b"
74
+ "gitHead": "253ed0e4ca95623decbade03938a07d837a1eba2"
75
75
  }