@middy/util 3.2.0 → 3.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.cjs +27 -20
  2. package/index.js +3 -3
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -2,8 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.createError = exports.normalizeHttpResponse = exports.jsonSafeStringify = exports.jsonSafeParse = exports.clearCache = exports.modifyCache = exports.getCache = exports.processCache = exports.sanitizeKey = exports.getInternal = exports.canPrefetch = exports.createClient = exports.createPrefetchClient = exports.awsClientDefaultOptions = void 0;
6
- var _https = require("https");
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ awsClientDefaultOptions: ()=>awsClientDefaultOptions,
13
+ createPrefetchClient: ()=>createPrefetchClient,
14
+ createClient: ()=>createClient,
15
+ canPrefetch: ()=>canPrefetch,
16
+ getInternal: ()=>getInternal,
17
+ sanitizeKey: ()=>sanitizeKey,
18
+ processCache: ()=>processCache,
19
+ getCache: ()=>getCache,
20
+ modifyCache: ()=>modifyCache,
21
+ clearCache: ()=>clearCache,
22
+ jsonSafeParse: ()=>jsonSafeParse,
23
+ jsonSafeStringify: ()=>jsonSafeStringify,
24
+ normalizeHttpResponse: ()=>normalizeHttpResponse,
25
+ HttpError: ()=>HttpError,
26
+ createError: ()=>createError
27
+ });
28
+ const _https = require("https");
7
29
  var _response;
8
30
  const awsClientDefaultOptions = {
9
31
  httpOptions: {
@@ -13,7 +35,6 @@ const awsClientDefaultOptions = {
13
35
  })
14
36
  }
15
37
  };
16
- exports.awsClientDefaultOptions = awsClientDefaultOptions;
17
38
  const createPrefetchClient = (options)=>{
18
39
  const awsClientOptions = {
19
40
  ...awsClientDefaultOptions,
@@ -27,7 +48,6 @@ const createPrefetchClient = (options)=>{
27
48
  }
28
49
  return client;
29
50
  };
30
- exports.createPrefetchClient = createPrefetchClient;
31
51
  const createClient = async (options, request)=>{
32
52
  let awsClientCredentials = {};
33
53
  if (options.awsClientAssumeRole) {
@@ -47,11 +67,9 @@ const createClient = async (options, request)=>{
47
67
  awsClientOptions: awsClientCredentials
48
68
  });
49
69
  };
50
- exports.createClient = createClient;
51
70
  const canPrefetch = (options = {})=>{
52
71
  return !options.awsClientAssumeRole && !options.disablePrefetch;
53
72
  };
54
- exports.canPrefetch = canPrefetch;
55
73
  const getInternal = async (variables, request)=>{
56
74
  if (!variables || !request) return {};
57
75
  let keys = [];
@@ -90,14 +108,12 @@ const getInternal = async (variables, request)=>{
90
108
  [sanitizeKey(key)]: values[index].value
91
109
  }), {});
92
110
  };
93
- exports.getInternal = getInternal;
94
111
  const isPromise = (promise)=>typeof promise?.then === 'function';
95
112
  const sanitizeKeyPrefixLeadingNumber = /^([0-9])/;
96
113
  const sanitizeKeyRemoveDisallowedChar = /[^a-zA-Z0-9]+/g;
97
114
  const sanitizeKey = (key)=>{
98
115
  return key.replace(sanitizeKeyPrefixLeadingNumber, '_$1').replace(sanitizeKeyRemoveDisallowedChar, '_');
99
116
  };
100
- exports.sanitizeKey = sanitizeKey;
101
117
  const cache = {};
102
118
  const processCache = (options, fetch = ()=>undefined, request)=>{
103
119
  const { cacheExpiry , cacheKey } = options;
@@ -122,25 +138,23 @@ const processCache = (options, fetch = ()=>undefined, request)=>{
122
138
  };
123
139
  }
124
140
  }
125
- const value = fetch(request);
141
+ const value1 = fetch(request);
126
142
  const expiry = Date.now() + cacheExpiry;
127
143
  if (cacheExpiry) {
128
144
  cache[cacheKey] = {
129
- value,
145
+ value: value1,
130
146
  expiry
131
147
  };
132
148
  }
133
149
  return {
134
- value,
150
+ value: value1,
135
151
  expiry
136
152
  };
137
153
  };
138
- exports.processCache = processCache;
139
154
  const getCache = (key)=>{
140
155
  if (!cache[key]) return {};
141
156
  return cache[key];
142
157
  };
143
- exports.getCache = getCache;
144
158
  const modifyCache = (cacheKey, value)=>{
145
159
  if (!cache[cacheKey]) return;
146
160
  cache[cacheKey] = {
@@ -149,7 +163,6 @@ const modifyCache = (cacheKey, value)=>{
149
163
  modified: true
150
164
  };
151
165
  };
152
- exports.modifyCache = modifyCache;
153
166
  const clearCache = (keys = null)=>{
154
167
  keys = keys ?? Object.keys(cache);
155
168
  if (!Array.isArray(keys)) keys = [
@@ -159,7 +172,6 @@ const clearCache = (keys = null)=>{
159
172
  cache[cacheKey] = undefined;
160
173
  }
161
174
  };
162
- exports.clearCache = clearCache;
163
175
  const jsonSafeParse = (text, reviver)=>{
164
176
  if (typeof text !== 'string') return text;
165
177
  const firstChar = text[0];
@@ -169,14 +181,12 @@ const jsonSafeParse = (text, reviver)=>{
169
181
  } catch (e) {}
170
182
  return text;
171
183
  };
172
- exports.jsonSafeParse = jsonSafeParse;
173
184
  const jsonSafeStringify = (value, replacer, space)=>{
174
185
  try {
175
186
  return JSON.stringify(value, replacer, space);
176
187
  } catch (e) {}
177
188
  return value;
178
189
  };
179
- exports.jsonSafeStringify = jsonSafeStringify;
180
190
  const normalizeHttpResponse = (request)=>{
181
191
  let { response } = request;
182
192
  if (typeof response === 'undefined') {
@@ -190,7 +200,6 @@ const normalizeHttpResponse = (request)=>{
190
200
  request.response = response;
191
201
  return response;
192
202
  };
193
- exports.normalizeHttpResponse = normalizeHttpResponse;
194
203
  const createErrorRegexp = /[^a-zA-Z]/g;
195
204
  class HttpError extends Error {
196
205
  constructor(code, message, options = {}){
@@ -207,11 +216,9 @@ class HttpError extends Error {
207
216
  this.expose = options.expose ?? code < 500;
208
217
  }
209
218
  }
210
- exports.HttpError = HttpError;
211
219
  const createError = (code, message, properties = {})=>{
212
220
  return new HttpError(code, message, properties);
213
221
  };
214
- exports.createError = createError;
215
222
  const httpErrorCodes = {
216
223
  100: 'Continue',
217
224
  101: 'Switching Protocols',
package/index.js CHANGED
@@ -111,16 +111,16 @@ export const processCache = (options, fetch = ()=>undefined, request)=>{
111
111
  };
112
112
  }
113
113
  }
114
- const value = fetch(request);
114
+ const value1 = fetch(request);
115
115
  const expiry = Date.now() + cacheExpiry;
116
116
  if (cacheExpiry) {
117
117
  cache[cacheKey] = {
118
- value,
118
+ value: value1,
119
119
  expiry
120
120
  };
121
121
  }
122
122
  return {
123
- value,
123
+ value: value1,
124
124
  expiry
125
125
  };
126
126
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/util",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -60,12 +60,12 @@
60
60
  "url": "https://github.com/middyjs/middy/issues"
61
61
  },
62
62
  "devDependencies": {
63
- "@middy/core": "3.2.0",
63
+ "@middy/core": "3.2.1",
64
64
  "@types/aws-lambda": "^8.10.76",
65
65
  "@types/node": "^18.0.0",
66
66
  "aws-sdk": "^2.939.0",
67
67
  "aws-xray-sdk": "^3.3.3"
68
68
  },
69
69
  "homepage": "https://middy.js.org",
70
- "gitHead": "ac46270daa388b52a81472ae8f9b8808a0136940"
70
+ "gitHead": "b4169ec20b798650e934a7c25ee80ae98d11e03a"
71
71
  }