@ultipa-graph/ultipa-node-sdk
Version:
NodeJS SDK for ultipa-server 4.0
49 lines • 1.8 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.printNode = exports.getNodesPrintInfo = void 0;
const chalk_1 = __importDefault(require("chalk"));
const types_1 = require("../types");
const alias_1 = require("./alias");
function getNodesPrintInfo(nodes, option) {
let schemaMap = {};
let rows = [];
nodes === null || nodes === void 0 ? void 0 : nodes.forEach((n, i) => {
let schema = n === null || n === void 0 ? void 0 : n.schema;
if (!n) {
schema = "printers_null_nodes";
}
if (!schemaMap[schema]) {
schemaMap[schema] = [];
}
let row = !n ? {
null_index: i
} : Object.assign({ "@schema": schema, _id: n.id, _uuid: n.uuid }, n.values);
if (option === null || option === void 0 ? void 0 : option.onlyRows) {
rows.push(row);
}
else {
schemaMap[schema].push(row);
}
});
if (option === null || option === void 0 ? void 0 : option.onlyRows) {
return rows;
}
return schemaMap;
}
exports.getNodesPrintInfo = getNodesPrintInfo;
function printNode(dataItem) {
if ((dataItem === null || dataItem === void 0 ? void 0 : dataItem.type) == types_1.ULTIPA.ResultType.RESULT_TYPE_NODE) {
let nodes = dataItem.asNodes();
(0, alias_1.printAlias)(dataItem);
let schemaMap = getNodesPrintInfo(nodes);
for (const schema in schemaMap) {
console.log(chalk_1.default.blue(` @${schema}`));
console.table(schemaMap[schema]);
}
}
}
exports.printNode = printNode;
//# sourceMappingURL=node.js.map