@middy/util 7.3.3 → 7.4.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.
Files changed (3) hide show
  1. package/index.d.ts +3 -0
  2. package/index.js +28 -6
  3. 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,9 +11,12 @@
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?, minLength?, maxLength?, pattern? }
15
- // Numeric: `minimum`/`maximum` (number/integer).
16
- // String: `minLength`/`maxLength` (string length), `pattern` (regex source).
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).
18
+ // String: `minLength`/`maxLength` (string length), `pattern` (regex
19
+ // source string per JSON Schema).
17
20
  // { type: 'object' | 'object?', properties?: {...}, additionalProperties?: <rule> }
18
21
  // `properties` validates known keys with the flat-schema form.
19
22
  // `additionalProperties` validates every other key's value against the
@@ -24,6 +27,10 @@
24
27
  // combine with `type` to require a specific type and/or presence.
25
28
  // Keys in `options` (or nested objects) that are not in `schema` throw,
26
29
  // catching typos.
30
+
31
+ const name = "util";
32
+ const pkg = `@middy/${name}`;
33
+
27
34
  const validateOptionsTypeCheckers = {
28
35
  string: (v) => typeof v === "string",
29
36
  number: (v) => typeof v === "number" && !Number.isNaN(v),
@@ -182,6 +189,9 @@ const checkRule = (rule, value, path, fail) => {
182
189
  additionalProperties,
183
190
  minimum,
184
191
  maximum,
192
+ exclusiveMinimum,
193
+ exclusiveMaximum,
194
+ multipleOf,
185
195
  pattern,
186
196
  minLength,
187
197
  maxLength,
@@ -194,6 +204,18 @@ const checkRule = (rule, value, path, fail) => {
194
204
  if (maximum !== undefined && value > maximum) {
195
205
  fail(`Option '${path}' must be <= ${maximum}`);
196
206
  }
207
+ if (exclusiveMinimum !== undefined && value <= exclusiveMinimum) {
208
+ fail(`Option '${path}' must be > ${exclusiveMinimum}`);
209
+ }
210
+ if (exclusiveMaximum !== undefined && value >= exclusiveMaximum) {
211
+ fail(`Option '${path}' must be < ${exclusiveMaximum}`);
212
+ }
213
+ if (multipleOf !== undefined) {
214
+ const quotient = value / multipleOf;
215
+ if (!Number.isFinite(quotient) || Math.floor(quotient) !== quotient) {
216
+ fail(`Option '${path}' must be a multiple of ${multipleOf}`);
217
+ }
218
+ }
197
219
  if (pattern !== undefined && !new RegExp(pattern).test(value)) {
198
220
  fail(`Option '${path}' must match pattern ${pattern}`);
199
221
  }
@@ -298,7 +320,7 @@ export const createClient = async (options, request) => {
298
320
  if (options.awsClientAssumeRole) {
299
321
  if (!request) {
300
322
  throw new Error("Request required when assuming role", {
301
- cause: { package: "@middy/util" },
323
+ cause: { package: pkg },
302
324
  });
303
325
  }
304
326
  awsClientCredentials = await getInternal(
@@ -398,7 +420,7 @@ export const getInternal = async (variables, request) => {
398
420
  }
399
421
  if (errors) {
400
422
  throw new Error("Failed to resolve internal values", {
401
- cause: { package: "@middy/util", data: errors },
423
+ cause: { package: pkg, data: errors },
402
424
  });
403
425
  }
404
426
  return obj;
@@ -429,7 +451,7 @@ const validateCacheExpiry = (cacheExpiry) => {
429
451
  ) {
430
452
  throw new Error(
431
453
  `Invalid cacheExpiry value: ${cacheExpiry}. Must be -1 (infinite), 0 (disabled), or a positive number (ms duration or unix timestamp)`,
432
- { cause: { package: "@middy/util" } },
454
+ { cause: { package: pkg } },
433
455
  );
434
456
  }
435
457
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/util",
3
- "version": "7.3.3",
3
+ "version": "7.4.0",
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.3",
60
+ "@middy/core": "7.4.0",
61
61
  "@types/aws-lambda": "^8.0.0",
62
62
  "@types/node": "^22.0.0",
63
63
  "aws-xray-sdk": "^3.3.3"