Socket
Socket
Sign inDemoInstall

@aws-sdk/smithy-client

Package Overview
Dependencies
Maintainers
6
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-sdk/smithy-client - npm Package Compare versions

Comparing version 3.160.0 to 3.161.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [3.161.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.160.0...v3.161.0) (2022-08-30)
### Features
* **smithy-client:** allow unambiguous type conversions in parse-utils ([#3888](https://github.com/aws/aws-sdk-js-v3/issues/3888)) ([967eb0a](https://github.com/aws/aws-sdk-js-v3/commit/967eb0aea76714a5f3243a57604799479fa7baea))
# [3.160.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.159.0...v3.160.0) (2022-08-29)

@@ -8,0 +19,0 @@

65

dist-cjs/parse-utils.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.strictParseByte = exports.strictParseShort = exports.strictParseInt32 = exports.strictParseInt = exports.strictParseLong = exports.limitedParseFloat32 = exports.limitedParseFloat = exports.handleFloat = exports.limitedParseDouble = exports.strictParseFloat32 = exports.strictParseFloat = exports.strictParseDouble = exports.expectUnion = exports.expectString = exports.expectObject = exports.expectNonNull = exports.expectByte = exports.expectShort = exports.expectInt32 = exports.expectInt = exports.expectLong = exports.expectFloat32 = exports.expectNumber = exports.expectBoolean = exports.parseBoolean = void 0;
exports.logger = exports.strictParseByte = exports.strictParseShort = exports.strictParseInt32 = exports.strictParseInt = exports.strictParseLong = exports.limitedParseFloat32 = exports.limitedParseFloat = exports.handleFloat = exports.limitedParseDouble = exports.strictParseFloat32 = exports.strictParseFloat = exports.strictParseDouble = exports.expectUnion = exports.expectString = exports.expectObject = exports.expectNonNull = exports.expectByte = exports.expectShort = exports.expectInt32 = exports.expectInt = exports.expectLong = exports.expectFloat32 = exports.expectNumber = exports.expectBoolean = exports.parseBoolean = void 0;
const parseBoolean = (value) => {

@@ -19,6 +19,29 @@ switch (value) {

}
if (typeof value === "number") {
if (value === 0 || value === 1) {
exports.logger.warn(stackTraceWarning(`Expected boolean, got ${typeof value}: ${value}`));
}
if (value === 0) {
return false;
}
if (value === 1) {
return true;
}
}
if (typeof value === "string") {
const lower = value.toLowerCase();
if (lower === "false" || lower === "true") {
exports.logger.warn(stackTraceWarning(`Expected boolean, got ${typeof value}: ${value}`));
}
if (lower === "false") {
return false;
}
if (lower === "true") {
return true;
}
}
if (typeof value === "boolean") {
return value;
}
throw new TypeError(`Expected boolean, got ${typeof value}`);
throw new TypeError(`Expected boolean, got ${typeof value}: ${value}`);
};

@@ -30,6 +53,15 @@ exports.expectBoolean = expectBoolean;

}
if (typeof value === "string") {
const parsed = parseFloat(value);
if (!Number.isNaN(parsed)) {
if (String(parsed) !== String(value)) {
exports.logger.warn(stackTraceWarning(`Expected number but observed string: ${value}`));
}
return parsed;
}
}
if (typeof value === "number") {
return value;
}
throw new TypeError(`Expected number, got ${typeof value}`);
throw new TypeError(`Expected number, got ${typeof value}: ${value}`);
};

@@ -55,3 +87,3 @@ exports.expectNumber = expectNumber;

}
throw new TypeError(`Expected integer, got ${typeof value}`);
throw new TypeError(`Expected integer, got ${typeof value}: ${value}`);
};

@@ -100,3 +132,4 @@ exports.expectLong = expectLong;

}
throw new TypeError(`Expected object, got ${typeof value}`);
const receivedType = Array.isArray(value) ? "array" : typeof value;
throw new TypeError(`Expected object, got ${receivedType}: ${value}`);
};

@@ -111,3 +144,7 @@ exports.expectObject = expectObject;

}
throw new TypeError(`Expected string, got ${typeof value}`);
if (["boolean", "number", "bigint"].includes(typeof value)) {
exports.logger.warn(stackTraceWarning(`Expected string, got ${typeof value}: ${value}`));
return String(value);
}
throw new TypeError(`Expected string, got ${typeof value}: ${value}`);
};

@@ -121,6 +158,6 @@ exports.expectString = expectString;

const setKeys = Object.entries(asObject)
.filter(([_, v]) => v !== null && v !== undefined)
.map(([k, _]) => k);
.filter(([, v]) => v != null)
.map(([k]) => k);
if (setKeys.length === 0) {
throw new TypeError(`Unions must have exactly one non-null member`);
throw new TypeError(`Unions must have exactly one non-null member. None were found.`);
}

@@ -213,1 +250,11 @@ if (setKeys.length > 1) {

exports.strictParseByte = strictParseByte;
const stackTraceWarning = (message) => {
return String(new TypeError(message).stack || message)
.split("\n")
.slice(0, 5)
.filter((s) => !s.includes("stackTraceWarning"))
.join("\n");
};
exports.logger = {
warn: console.warn,
};

@@ -16,6 +16,29 @@ import { __read } from "tslib";

}
if (typeof value === "number") {
if (value === 0 || value === 1) {
logger.warn(stackTraceWarning("Expected boolean, got ".concat(typeof value, ": ").concat(value)));
}
if (value === 0) {
return false;
}
if (value === 1) {
return true;
}
}
if (typeof value === "string") {
var lower = value.toLowerCase();
if (lower === "false" || lower === "true") {
logger.warn(stackTraceWarning("Expected boolean, got ".concat(typeof value, ": ").concat(value)));
}
if (lower === "false") {
return false;
}
if (lower === "true") {
return true;
}
}
if (typeof value === "boolean") {
return value;
}
throw new TypeError("Expected boolean, got ".concat(typeof value));
throw new TypeError("Expected boolean, got ".concat(typeof value, ": ").concat(value));
};

@@ -26,6 +49,15 @@ export var expectNumber = function (value) {

}
if (typeof value === "string") {
var parsed = parseFloat(value);
if (!Number.isNaN(parsed)) {
if (String(parsed) !== String(value)) {
logger.warn(stackTraceWarning("Expected number but observed string: ".concat(value)));
}
return parsed;
}
}
if (typeof value === "number") {
return value;
}
throw new TypeError("Expected number, got ".concat(typeof value));
throw new TypeError("Expected number, got ".concat(typeof value, ": ").concat(value));
};

@@ -49,3 +81,3 @@ var MAX_FLOAT = Math.ceil(Math.pow(2, 127) * (2 - Math.pow(2, -23)));

}
throw new TypeError("Expected integer, got ".concat(typeof value));
throw new TypeError("Expected integer, got ".concat(typeof value, ": ").concat(value));
};

@@ -89,3 +121,4 @@ export var expectInt = expectLong;

}
throw new TypeError("Expected object, got ".concat(typeof value));
var receivedType = Array.isArray(value) ? "array" : typeof value;
throw new TypeError("Expected object, got ".concat(receivedType, ": ").concat(value));
};

@@ -99,3 +132,7 @@ export var expectString = function (value) {

}
throw new TypeError("Expected string, got ".concat(typeof value));
if (["boolean", "number", "bigint"].includes(typeof value)) {
logger.warn(stackTraceWarning("Expected string, got ".concat(typeof value, ": ").concat(value)));
return String(value);
}
throw new TypeError("Expected string, got ".concat(typeof value, ": ").concat(value));
};

@@ -109,11 +146,11 @@ export var expectUnion = function (value) {

.filter(function (_a) {
var _b = __read(_a, 2), _ = _b[0], v = _b[1];
return v !== null && v !== undefined;
var _b = __read(_a, 2), v = _b[1];
return v != null;
})
.map(function (_a) {
var _b = __read(_a, 2), k = _b[0], _ = _b[1];
var _b = __read(_a, 1), k = _b[0];
return k;
});
if (setKeys.length === 0) {
throw new TypeError("Unions must have exactly one non-null member");
throw new TypeError("Unions must have exactly one non-null member. None were found.");
}

@@ -197,1 +234,11 @@ if (setKeys.length > 1) {

};
var stackTraceWarning = function (message) {
return String(new TypeError(message).stack || message)
.split("\n")
.slice(0, 5)
.filter(function (s) { return !s.includes("stackTraceWarning"); })
.join("\n");
};
export var logger = {
warn: console.warn,
};

@@ -8,5 +8,16 @@ /**

export declare const parseBoolean: (value: string) => boolean;
/**
* Asserts a value is a boolean and returns it.
* Casts strings and numbers with a warning if there is evidence that they were
* intended to be booleans.
*
* @param value A value that is expected to be a boolean.
* @returns The value if it's a boolean, undefined if it's null/undefined,
* otherwise an error is thrown.
*/
export declare const expectBoolean: (value: any) => boolean | undefined;
/**
* Asserts a value is a number and returns it.
* Casts strings with a warning if the string is a parseable number.
* This is to unblock slight API definition/implementation inconsistencies.
*

@@ -81,2 +92,3 @@ * @param value A value that is expected to be a number.

* Asserts a value is a string and returns it.
* Numbers and boolean will be cast to strings with a warning.
*

@@ -202,1 +214,10 @@ * @param value A value that is expected to be a string.

export declare const strictParseByte: (value: string | number) => number | undefined;
/**
* @private
*/
export declare const logger: {
warn: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
};
export declare const parseBoolean: (value: string) => boolean;
export declare const expectBoolean: (value: any) => boolean | undefined;

@@ -50,1 +51,8 @@

export declare const strictParseByte: (value: string | number) => number | undefined;
export declare const logger: {
warn: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
};

2

package.json
{
"name": "@aws-sdk/smithy-client",
"version": "3.160.0",
"version": "3.161.0",
"scripts": {

@@ -5,0 +5,0 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc