@middy/util 7.3.2 → 7.3.4
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.d.ts +3 -0
- package/index.js +27 -6
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -206,6 +206,9 @@ export type NumberRule = {
|
|
|
206
206
|
type: "number" | "integer";
|
|
207
207
|
minimum?: number;
|
|
208
208
|
maximum?: number;
|
|
209
|
+
exclusiveMinimum?: number;
|
|
210
|
+
exclusiveMaximum?: number;
|
|
211
|
+
multipleOf?: number;
|
|
209
212
|
enum?: readonly number[];
|
|
210
213
|
examples?: readonly number[];
|
|
211
214
|
};
|
package/index.js
CHANGED
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
// `items` is applied to each array element. It can be a type string,
|
|
12
12
|
// a predicate function, or a plain object treated as a per-element
|
|
13
13
|
// object schema (validated recursively with the same rules).
|
|
14
|
-
// { type: '<type>' | '<type>?', minimum?, maximum?,
|
|
15
|
-
//
|
|
14
|
+
// { type: '<type>' | '<type>?', minimum?, maximum?, exclusiveMinimum?,
|
|
15
|
+
// exclusiveMaximum?, multipleOf?, minLength?, maxLength?, pattern? }
|
|
16
|
+
// Numeric: `minimum`/`maximum` (inclusive), `exclusiveMinimum`/
|
|
17
|
+
// `exclusiveMaximum` (exclusive), `multipleOf` (number/integer).
|
|
16
18
|
// String: `minLength`/`maxLength` (string length), `pattern` (regex source).
|
|
17
19
|
// { type: 'object' | 'object?', properties?: {...}, additionalProperties?: <rule> }
|
|
18
20
|
// `properties` validates known keys with the flat-schema form.
|
|
@@ -24,6 +26,10 @@
|
|
|
24
26
|
// combine with `type` to require a specific type and/or presence.
|
|
25
27
|
// Keys in `options` (or nested objects) that are not in `schema` throw,
|
|
26
28
|
// catching typos.
|
|
29
|
+
|
|
30
|
+
const name = "util";
|
|
31
|
+
const pkg = `@middy/${name}`;
|
|
32
|
+
|
|
27
33
|
const validateOptionsTypeCheckers = {
|
|
28
34
|
string: (v) => typeof v === "string",
|
|
29
35
|
number: (v) => typeof v === "number" && !Number.isNaN(v),
|
|
@@ -182,6 +188,9 @@ const checkRule = (rule, value, path, fail) => {
|
|
|
182
188
|
additionalProperties,
|
|
183
189
|
minimum,
|
|
184
190
|
maximum,
|
|
191
|
+
exclusiveMinimum,
|
|
192
|
+
exclusiveMaximum,
|
|
193
|
+
multipleOf,
|
|
185
194
|
pattern,
|
|
186
195
|
minLength,
|
|
187
196
|
maxLength,
|
|
@@ -194,7 +203,19 @@ const checkRule = (rule, value, path, fail) => {
|
|
|
194
203
|
if (maximum !== undefined && value > maximum) {
|
|
195
204
|
fail(`Option '${path}' must be <= ${maximum}`);
|
|
196
205
|
}
|
|
197
|
-
if (
|
|
206
|
+
if (exclusiveMinimum !== undefined && value <= exclusiveMinimum) {
|
|
207
|
+
fail(`Option '${path}' must be > ${exclusiveMinimum}`);
|
|
208
|
+
}
|
|
209
|
+
if (exclusiveMaximum !== undefined && value >= exclusiveMaximum) {
|
|
210
|
+
fail(`Option '${path}' must be < ${exclusiveMaximum}`);
|
|
211
|
+
}
|
|
212
|
+
if (multipleOf !== undefined) {
|
|
213
|
+
const quotient = value / multipleOf;
|
|
214
|
+
if (!Number.isFinite(quotient) || Math.floor(quotient) !== quotient) {
|
|
215
|
+
fail(`Option '${path}' must be a multiple of ${multipleOf}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (pattern !== undefined && !pattern.test(value)) {
|
|
198
219
|
fail(`Option '${path}' must match pattern ${pattern}`);
|
|
199
220
|
}
|
|
200
221
|
if (minLength !== undefined && value.length < minLength) {
|
|
@@ -298,7 +319,7 @@ export const createClient = async (options, request) => {
|
|
|
298
319
|
if (options.awsClientAssumeRole) {
|
|
299
320
|
if (!request) {
|
|
300
321
|
throw new Error("Request required when assuming role", {
|
|
301
|
-
cause: { package:
|
|
322
|
+
cause: { package: pkg },
|
|
302
323
|
});
|
|
303
324
|
}
|
|
304
325
|
awsClientCredentials = await getInternal(
|
|
@@ -398,7 +419,7 @@ export const getInternal = async (variables, request) => {
|
|
|
398
419
|
}
|
|
399
420
|
if (errors) {
|
|
400
421
|
throw new Error("Failed to resolve internal values", {
|
|
401
|
-
cause: { package:
|
|
422
|
+
cause: { package: pkg, data: errors },
|
|
402
423
|
});
|
|
403
424
|
}
|
|
404
425
|
return obj;
|
|
@@ -429,7 +450,7 @@ const validateCacheExpiry = (cacheExpiry) => {
|
|
|
429
450
|
) {
|
|
430
451
|
throw new Error(
|
|
431
452
|
`Invalid cacheExpiry value: ${cacheExpiry}. Must be -1 (infinite), 0 (disabled), or a positive number (ms duration or unix timestamp)`,
|
|
432
|
-
{ cause: { package:
|
|
453
|
+
{ cause: { package: pkg } },
|
|
433
454
|
);
|
|
434
455
|
}
|
|
435
456
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/util",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.4",
|
|
4
4
|
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@aws-sdk/client-ssm": "^3.0.0",
|
|
60
|
-
"@middy/core": "7.3.
|
|
60
|
+
"@middy/core": "7.3.4",
|
|
61
61
|
"@types/aws-lambda": "^8.0.0",
|
|
62
62
|
"@types/node": "^22.0.0",
|
|
63
63
|
"aws-xray-sdk": "^3.3.3"
|