Commit 6ea8749f authored by 邓晓峰's avatar 邓晓峰

fix: 修复format function undefined

parent 58088be2
module.exports = {
extends: [require.resolve('@umijs/fabric/dist/eslint')],
rules: {
'@typescript-eslint/prefer-interface': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'no-return-assign': 0,
semi: ['error', 'always'],
'no-confusing-arrow': 0,
......
import _typeof from "@babel/runtime/helpers/esm/typeof";
import ClientImplementation from './ClientImplementation';
import { ERROR } from './consts';
import { validate } from './utils';
import { validate, format } from './utils';
/* eslint-disable */
var Client = function Client(host, port, path, clientId) {
......
......@@ -18,7 +18,7 @@ var _utils = require("./utils");
/* eslint-disable */
var Client = function Client(host, port, path, clientId) {
var uri;
if (typeof host !== 'string') throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(host), 'host']));
if (typeof host !== 'string') throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(host), 'host']));
if (arguments.length == 2) {
// host: must be full ws:// uri
......@@ -32,7 +32,7 @@ var Client = function Client(host, port, path, clientId) {
port = parseInt(match[7]);
path = match[8];
} else {
throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [host, 'host']));
throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [host, 'host']));
}
} else {
if (arguments.length == 3) {
......@@ -40,8 +40,8 @@ var Client = function Client(host, port, path, clientId) {
path = '/mqtt';
}
if (typeof port !== 'number' || port < 0) throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(port), 'port']));
if (typeof path !== 'string') throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(path), 'path']));
if (typeof port !== 'number' || port < 0) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(port), 'port']));
if (typeof path !== 'string') throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(path), 'path']));
var ipv6AddSBracket = host.indexOf(':') !== -1 && host.slice(0, 1) !== '[' && host.slice(-1) !== ']';
uri = 'ws://' + (ipv6AddSBracket ? '[' + host + ']' : host) + ':' + port + path;
}
......@@ -58,7 +58,7 @@ var Client = function Client(host, port, path, clientId) {
clientIdLength++;
}
if (typeof clientId !== 'string' || clientIdLength > 65535) throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [clientId, 'clientId']));
if (typeof clientId !== 'string' || clientIdLength > 65535) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [clientId, 'clientId']));
var client = new _ClientImplementation.default(uri, host, port, path, clientId); //Public Properties
Object.defineProperties(this, {
......@@ -67,7 +67,7 @@ var Client = function Client(host, port, path, clientId) {
return host;
},
set: function set() {
throw new Error(format(_consts.ERROR.UNSUPPORTED_OPERATION));
throw new Error((0, _utils.format)(_consts.ERROR.UNSUPPORTED_OPERATION));
}
},
port: {
......@@ -75,7 +75,7 @@ var Client = function Client(host, port, path, clientId) {
return port;
},
set: function set() {
throw new Error(format(_consts.ERROR.UNSUPPORTED_OPERATION));
throw new Error((0, _utils.format)(_consts.ERROR.UNSUPPORTED_OPERATION));
}
},
path: {
......@@ -83,7 +83,7 @@ var Client = function Client(host, port, path, clientId) {
return path;
},
set: function set() {
throw new Error(format(_consts.ERROR.UNSUPPORTED_OPERATION));
throw new Error((0, _utils.format)(_consts.ERROR.UNSUPPORTED_OPERATION));
}
},
uri: {
......@@ -91,7 +91,7 @@ var Client = function Client(host, port, path, clientId) {
return uri;
},
set: function set() {
throw new Error(format(_consts.ERROR.UNSUPPORTED_OPERATION));
throw new Error((0, _utils.format)(_consts.ERROR.UNSUPPORTED_OPERATION));
}
},
clientId: {
......@@ -99,7 +99,7 @@ var Client = function Client(host, port, path, clientId) {
return client.clientId;
},
set: function set() {
throw new Error(format(_consts.ERROR.UNSUPPORTED_OPERATION));
throw new Error((0, _utils.format)(_consts.ERROR.UNSUPPORTED_OPERATION));
}
},
onConnected: {
......@@ -107,7 +107,7 @@ var Client = function Client(host, port, path, clientId) {
return client.onConnected;
},
set: function set(newOnConnected) {
if (typeof newOnConnected === 'function') client.onConnected = newOnConnected;else throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(newOnConnected), 'onConnected']));
if (typeof newOnConnected === 'function') client.onConnected = newOnConnected;else throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(newOnConnected), 'onConnected']));
}
},
disconnectedPublishing: {
......@@ -131,7 +131,7 @@ var Client = function Client(host, port, path, clientId) {
return client.onConnectionLost;
},
set: function set(newOnConnectionLost) {
if (typeof newOnConnectionLost === 'function') client.onConnectionLost = newOnConnectionLost;else throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(newOnConnectionLost), 'onConnectionLost']));
if (typeof newOnConnectionLost === 'function') client.onConnectionLost = newOnConnectionLost;else throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(newOnConnectionLost), 'onConnectionLost']));
}
},
onMessageDelivered: {
......@@ -139,7 +139,7 @@ var Client = function Client(host, port, path, clientId) {
return client.onMessageDelivered;
},
set: function set(newOnMessageDelivered) {
if (typeof newOnMessageDelivered === 'function') client.onMessageDelivered = newOnMessageDelivered;else throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(newOnMessageDelivered), 'onMessageDelivered']));
if (typeof newOnMessageDelivered === 'function') client.onMessageDelivered = newOnMessageDelivered;else throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(newOnMessageDelivered), 'onMessageDelivered']));
}
},
onMessageArrived: {
......@@ -147,7 +147,7 @@ var Client = function Client(host, port, path, clientId) {
return client.onMessageArrived;
},
set: function set(newOnMessageArrived) {
if (typeof newOnMessageArrived === 'function') client.onMessageArrived = newOnMessageArrived;else throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(newOnMessageArrived), 'onMessageArrived']));
if (typeof newOnMessageArrived === 'function') client.onMessageArrived = newOnMessageArrived;else throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(newOnMessageArrived), 'onMessageArrived']));
}
},
trace: {
......@@ -158,7 +158,7 @@ var Client = function Client(host, port, path, clientId) {
if (typeof trace === 'function') {
client.traceFunction = trace;
} else {
throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(trace), 'onTrace']));
throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(trace), 'onTrace']));
}
}
}
......@@ -250,7 +250,7 @@ var Client = function Client(host, port, path, clientId) {
if (connectOptions.keepAliveInterval === undefined) connectOptions.keepAliveInterval = 60;
if (connectOptions.mqttVersion > 4 || connectOptions.mqttVersion < 3) {
throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.mqttVersion, 'connectOptions.mqttVersion']));
throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.mqttVersion, 'connectOptions.mqttVersion']));
}
if (connectOptions.mqttVersion === undefined) {
......@@ -261,45 +261,45 @@ var Client = function Client(host, port, path, clientId) {
} //Check that if password is set, so is username
if (connectOptions.password !== undefined && connectOptions.userName === undefined) throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.password, 'connectOptions.password']));
if (connectOptions.password !== undefined && connectOptions.userName === undefined) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.password, 'connectOptions.password']));
if (connectOptions.willMessage) {
if (!(connectOptions.willMessage instanceof Message)) throw new Error(format(_consts.ERROR.INVALID_TYPE, [connectOptions.willMessage, 'connectOptions.willMessage'])); // The will message must have a payload that can be represented as a string.
if (!(connectOptions.willMessage instanceof Message)) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [connectOptions.willMessage, 'connectOptions.willMessage'])); // The will message must have a payload that can be represented as a string.
// Cause the willMessage to throw an exception if this is not the case.
connectOptions.willMessage.stringPayload = null;
if (typeof connectOptions.willMessage.destinationName === 'undefined') throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(connectOptions.willMessage.destinationName), 'connectOptions.willMessage.destinationName']));
if (typeof connectOptions.willMessage.destinationName === 'undefined') throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(connectOptions.willMessage.destinationName), 'connectOptions.willMessage.destinationName']));
}
if (typeof connectOptions.cleanSession === 'undefined') connectOptions.cleanSession = true;
if (connectOptions.hosts) {
if (!(connectOptions.hosts instanceof Array)) throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.hosts, 'connectOptions.hosts']));
if (connectOptions.hosts.length < 1) throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.hosts, 'connectOptions.hosts']));
if (!(connectOptions.hosts instanceof Array)) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.hosts, 'connectOptions.hosts']));
if (connectOptions.hosts.length < 1) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.hosts, 'connectOptions.hosts']));
var usingURIs = false;
for (var i = 0; i < connectOptions.hosts.length; i++) {
if (typeof connectOptions.hosts[i] !== 'string') throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(connectOptions.hosts[i]), 'connectOptions.hosts[' + i + ']']));
if (typeof connectOptions.hosts[i] !== 'string') throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(connectOptions.hosts[i]), 'connectOptions.hosts[' + i + ']']));
if (/^(wss?):\/\/((\[(.+)\])|([^\/]+?))(:(\d+))?(\/.*)$/.test(connectOptions.hosts[i])) {
if (i === 0) {
usingURIs = true;
} else if (!usingURIs) {
throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.hosts[i], 'connectOptions.hosts[' + i + ']']));
throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.hosts[i], 'connectOptions.hosts[' + i + ']']));
}
} else if (usingURIs) {
throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.hosts[i], 'connectOptions.hosts[' + i + ']']));
throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.hosts[i], 'connectOptions.hosts[' + i + ']']));
}
}
if (!usingURIs) {
if (!connectOptions.ports) throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.ports, 'connectOptions.ports']));
if (!(connectOptions.ports instanceof Array)) throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.ports, 'connectOptions.ports']));
if (connectOptions.hosts.length !== connectOptions.ports.length) throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.ports, 'connectOptions.ports']));
if (!connectOptions.ports) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.ports, 'connectOptions.ports']));
if (!(connectOptions.ports instanceof Array)) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.ports, 'connectOptions.ports']));
if (connectOptions.hosts.length !== connectOptions.ports.length) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [connectOptions.ports, 'connectOptions.ports']));
connectOptions.uris = [];
for (var i = 0; i < connectOptions.hosts.length; i++) {
if (typeof connectOptions.ports[i] !== 'number' || connectOptions.ports[i] < 0) throw new Error(format(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(connectOptions.ports[i]), 'connectOptions.ports[' + i + ']']));
if (typeof connectOptions.ports[i] !== 'number' || connectOptions.ports[i] < 0) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_TYPE, [(0, _typeof2.default)(connectOptions.ports[i]), 'connectOptions.ports[' + i + ']']));
var host = connectOptions.hosts[i];
var port = connectOptions.ports[i];
var ipv6 = host.indexOf(':') !== -1;
......@@ -358,7 +358,7 @@ var Client = function Client(host, port, path, clientId) {
timeout: 'number'
});
if (subscribeOptions.timeout && !subscribeOptions.onFailure) throw new Error('subscribeOptions.timeout specified with no onFailure callback.');
if (typeof subscribeOptions.qos !== 'undefined' && !(subscribeOptions.qos === 0 || subscribeOptions.qos === 1 || subscribeOptions.qos === 2)) throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [subscribeOptions.qos, 'subscribeOptions.qos']));
if (typeof subscribeOptions.qos !== 'undefined' && !(subscribeOptions.qos === 0 || subscribeOptions.qos === 1 || subscribeOptions.qos === 2)) throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [subscribeOptions.qos, 'subscribeOptions.qos']));
client.subscribe(filter, subscribeOptions);
};
/**
......@@ -435,7 +435,7 @@ var Client = function Client(host, port, path, clientId) {
} else if (arguments.length == 1) {
if (!(topic instanceof Message) && typeof topic !== 'string') throw new Error('Invalid argument:' + (0, _typeof2.default)(topic));
message = topic;
if (typeof message.destinationName === 'undefined') throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [message.destinationName, 'Message.destinationName']));
if (typeof message.destinationName === 'undefined') throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [message.destinationName, 'Message.destinationName']));
client.send(message);
} else {
//parameter checking in Message object
......@@ -479,7 +479,7 @@ var Client = function Client(host, port, path, clientId) {
} else if (arguments.length == 1) {
if (!(topic instanceof Message) && typeof topic !== 'string') throw new Error('Invalid argument:' + (0, _typeof2.default)(topic));
message = topic;
if (typeof message.destinationName === 'undefined') throw new Error(format(_consts.ERROR.INVALID_ARGUMENT, [message.destinationName, 'Message.destinationName']));
if (typeof message.destinationName === 'undefined') throw new Error((0, _utils.format)(_consts.ERROR.INVALID_ARGUMENT, [message.destinationName, 'Message.destinationName']));
client.send(message);
} else {
//parameter checking in Message object
......
import ClientImplementation from './ClientImplementation';
import { ERROR } from './consts';
import { validate, format } from './utils';
/* eslint-disable */
const Client = function (host, port, path, clientId) {
var uri;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment