aws-iot-device-sdk-v2
Advanced tools
Comparing version 1.11.0 to 1.11.1
@@ -39,2 +39,11 @@ import { eventstream } from "aws-crt"; | ||
/** | ||
* Normalizes an array value | ||
* | ||
* @param value array to normalize | ||
* @param valueTransformer optional transformation to apply to all array values | ||
* | ||
* @return a normalized array | ||
*/ | ||
export declare function normalizeArrayValue(value: any, transformer?: PropertyTransformer): any[]; | ||
/** | ||
* Normalization/deserialization helper that replaces an array value, if it exists, with a potentially transformed value | ||
@@ -49,2 +58,12 @@ * | ||
/** | ||
* Transforms a map value into a generic object with optional key and value transformation | ||
* | ||
* @param value map to transform | ||
* @param keyTransformer optional transformation to apply to all map keys | ||
* @param valueTransformer optional transformation to apply to all map values | ||
* | ||
* @return map transformed into an object | ||
*/ | ||
export declare function normalizeMapValueAsObject(value: any, keyTransformer?: PropertyTransformer, valueTransformer?: PropertyTransformer): any; | ||
/** | ||
* Normalization/deserialization helper that replaces a javascript Object, if it exists, with a map where the | ||
@@ -58,3 +77,3 @@ * values are potentially transformed | ||
*/ | ||
export declare function setDefinedMapPropertyAsObject(object: any, propertyName: string, value: any, transformer?: PropertyTransformer): void; | ||
export declare function setDefinedMapPropertyAsObject(object: any, propertyName: string, value: any, keyTransformer?: PropertyTransformer, valueTransformer?: PropertyTransformer): void; | ||
/** | ||
@@ -69,13 +88,4 @@ * Normalization/deserialization helper that replaces an string-keyed map value, if it exists, with a map where the | ||
*/ | ||
export declare function setDefinedObjectPropertyAsMap(object: any, propertyName: string, value: any, transformer?: PropertyTransformer): void; | ||
export declare function setDefinedObjectPropertyAsMap(object: any, propertyName: string, value: any, keyTransformer?: PropertyTransformer, valueTransformer?: PropertyTransformer): void; | ||
/** | ||
* Normalization/deserialization helper that transforms a union value, if it exists, with a union value where the | ||
* single set property has been optionally transformed | ||
* | ||
* @param object union value to potentially set a union property on | ||
* @param union union value to transform | ||
* @param setters map of union members to transformation functions | ||
*/ | ||
export declare function setUnionProperty(object: any, union: any, setters: UnionTransformer): void; | ||
/** | ||
* Throws an error if a property value is not a string | ||
@@ -176,2 +186,18 @@ * | ||
export declare function validateValueAsOptionalBlob(value: any, propertyName?: string, type?: string): void; | ||
/** | ||
* Throws an error if a property value is not a valid defined object | ||
* | ||
* @param value value to check | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
export declare function validateValueAsAny(value: any, propertyName?: string, type?: string): void; | ||
/** | ||
* Throws an error if a property value is not a valid JS object or undefined (always succeeds) | ||
* | ||
* @param value value to check | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
export declare function validateValueAsOptionalAny(value: any, propertyName?: string, type?: string): void; | ||
export type ElementValidator = (value: any) => void; | ||
@@ -204,3 +230,3 @@ /** | ||
*/ | ||
export declare function validateValueAsMap(value: any, elementValidator: ElementValidator, propertyName?: string, type?: string): void; | ||
export declare function validateValueAsMap(value: any, keyValidator: ElementValidator, valueValidator: ElementValidator, propertyName?: string, type?: string): void; | ||
/** | ||
@@ -214,3 +240,3 @@ * Throws an error if a property value is not a valid map type or undefined | ||
*/ | ||
export declare function validateValueAsOptionalMap(value: any, elementValidator: ElementValidator, propertyName?: string, type?: string): void; | ||
export declare function validateValueAsOptionalMap(value: any, keyValidator: ElementValidator, valueValidator: ElementValidator, propertyName?: string, type?: string): void; | ||
/** | ||
@@ -234,24 +260,2 @@ * Throws an error if a property value does not pass a validation check | ||
export declare function validateValueAsOptionalObject(value: any, elementValidator: ElementValidator, propertyName: string, type: string): void; | ||
/** | ||
* Throws an error if a property value does not belong to a set of valid enumerated values as strings. Backwards | ||
* compatibility dictates that we cannot validate response data due to a need for enums to be able to expand without | ||
* breaking clients using an older service model. | ||
* | ||
* @param value value to check | ||
* @param validValues set of allowed enum values | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
export declare function validateValueAsEnum(value: any, validValues: Set<string>, propertyName?: string, type?: string): void; | ||
/** | ||
* Throws an error if a property value is defined and does not belong to a set of valid enumerated values as strings. | ||
* Backwards compatibility dictates that we cannot validate response data due to a need for enums to be able to expand | ||
* without breaking clients using an older service model. | ||
* | ||
* @param value value to check | ||
* @param validValues set of allowed enum values | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
export declare function validateValueAsOptionalEnum(value: any, validValues: Set<string>, propertyName?: string, type?: string): void; | ||
export type UnionTransformer = Map<string, PropertyTransformer | undefined>; | ||
@@ -258,0 +262,0 @@ export type UnionValidator = Map<string, ElementValidator | undefined>; |
@@ -30,3 +30,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateValueAsUnion = exports.validateValueAsOptionalEnum = exports.validateValueAsEnum = exports.validateValueAsOptionalObject = exports.validateValueAsObject = exports.validateValueAsOptionalMap = exports.validateValueAsMap = exports.validateValueAsOptionalArray = exports.validateValueAsArray = exports.validateValueAsOptionalBlob = exports.validateValueAsBlob = exports.validateValueAsOptionalDate = exports.validateValueAsDate = exports.validateValueAsOptionalBoolean = exports.validateValueAsBoolean = exports.validateValueAsOptionalInteger = exports.validateValueAsInteger = exports.validateValueAsOptionalNumber = exports.validateValueAsNumber = exports.validateValueAsOptionalString = exports.validateValueAsString = exports.setUnionProperty = exports.setDefinedObjectPropertyAsMap = exports.setDefinedMapPropertyAsObject = exports.setDefinedArrayProperty = exports.setDefinedProperty = exports.transformNumberAsDate = exports.encodeDateAsNumber = exports.transformStringAsPayload = exports.encodePayloadAsString = void 0; | ||
exports.validateValueAsUnion = exports.validateValueAsOptionalObject = exports.validateValueAsObject = exports.validateValueAsOptionalMap = exports.validateValueAsMap = exports.validateValueAsOptionalArray = exports.validateValueAsArray = exports.validateValueAsOptionalAny = exports.validateValueAsAny = exports.validateValueAsOptionalBlob = exports.validateValueAsBlob = exports.validateValueAsOptionalDate = exports.validateValueAsDate = exports.validateValueAsOptionalBoolean = exports.validateValueAsBoolean = exports.validateValueAsOptionalInteger = exports.validateValueAsInteger = exports.validateValueAsOptionalNumber = exports.validateValueAsNumber = exports.validateValueAsOptionalString = exports.validateValueAsString = exports.setDefinedObjectPropertyAsMap = exports.setDefinedMapPropertyAsObject = exports.normalizeMapValueAsObject = exports.setDefinedArrayProperty = exports.normalizeArrayValue = exports.setDefinedProperty = exports.transformNumberAsDate = exports.encodeDateAsNumber = exports.transformStringAsPayload = exports.encodePayloadAsString = void 0; | ||
const eventstream_rpc = __importStar(require("./eventstream_rpc")); | ||
@@ -99,2 +99,21 @@ const aws_crt_1 = require("aws-crt"); | ||
/** | ||
* Normalizes an array value | ||
* | ||
* @param value array to normalize | ||
* @param valueTransformer optional transformation to apply to all array values | ||
* | ||
* @return a normalized array | ||
*/ | ||
function normalizeArrayValue(value, transformer) { | ||
if (transformer == undefined) { | ||
return value; | ||
} | ||
let array = new Array(); | ||
for (const element of value) { | ||
array.push(transformer(element)); | ||
} | ||
return array; | ||
} | ||
exports.normalizeArrayValue = normalizeArrayValue; | ||
/** | ||
* Normalization/deserialization helper that replaces an array value, if it exists, with a potentially transformed value | ||
@@ -111,15 +130,25 @@ * | ||
} | ||
let array = new Array(); | ||
for (const element of value) { | ||
if (transformer) { | ||
array.push(transformer(element)); | ||
} | ||
else { | ||
array.push(element); | ||
} | ||
} | ||
object[propertyName] = array; | ||
object[propertyName] = normalizeArrayValue(value, transformer); | ||
} | ||
exports.setDefinedArrayProperty = setDefinedArrayProperty; | ||
/** | ||
* Transforms a map value into a generic object with optional key and value transformation | ||
* | ||
* @param value map to transform | ||
* @param keyTransformer optional transformation to apply to all map keys | ||
* @param valueTransformer optional transformation to apply to all map values | ||
* | ||
* @return map transformed into an object | ||
*/ | ||
function normalizeMapValueAsObject(value, keyTransformer, valueTransformer) { | ||
let mapAsObject = {}; | ||
for (const [key, val] of value.entries()) { | ||
let transformedKey = keyTransformer ? keyTransformer(key) : key; | ||
let transformedvalue = valueTransformer ? valueTransformer(val) : val; | ||
mapAsObject[transformedKey] = transformedvalue; | ||
} | ||
return mapAsObject; | ||
} | ||
exports.normalizeMapValueAsObject = normalizeMapValueAsObject; | ||
/** | ||
* Normalization/deserialization helper that replaces a javascript Object, if it exists, with a map where the | ||
@@ -133,16 +162,7 @@ * values are potentially transformed | ||
*/ | ||
function setDefinedMapPropertyAsObject(object, propertyName, value, transformer) { | ||
function setDefinedMapPropertyAsObject(object, propertyName, value, keyTransformer, valueTransformer) { | ||
if (value === undefined || value == null) { | ||
return; | ||
} | ||
let mapAsObject = {}; | ||
for (const [key, val] of value.entries()) { | ||
if (transformer) { | ||
mapAsObject[key] = transformer(val); | ||
} | ||
else { | ||
mapAsObject[key] = val; | ||
} | ||
} | ||
object[propertyName] = mapAsObject; | ||
object[propertyName] = normalizeMapValueAsObject(value); | ||
} | ||
@@ -159,3 +179,3 @@ exports.setDefinedMapPropertyAsObject = setDefinedMapPropertyAsObject; | ||
*/ | ||
function setDefinedObjectPropertyAsMap(object, propertyName, value, transformer) { | ||
function setDefinedObjectPropertyAsMap(object, propertyName, value, keyTransformer, valueTransformer) { | ||
if (value === undefined || value == null) { | ||
@@ -166,8 +186,5 @@ return; | ||
for (const property in value) { | ||
if (transformer) { | ||
map.set(property, transformer(value[property])); | ||
} | ||
else { | ||
map.set(property, value[property]); | ||
} | ||
let transformedKey = keyTransformer ? keyTransformer(property) : property; | ||
let transformedValue = valueTransformer ? valueTransformer(value[property]) : value[property]; | ||
map.set(transformedKey, transformedValue); | ||
} | ||
@@ -178,23 +195,2 @@ object[propertyName] = map; | ||
/** | ||
* Normalization/deserialization helper that transforms a union value, if it exists, with a union value where the | ||
* single set property has been optionally transformed | ||
* | ||
* @param object union value to potentially set a union property on | ||
* @param union union value to transform | ||
* @param setters map of union members to transformation functions | ||
*/ | ||
function setUnionProperty(object, union, setters) { | ||
let propertyCount = getPropertyCount(union, setters.keys()); | ||
if (propertyCount != 1) { | ||
throw eventstream_rpc.createRpcError(eventstream_rpc.RpcErrorType.ValidationError, `Union has ${propertyCount} properties set`); | ||
} | ||
for (const [propertyName, setter] of setters.entries()) { | ||
let propertyValue = union[propertyName]; | ||
if (propertyValue) { | ||
setDefinedProperty(object, propertyName, propertyValue, setter); | ||
} | ||
} | ||
} | ||
exports.setUnionProperty = setUnionProperty; | ||
/** | ||
* Throws an RpcError with a detailed description, if possible, of what required property was missing | ||
@@ -410,2 +406,29 @@ * | ||
/** | ||
* Throws an error if a property value is not a valid defined object | ||
* | ||
* @param value value to check | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
function validateValueAsAny(value, propertyName, type) { | ||
if (value === undefined) { | ||
throwMissingPropertyError(propertyName, type); | ||
} | ||
} | ||
exports.validateValueAsAny = validateValueAsAny; | ||
/** | ||
* Throws an error if a property value is not a valid JS object or undefined (always succeeds) | ||
* | ||
* @param value value to check | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
function validateValueAsOptionalAny(value, propertyName, type) { | ||
if (value === undefined) { | ||
return; | ||
} | ||
validateValueAsAny(value, propertyName, type); | ||
} | ||
exports.validateValueAsOptionalAny = validateValueAsOptionalAny; | ||
/** | ||
* Throws an error if a property value is not a valid array type | ||
@@ -464,3 +487,3 @@ * | ||
*/ | ||
function validateValueAsMap(value, elementValidator, propertyName, type) { | ||
function validateValueAsMap(value, keyValidator, valueValidator, propertyName, type) { | ||
if (value === undefined) { | ||
@@ -475,3 +498,3 @@ return; | ||
try { | ||
validateValueAsString(key); | ||
keyValidator(key); | ||
} | ||
@@ -488,3 +511,3 @@ catch (err) { | ||
try { | ||
elementValidator(val); | ||
valueValidator(val); | ||
} | ||
@@ -511,7 +534,7 @@ catch (err) { | ||
*/ | ||
function validateValueAsOptionalMap(value, elementValidator, propertyName, type) { | ||
function validateValueAsOptionalMap(value, keyValidator, valueValidator, propertyName, type) { | ||
if (value === undefined) { | ||
return; | ||
} | ||
validateValueAsMap(value, elementValidator, propertyName, type); | ||
validateValueAsMap(value, keyValidator, valueValidator, propertyName, type); | ||
} | ||
@@ -555,41 +578,2 @@ exports.validateValueAsOptionalMap = validateValueAsOptionalMap; | ||
exports.validateValueAsOptionalObject = validateValueAsOptionalObject; | ||
/** | ||
* Throws an error if a property value does not belong to a set of valid enumerated values as strings. Backwards | ||
* compatibility dictates that we cannot validate response data due to a need for enums to be able to expand without | ||
* breaking clients using an older service model. | ||
* | ||
* @param value value to check | ||
* @param validValues set of allowed enum values | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
function validateValueAsEnum(value, validValues, propertyName, type) { | ||
if (value === undefined) { | ||
throwMissingPropertyError(propertyName, type); | ||
} | ||
if (typeof value !== 'string') { | ||
throwInvalidPropertyValueError("a string value", propertyName, type); | ||
} | ||
if (!validValues.has(value)) { | ||
throwInvalidPropertyValueError("a valid enum value", propertyName, type); | ||
} | ||
} | ||
exports.validateValueAsEnum = validateValueAsEnum; | ||
/** | ||
* Throws an error if a property value is defined and does not belong to a set of valid enumerated values as strings. | ||
* Backwards compatibility dictates that we cannot validate response data due to a need for enums to be able to expand | ||
* without breaking clients using an older service model. | ||
* | ||
* @param value value to check | ||
* @param validValues set of allowed enum values | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
function validateValueAsOptionalEnum(value, validValues, propertyName, type) { | ||
if (value === undefined) { | ||
return; | ||
} | ||
validateValueAsEnum(value, validValues, propertyName, type); | ||
} | ||
exports.validateValueAsOptionalEnum = validateValueAsOptionalEnum; | ||
/* | ||
@@ -596,0 +580,0 @@ * Unions must have exactly one property set. This function helps check that. |
@@ -200,2 +200,10 @@ /// <reference types="node" /> | ||
/** | ||
* Checks an RPC Client configuration structure and throws an exception if there is a problem with one of the | ||
* required properties. Does explicit type checks in spite of typescript to validate even when used from a | ||
* pure Javascript project. | ||
* | ||
* @param config RPC client configuration to validate | ||
*/ | ||
export declare function validateRpcClientConfig(config: RpcClientConfig): void; | ||
/** | ||
* Configuration options for the RPC client's connect step | ||
@@ -241,3 +249,4 @@ */ | ||
* Attempts to open a network connection to the configured remote endpoint. Returned promise will be fulfilled if | ||
* the transport-level connection is successfully established, and rejected otherwise. | ||
* the transport-level connection is successfully established and the eventstream handshake completes without | ||
* error. | ||
* | ||
@@ -377,2 +386,8 @@ * Returns a promise that is resolved with additional context on a successful connection, otherwise rejected. | ||
private operation; | ||
/** | ||
* @internal | ||
* | ||
* @param operationConfig | ||
* @param serviceModel | ||
*/ | ||
constructor(operationConfig: OperationConfig, serviceModel: EventstreamRpcServiceModel); | ||
@@ -412,2 +427,9 @@ /** | ||
private responseHandled; | ||
/** | ||
* @internal | ||
* | ||
* @param request | ||
* @param operationConfig | ||
* @param serviceModel | ||
*/ | ||
constructor(request: RequestType, operationConfig: OperationConfig, serviceModel: EventstreamRpcServiceModel); | ||
@@ -414,0 +436,0 @@ /** |
@@ -16,3 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRpcError = exports.StreamingOperation = exports.RequestResponseOperation = exports.RpcClient = exports.RpcError = exports.RpcErrorType = void 0; | ||
exports.createRpcError = exports.StreamingOperation = exports.RequestResponseOperation = exports.RpcClient = exports.validateRpcClientConfig = exports.RpcError = exports.RpcErrorType = void 0; | ||
/** | ||
@@ -91,2 +91,27 @@ * @packageDocumentation | ||
/** | ||
* Checks an RPC Client configuration structure and throws an exception if there is a problem with one of the | ||
* required properties. Does explicit type checks in spite of typescript to validate even when used from a | ||
* pure Javascript project. | ||
* | ||
* @param config RPC client configuration to validate | ||
*/ | ||
function validateRpcClientConfig(config) { | ||
if (!config) { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration is undefined"); | ||
} | ||
if (!config.hostName) { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration must have a valid host name"); | ||
} | ||
if (typeof config.hostName !== 'string') { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration host name must be a string"); | ||
} | ||
if (config.port === undefined || config.port === null) { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration must have a valid port"); | ||
} | ||
if (typeof config.port !== 'number' || !Number.isSafeInteger(config.port) || config.port < 0 || config.port > 65535) { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration host name must be 16-bit integer"); | ||
} | ||
} | ||
exports.validateRpcClientConfig = validateRpcClientConfig; | ||
/** | ||
* @internal a rough mirror of the internal connection state, but ultimately must be independent due to the more | ||
@@ -141,3 +166,4 @@ * complex connection establishment process (connect/connack). Used to prevent API invocations when the client | ||
* Attempts to open a network connection to the configured remote endpoint. Returned promise will be fulfilled if | ||
* the transport-level connection is successfully established, and rejected otherwise. | ||
* the transport-level connection is successfully established and the eventstream handshake completes without | ||
* error. | ||
* | ||
@@ -341,3 +367,3 @@ * Returns a promise that is resolved with additional context on a successful connection, otherwise rejected. | ||
} | ||
connectMessage.headers.push(aws_crt_1.eventstream.Header.newString(':version', '0.1.0'), aws_crt_1.eventstream.Header.newString('client-name', 'accepted.testy_mc_testerson')); | ||
connectMessage.headers.push(aws_crt_1.eventstream.Header.newString(':version', '0.1.0')); | ||
} | ||
@@ -467,2 +493,8 @@ } | ||
class RequestResponseOperation extends events_1.EventEmitter { | ||
/** | ||
* @internal | ||
* | ||
* @param operationConfig | ||
* @param serviceModel | ||
*/ | ||
constructor(operationConfig, serviceModel) { | ||
@@ -519,2 +551,9 @@ if (!serviceModel.operations.has(operationConfig.name)) { | ||
class StreamingOperation extends events_1.EventEmitter { | ||
/** | ||
* @internal | ||
* | ||
* @param request | ||
* @param operationConfig | ||
* @param serviceModel | ||
*/ | ||
constructor(request, operationConfig, serviceModel) { | ||
@@ -576,2 +615,5 @@ if (!serviceModel.operations.has(operationConfig.name)) { | ||
try { | ||
if (!doesOperationAllowOutboundMessages(this.serviceModel, this.operationConfig.name)) { | ||
throw createRpcError(RpcErrorType.ValidationError, `Operation '${this.operationConfig.name}' does not allow outbound streaming messages.`); | ||
} | ||
if (!this.operationConfig.options.disableValidation) { | ||
@@ -697,3 +739,3 @@ validateOutboundMessage(this.serviceModel, this.operationConfig.name, message); | ||
if (!validator) { | ||
throw createRpcError(RpcErrorType.InternalError, `No shape named '${shapeName}' exists in the service model`); | ||
throw createRpcError(RpcErrorType.ValidationError, `No shape named '${shapeName}' exists in the service model`); | ||
} | ||
@@ -709,3 +751,3 @@ validator(shape); | ||
if (!selectedShape) { | ||
throw createRpcError(RpcErrorType.InternalError, `Operation '${operationName}' does not have a defined selection shape`); | ||
throw createRpcError(RpcErrorType.ValidationError, `Operation '${operationName}' does not have a defined selection shape`); | ||
} | ||
@@ -720,2 +762,9 @@ return validateShape(model, selectedShape, shape); | ||
} | ||
function doesOperationAllowOutboundMessages(model, operationName) { | ||
let operation = model.operations.get(operationName); | ||
if (!operation) { | ||
throw createRpcError(RpcErrorType.InternalError, `No operation named '${operationName}' exists in the service model`); | ||
} | ||
return operation.outboundMessageShape !== undefined; | ||
} | ||
function serializeMessage(model, operationName, message, shapeSelector) { | ||
@@ -722,0 +771,0 @@ let operation = model.operations.get(operationName); |
@@ -77,2 +77,23 @@ /* | ||
/** | ||
* Normalizes an array value | ||
* | ||
* @param value array to normalize | ||
* @param valueTransformer optional transformation to apply to all array values | ||
* | ||
* @return a normalized array | ||
*/ | ||
export function normalizeArrayValue(value: any, transformer? : PropertyTransformer) : any[] { | ||
if (transformer == undefined) { | ||
return value; | ||
} | ||
let array: any[] = new Array(); | ||
for (const element of value) { | ||
array.push(transformer(element)); | ||
} | ||
return array; | ||
} | ||
/** | ||
* Normalization/deserialization helper that replaces an array value, if it exists, with a potentially transformed value | ||
@@ -90,12 +111,25 @@ * | ||
let array = new Array(); | ||
for (const element of value) { | ||
if (transformer) { | ||
array.push(transformer(element)); | ||
} else { | ||
array.push(element); | ||
} | ||
object[propertyName] = normalizeArrayValue(value, transformer); | ||
} | ||
/** | ||
* Transforms a map value into a generic object with optional key and value transformation | ||
* | ||
* @param value map to transform | ||
* @param keyTransformer optional transformation to apply to all map keys | ||
* @param valueTransformer optional transformation to apply to all map values | ||
* | ||
* @return map transformed into an object | ||
*/ | ||
export function normalizeMapValueAsObject(value: any, keyTransformer?: PropertyTransformer, valueTransformer? : PropertyTransformer) : any { | ||
let mapAsObject: any = {}; | ||
for (const [key, val] of (value as Map<any, any>).entries()) { | ||
let transformedKey : any = keyTransformer ? keyTransformer(key) : key; | ||
let transformedvalue : any = valueTransformer ? valueTransformer(val) : val; | ||
mapAsObject[transformedKey] = transformedvalue; | ||
} | ||
object[propertyName] = array; | ||
return mapAsObject; | ||
} | ||
@@ -112,3 +146,3 @@ | ||
*/ | ||
export function setDefinedMapPropertyAsObject(object: any, propertyName: string, value: any, transformer? : PropertyTransformer) : void { | ||
export function setDefinedMapPropertyAsObject(object: any, propertyName: string, value: any, keyTransformer?: PropertyTransformer, valueTransformer? : PropertyTransformer) : void { | ||
if (value === undefined || value == null) { | ||
@@ -118,12 +152,3 @@ return; | ||
let mapAsObject : any = {}; | ||
for (const [key, val] of (value as Map<string, any>).entries()) { | ||
if (transformer) { | ||
mapAsObject[key] = transformer(val); | ||
} else { | ||
mapAsObject[key] = val; | ||
} | ||
} | ||
object[propertyName] = mapAsObject; | ||
object[propertyName] = normalizeMapValueAsObject(value); | ||
} | ||
@@ -140,3 +165,3 @@ | ||
*/ | ||
export function setDefinedObjectPropertyAsMap(object: any, propertyName: string, value: any, transformer? : PropertyTransformer) : void { | ||
export function setDefinedObjectPropertyAsMap(object: any, propertyName: string, value: any, keyTransformer?: PropertyTransformer, valueTransformer? : PropertyTransformer) : void { | ||
if (value === undefined || value == null) { | ||
@@ -148,7 +173,6 @@ return; | ||
for (const property in value) { | ||
if (transformer) { | ||
map.set(property, transformer(value[property])); | ||
} else { | ||
map.set(property, value[property]); | ||
} | ||
let transformedKey : any = keyTransformer ? keyTransformer(property) : property; | ||
let transformedValue : any = valueTransformer ? valueTransformer(value[property]) : value[property]; | ||
map.set(transformedKey, transformedValue); | ||
} | ||
@@ -160,25 +184,2 @@ | ||
/** | ||
* Normalization/deserialization helper that transforms a union value, if it exists, with a union value where the | ||
* single set property has been optionally transformed | ||
* | ||
* @param object union value to potentially set a union property on | ||
* @param union union value to transform | ||
* @param setters map of union members to transformation functions | ||
*/ | ||
export function setUnionProperty(object : any, union : any, setters : UnionTransformer) { | ||
let propertyCount : number = getPropertyCount(union, setters.keys()); | ||
if (propertyCount != 1) { | ||
throw eventstream_rpc.createRpcError(eventstream_rpc.RpcErrorType.ValidationError, `Union has ${propertyCount} properties set`); | ||
} | ||
for (const [propertyName, setter] of setters.entries()) { | ||
let propertyValue = union[propertyName]; | ||
if (propertyValue) { | ||
setDefinedProperty(object, propertyName, propertyValue, setter); | ||
} | ||
} | ||
} | ||
/** | ||
* Throws an RpcError with a detailed description, if possible, of what required property was missing | ||
@@ -405,2 +406,30 @@ * | ||
/** | ||
* Throws an error if a property value is not a valid defined object | ||
* | ||
* @param value value to check | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
export function validateValueAsAny(value : any, propertyName?: string, type?: string) { | ||
if (value === undefined) { | ||
throwMissingPropertyError(propertyName, type); | ||
} | ||
} | ||
/** | ||
* Throws an error if a property value is not a valid JS object or undefined (always succeeds) | ||
* | ||
* @param value value to check | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
export function validateValueAsOptionalAny(value : any, propertyName?: string, type?: string) { | ||
if (value === undefined) { | ||
return; | ||
} | ||
validateValueAsAny(value, propertyName, type); | ||
} | ||
export type ElementValidator = (value : any) => void; | ||
@@ -463,3 +492,3 @@ | ||
*/ | ||
export function validateValueAsMap(value : any, elementValidator : ElementValidator, propertyName?: string, type?: string) { | ||
export function validateValueAsMap(value : any, keyValidator : ElementValidator, valueValidator : ElementValidator, propertyName?: string, type?: string) { | ||
if (value === undefined) { | ||
@@ -476,3 +505,3 @@ return; | ||
try { | ||
validateValueAsString(key); | ||
keyValidator(key); | ||
} catch (err) { | ||
@@ -488,3 +517,3 @@ let rpcError : eventstream_rpc.RpcError = err as eventstream_rpc.RpcError; | ||
try { | ||
elementValidator(val); | ||
valueValidator(val); | ||
} catch (err) { | ||
@@ -509,3 +538,3 @@ let rpcError : eventstream_rpc.RpcError = err as eventstream_rpc.RpcError; | ||
*/ | ||
export function validateValueAsOptionalMap(value : any, elementValidator : ElementValidator, propertyName?: string, type?: string) { | ||
export function validateValueAsOptionalMap(value : any, keyValidator : ElementValidator, valueValidator : ElementValidator, propertyName?: string, type?: string) { | ||
if (value === undefined) { | ||
@@ -515,3 +544,3 @@ return; | ||
validateValueAsMap(value, elementValidator, propertyName, type); | ||
validateValueAsMap(value, keyValidator, valueValidator, propertyName, type); | ||
} | ||
@@ -556,44 +585,2 @@ | ||
/** | ||
* Throws an error if a property value does not belong to a set of valid enumerated values as strings. Backwards | ||
* compatibility dictates that we cannot validate response data due to a need for enums to be able to expand without | ||
* breaking clients using an older service model. | ||
* | ||
* @param value value to check | ||
* @param validValues set of allowed enum values | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
export function validateValueAsEnum(value : any, validValues : Set<string>, propertyName? : string, type? : string) { | ||
if (value === undefined) { | ||
throwMissingPropertyError(propertyName, type); | ||
} | ||
if (typeof value !== 'string') { | ||
throwInvalidPropertyValueError("a string value", propertyName, type); | ||
} | ||
if (!validValues.has(value as string)) { | ||
throwInvalidPropertyValueError("a valid enum value", propertyName, type); | ||
} | ||
} | ||
/** | ||
* Throws an error if a property value is defined and does not belong to a set of valid enumerated values as strings. | ||
* Backwards compatibility dictates that we cannot validate response data due to a need for enums to be able to expand | ||
* without breaking clients using an older service model. | ||
* | ||
* @param value value to check | ||
* @param validValues set of allowed enum values | ||
* @param propertyName optional, name of the property with this value | ||
* @param type optional, type of object that the property is on | ||
*/ | ||
export function validateValueAsOptionalEnum(value : any, validValues : Set<string>, propertyName? : string, type? : string) { | ||
if (value === undefined) { | ||
return; | ||
} | ||
validateValueAsEnum(value, validValues, propertyName, type); | ||
} | ||
/* | ||
@@ -600,0 +587,0 @@ * Unions must have exactly one property set. This function helps check that. |
@@ -267,2 +267,31 @@ /* | ||
/** | ||
* Checks an RPC Client configuration structure and throws an exception if there is a problem with one of the | ||
* required properties. Does explicit type checks in spite of typescript to validate even when used from a | ||
* pure Javascript project. | ||
* | ||
* @param config RPC client configuration to validate | ||
*/ | ||
export function validateRpcClientConfig(config: RpcClientConfig) { | ||
if (!config) { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration is undefined"); | ||
} | ||
if (!config.hostName) { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration must have a valid host name"); | ||
} | ||
if (typeof config.hostName !== 'string') { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration host name must be a string"); | ||
} | ||
if (config.port === undefined || config.port === null) { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration must have a valid port"); | ||
} | ||
if (typeof config.port !== 'number' || !Number.isSafeInteger(config.port as number) || config.port < 0 || config.port > 65535) { | ||
throw createRpcError(RpcErrorType.ValidationError, "Eventstream RPC client configuration host name must be 16-bit integer"); | ||
} | ||
} | ||
/** | ||
* @internal a rough mirror of the internal connection state, but ultimately must be independent due to the more | ||
@@ -311,3 +340,2 @@ * complex connection establishment process (connect/connack). Used to prevent API invocations when the client | ||
private unclosedOperations? : Set<OperationBase>; | ||
private disconnectionReason? : CrtError; | ||
@@ -350,3 +378,4 @@ | ||
* Attempts to open a network connection to the configured remote endpoint. Returned promise will be fulfilled if | ||
* the transport-level connection is successfully established, and rejected otherwise. | ||
* the transport-level connection is successfully established and the eventstream handshake completes without | ||
* error. | ||
* | ||
@@ -589,4 +618,3 @@ * Returns a promise that is resolved with additional context on a successful connection, otherwise rejected. | ||
connectMessage.headers.push( | ||
eventstream.Header.newString(':version', '0.1.0'), | ||
eventstream.Header.newString('client-name', 'accepted.testy_mc_testerson') | ||
eventstream.Header.newString(':version', '0.1.0') | ||
); | ||
@@ -663,2 +691,3 @@ } | ||
constructor(readonly operationConfig: OperationConfig) { | ||
@@ -772,2 +801,8 @@ super(); | ||
/** | ||
* @internal | ||
* | ||
* @param operationConfig | ||
* @param serviceModel | ||
*/ | ||
constructor(private operationConfig: OperationConfig, private serviceModel: EventstreamRpcServiceModel) { | ||
@@ -851,2 +886,9 @@ if (!serviceModel.operations.has(operationConfig.name)) { | ||
/** | ||
* @internal | ||
* | ||
* @param request | ||
* @param operationConfig | ||
* @param serviceModel | ||
*/ | ||
constructor(private request: RequestType, private operationConfig: OperationConfig, private serviceModel: EventstreamRpcServiceModel) { | ||
@@ -911,2 +953,6 @@ if (!serviceModel.operations.has(operationConfig.name)) { | ||
try { | ||
if (!doesOperationAllowOutboundMessages(this.serviceModel, this.operationConfig.name)) { | ||
throw createRpcError(RpcErrorType.ValidationError, `Operation '${this.operationConfig.name}' does not allow outbound streaming messages.`); | ||
} | ||
if (!this.operationConfig.options.disableValidation) { | ||
@@ -1048,3 +1094,3 @@ validateOutboundMessage(this.serviceModel, this.operationConfig.name, message); | ||
if (!validator) { | ||
throw createRpcError(RpcErrorType.InternalError, `No shape named '${shapeName}' exists in the service model`); | ||
throw createRpcError(RpcErrorType.ValidationError, `No shape named '${shapeName}' exists in the service model`); | ||
} | ||
@@ -1063,3 +1109,3 @@ | ||
if (!selectedShape) { | ||
throw createRpcError(RpcErrorType.InternalError, `Operation '${operationName}' does not have a defined selection shape`); | ||
throw createRpcError(RpcErrorType.ValidationError, `Operation '${operationName}' does not have a defined selection shape`); | ||
} | ||
@@ -1077,2 +1123,11 @@ | ||
function doesOperationAllowOutboundMessages(model: EventstreamRpcServiceModel, operationName: string) : boolean { | ||
let operation = model.operations.get(operationName); | ||
if (!operation) { | ||
throw createRpcError(RpcErrorType.InternalError, `No operation named '${operationName}' exists in the service model`); | ||
} | ||
return operation.outboundMessageShape !== undefined; | ||
} | ||
function serializeMessage(model: EventstreamRpcServiceModel, operationName: string, message: any, shapeSelector: OperationShapeSelector) : eventstream.Message { | ||
@@ -1079,0 +1134,0 @@ let operation = model.operations.get(operationName); |
{ | ||
"name": "aws-iot-device-sdk-v2", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"description": "NodeJS API for the AWS IoT service", | ||
@@ -45,4 +45,4 @@ "homepage": "https://github.com/aws/aws-iot-device-sdk-js-v2", | ||
"@aws-sdk/util-utf8-browser": "^3.109.0", | ||
"aws-crt": "^1.15.15" | ||
"aws-crt": "^1.15.16" | ||
} | ||
} |
@@ -127,2 +127,2 @@ # AWS IoT Device SDK for JavaScript v2 | ||
Latest released version: v1.11.0 | ||
Latest released version: v1.11.1 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
828794
82
15997
Updatedaws-crt@^1.15.16