bruno
bruno copied to clipboard
Unable to print a javascript object
const { _ } = require('lodash'),
{ faker } = require('@faker-js/faker'),
axios = require('axios'),
host = bru.getEnvVar("host"),
port = bru.getEnvVar("port"),
apiPath = bru.getEnvVar("api-path"),
fieldsPath = "/streams/device_shadow/fields";
const streamResp = await axios.get(host + port + apiPath + fieldsPath);
const rawFieldTypes = ["Bool",
"Float32",
"Float64",
"Int8",
"Int16",
"Int32",
"Int64",
"UInt8",
"UInt16",
"UInt32",
"UInt64",
"String",
"Date",
"DateTime",
"DateTime64(3)",
"DateTime64(6)",
"Array(String)"];
function makeNullable(fieldType) {
return "Nullable(".concat(fieldType).concat(")");
}
function generateStringArray(length) {
const stringArray = [];
for (let i = 0; i < length; i++) {
stringArray.push(faker.lorem.word()); // Generate a fake word as a string
}
return stringArray;
}
const fieldTypes = []
for (let i = 0; i< rawFieldTypes.length; i++) {
fieldTypes.push(makeNullable(rawFieldTypes[i]));
}
const finalFieldTypes = fieldTypes.concat(rawFieldTypes)
function mapFieldType(fieldType) {
switch (fieldType) {
case "Bool":
return faker.datatype.boolean();
case "Float32":
return faker.number.float();
case "Float64":
return faker.number.float({ min: 0, max: 100, precision: 0.01 });
case "Int8":
return faker.number.bigInt({ min: -128, max: 127 });
case "UInt8":
return faker.number.bigInt({ min: 0, max: 255 });
case "Int16":
return faker.number.bigInt({ min: -32768, max: 32767 });
case "UInt16":
return faker.number.bigInt({ min: 0, max: 65535 });
case "Int64":
return "null";
case "UInt64":
return "null"
case "String":
return faker.string.alpha();
case "Date":
return faker.date.past();
case "DateTime":
return faker.date.recent();
case "DateTime64(3)":
return faker.date.recent().toISOString().replace('Z', '').replace('T', ' ');
case "Array(String)":
return generateStringArray(5);
default:
return faker.number.bigInt();
}
}
function mapDataObject(dataObject) {
const mappedData = {};
for (const key in dataObject) {
if (dataObject.hasOwnProperty(key)) {
const fieldType = dataObject[key].type;
mappedData[key] = mapFieldType(fieldType);
}
}
return mappedData;
}
const mappedData = mapDataObject(streamResp.data.result);
console.log(Object.keys(mappedData));
console.log("Mapped Data:", mappedData.range);
console.log("Mapped Data:", mappedData.firmware_version);
Attaching a video of trying to print mappedData object, nothing in console of web inspector.
https://github.com/usebruno/bruno/assets/72066862/b398aaaf-b0ce-4421-afe9-8c4ddd2f64f4
Could you launch Bruno from a Terminal/CLI and check the Logs? It should log the error like this: Could not send the above console.log to the BrowserWindow: "Reason"