export function validateValueAsArray()

in lib/eventstream_rpc_utils.ts [437:458]


export function validateValueAsArray(value : any, elementValidator : ElementValidator, propertyName?: string, type?: string) {
    if (value === undefined) {
        throwMissingPropertyError(propertyName, type);
    }

    if (!Array.isArray(value)) {
        throwInvalidPropertyValueError('an array value', propertyName, type);
    }

    for (const element of value) {
        try {
            elementValidator(element);
        } catch (err) {
            let rpcError : eventstream_rpc.RpcError = err as eventstream_rpc.RpcError;
            if (propertyName && type) {
                throw eventstream_rpc.createRpcError(eventstream_rpc.RpcErrorType.ValidationError, `Array property '${propertyName}' of type '${type}' contains an invalid value`, new CrtError(rpcError.toString()));
            } else {
                throw eventstream_rpc.createRpcError(eventstream_rpc.RpcErrorType.ValidationError, `Array contains an invalid value`, new CrtError(rpcError.toString()));
            }
        }
    }
}