@middy/util 5.5.0 → 6.0.0-alpha.0
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.js +11 -4
- package/package.json +6 -3
package/index.js
CHANGED
|
@@ -102,7 +102,11 @@ export const sanitizeKey = (key) => {
|
|
|
102
102
|
|
|
103
103
|
// fetch Cache
|
|
104
104
|
const cache = {} // key: { value:{fetchKey:Promise}, expiry }
|
|
105
|
-
export const processCache = (
|
|
105
|
+
export const processCache = (
|
|
106
|
+
options,
|
|
107
|
+
middlewareFetch = () => undefined,
|
|
108
|
+
request
|
|
109
|
+
) => {
|
|
106
110
|
let { cacheKey, cacheKeyExpiry, cacheExpiry } = options
|
|
107
111
|
cacheExpiry = cacheKeyExpiry?.[cacheKey] ?? cacheExpiry
|
|
108
112
|
const now = Date.now()
|
|
@@ -112,7 +116,7 @@ export const processCache = (options, fetch = () => undefined, request) => {
|
|
|
112
116
|
|
|
113
117
|
if (unexpired) {
|
|
114
118
|
if (cached.modified) {
|
|
115
|
-
const value =
|
|
119
|
+
const value = middlewareFetch(request, cached.value)
|
|
116
120
|
Object.assign(cached.value, value)
|
|
117
121
|
cache[cacheKey] = { value: cached.value, expiry: cached.expiry }
|
|
118
122
|
return cache[cacheKey]
|
|
@@ -120,14 +124,17 @@ export const processCache = (options, fetch = () => undefined, request) => {
|
|
|
120
124
|
return { ...cached, cache: true }
|
|
121
125
|
}
|
|
122
126
|
}
|
|
123
|
-
const value =
|
|
127
|
+
const value = middlewareFetch(request)
|
|
124
128
|
// secrets-manager can override to unix timestamp
|
|
125
129
|
const expiry = cacheExpiry > 86400000 ? cacheExpiry : now + cacheExpiry
|
|
126
130
|
const duration = cacheExpiry > 86400000 ? cacheExpiry - now : cacheExpiry
|
|
127
131
|
if (cacheExpiry) {
|
|
128
132
|
const refresh =
|
|
129
133
|
duration > 0
|
|
130
|
-
? setTimeout(
|
|
134
|
+
? setTimeout(
|
|
135
|
+
() => processCache(options, middlewareFetch, request),
|
|
136
|
+
duration
|
|
137
|
+
)
|
|
131
138
|
: undefined
|
|
132
139
|
cache[cacheKey] = { value, expiry, refresh }
|
|
133
140
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/util",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha.0",
|
|
4
4
|
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=20"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"import": {
|
|
17
17
|
"types": "./index.d.ts",
|
|
18
18
|
"default": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"default": "./index.js"
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
},
|
|
@@ -55,7 +58,7 @@
|
|
|
55
58
|
},
|
|
56
59
|
"devDependencies": {
|
|
57
60
|
"@aws-sdk/client-ssm": "^3.0.0",
|
|
58
|
-
"@middy/core": "
|
|
61
|
+
"@middy/core": "6.0.0-alpha.0",
|
|
59
62
|
"@types/aws-lambda": "^8.10.76",
|
|
60
63
|
"@types/node": "^20.0.0",
|
|
61
64
|
"aws-xray-sdk": "^3.3.3"
|